Skip to content

agentHost: keep MCP servers starting until their tools load - #341881

Merged
Connor Peet (connor4312) merged 2 commits into
microsoft:mainfrom
connor4312:connor4312/mcp-tools-loaded-starting
Oct 16, 2026
Merged

Connor Peet (connor4312) merged 2 commits into
microsoft:mainfrom
connor4312:connor4312/mcp-tools-loaded-starting

Conversation

@connor4312

Copy link
Copy Markdown
Member

Refs #341543. Pairs with the runtime change github/copilot-agent-runtime#26938.

An MCP server can report connected before it has answered tools/list. Today the agent host shows such a server as Ready even though the turn is still waiting on its tools. With a server that never answers tools/list (for example GitKraken's gk mcp, see gitkraken/vscode-gitlens#5994), that looks like a Ready server and a chat that hangs for minutes.

This PR keeps the server in Starting until its tools have loaded:

  • CopilotSessionWrapper exposes the runtime's new session.mcp_server_tools_loaded event as onMcpServerToolsLoaded. The bundled SDK types don't include this event yet, so its type is declared locally.
  • CopilotAgentSession translates a connected SDK status to Starting until that server's tools have loaded. It also keeps the server's blocking state, so "move to background" still applies.
  • When the inventory is refreshed from mcp.listConfigured, the session reads the new live.toolsLoaded field. true marks tools loaded and false marks them pending. If the field is missing (an older runtime), a connected server is treated as loaded, which is the current behavior.

How to test

  1. Use a runtime build that includes github/copilot-agent-runtime#26938, via the chat.agentHost.copilot.runtimePath setting.
  2. Add a stdio MCP server that answers initialize but sleeps for about 30s before answering tools/list.
  3. Send a chat request. The server shows as Starting, and "move to background" lets the turn continue. Once the tools arrive, the server shows as Ready.

With an older runtime, behavior is unchanged.

Copilot AI balanced review requested due to automatic review settings October 15, 2026 22:10
@connor4312
Connor Peet (connor4312) enabled auto-merge (squash) October 15, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Older-runtime connection and reconnect events can leave usable servers stuck in Starting until another inventory refresh.

1 open finding
What changed in this PR

Keeps Agent Host MCP servers Starting until their tools load, avoiding premature Ready status during slow initialization.

Changes:

  • Exposes the runtime’s tools-loaded event.
  • Tracks tool readiness through lifecycle events and inventory.
  • Adds readiness and inventory-race tests.
File Description
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Tests tool readiness, compatibility, and inventory races.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotSessionWrapper.ts Exposes the tools-loaded event with local types.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Gates Ready status on tool availability while preserving blocking state.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…ols load

Older runtimes never emit session.mcp_server_tools_loaded, so a server that
connected (or reconnected) after the initial inventory stayed Starting.
Refreshing listConfigured on connection lets inventory toolsLoaded, or its
absence on older runtimes, decide readiness.

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants