Skip to content

agentHost: fix MCP routing activation and sign-in fallback - #343241

Merged
Martin Aeschlimann (aeschli) merged 2 commits into
mainfrom
aeschli/agents/mcp-routing-tools-auth-implementation
Oct 21, 2026
Merged

Martin Aeschlimann (aeschli) merged 2 commits into
mainfrom
aeschli/agents/mcp-routing-tools-auth-implementation

Conversation

@aeschli

@aeschli Martin Aeschlimann (aeschli) commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix three gaps in experimental MCP tool routing:

  • Keep proactive sign-in hints when routing tools cannot be registered, including when tool search is unavailable. The host advertises actual registrations per chat, rather than the client suppressing hints solely because the routing setting is enabled.
  • Wait for server activation and tool readiness before discovering tools. Reuse starting/ready servers and share activation between concurrent routing calls.
  • Include SDK-global MCP servers in the routing inventory before creating or resuming an SDK session. Read their configurations through the existing client-level mcp.config.list() API, so a newly configured server such as Atlassian has a routing tool even before its first authentication and without cached tool metadata. This does not start servers eagerly or copy SDK-owned configurations into session registration. Existing configuration precedence and disabled-server filtering are preserved.

Authentication cancellation settles routing activation without aborting the turn. Sign-in hints can reappear if routing is registered and subsequently removed, while unrelated hint deduplication remains intact.

Routing metadata readers return independent snapshots, and registration metadata uses stable ordering to avoid order-only updates. Activation cleanup deliberately cancels its private token to release the listener retained by waitForState.

Includes regression tests for first-use SDK-global routing on create/resume, activation without a client-provided server definition, configuration precedence and disabled names, metadata isolation, and stable registration ordering. The feature remains experimental and disabled by default.

Validation

Passed:

  • npm run build-fast -- --client-only

  • npm run typecheck-client

  • git diff --check

  • Follow-up changed-file ESLint:

    npm run eslint -- \
      src/vs/platform/agentHost/node/copilot/copilotAgent.ts \
      src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts \
      src/vs/platform/agentHost/common/meta/vscode/mcpCustomizationMeta.ts \
      src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts \
      src/vs/platform/agentHost/test/common/agentMetaReaders.test.ts
  • Focused unit tests: 261 passing:

    ./scripts/test.sh --reporter dot \
      --run src/vs/platform/agentHost/test/common/agentMetaReaders.test.ts \
      --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts \
      --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts \
      --grep 'client tool calls|MCP server|MCP (authentication|sources|provenance)|MCP lifecycle|user configuration lookup|publishes user MCP|registered MCP routing|mcp authentication|cancelled OAuth|cancel.*authentication|cancel.*auth|shared.*auth'

Live validation used Code OSS's default user-data directory with routing enabled and an unauthenticated SDK-global Atlassian server:

  1. Inspected the initial SDK tool registration with dbgjs and confirmed an Atlassian routing tool was present before SDK session creation, despite having no cached tool metadata.
  2. Sent a fresh request to call an Atlassian read-only tool. Tool search discovered the routing tool and the call reached the normal MCP authentication required — Atlassian prompt, rather than reporting no Atlassian tools available.
  3. Stopped at the authentication prompt. No authentication was granted and no Atlassian read operation was completed.

Full integration and smoke suites were not run.

Advertise actual per-chat routing registrations so servers without routing tools retain sign-in hints. Await shared server activation and tool readiness, and settle activation when authentication is cancelled without aborting the turn.

Cover routing availability transitions, authentication cancellation, retries, and metadata validation with regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:26

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Fixes experimental MCP tool routing behavior to (1) keep proactive MCP sign-in hints accurate based on actual routing tool registrations per chat, and (2) ensure routing waits for MCP server readiness/tools and shares activation across concurrent calls.

Changes:

  • Advertise/consume per-chat MCP routing registrations via session _meta (vscode.mcpRoutingServers) to drive sign-in hint behavior.
  • Add shared MCP routing activation that waits for server readiness/tools (including cancellation handling) before tool discovery.
  • Add/adjust regression tests and update the routing setting description.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHostChatContribution.test.ts Extends test harness to simulate routing registration meta; adds coverage for sign-in hint behavior under routing registration changes.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostSessionHandler.ts Always wires MCP auth prompting, but suppresses/resurfaces hints based on actual per-chat routing registrations.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Adds routing activation/ready-tool-waiting/concurrency/cancellation tests; adjusts expectations for tool discovery calls.
src/​vs/​platform/​agentHost/​test/​common/​agentMetaReaders.test.ts Adds tests for routing server meta validation and opaque metadata preservation.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Implements per-chat routing registration emission and shared routing server activation (waits for readiness/tools, handles cancellation).
src/​vs/​platform/​agentHost/​common/​meta/​vscode/​mcpCustomizationMeta.ts Introduces readMcpRoutingServers / withMcpRoutingServers metadata helpers.
src/​vs/​platform/​agentHost/​common/​meta/​mcpCustomizationMeta.ts Re-exports new routing meta helpers.
src/​vs/​platform/​agentHost/​common/​agentHostStarter.config.contribution.ts Updates experimental setting description to reflect tool-search dependency and new hint/activation behavior.

Review effort: Lite

roblourens
roblourens previously approved these changes Oct 21, 2026
Read SDK-global configurations before session launch so uncached, unauthenticated servers have routing tools on the first request. Preserve configuration precedence, enablement, and SDK ownership.\n\nReturn independent routing metadata snapshots and normalize registration ordering. Document why activation cleanup cancels its private token.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@aeschli
Martin Aeschlimann (aeschli) merged commit 46f1328 into main Oct 21, 2026
58 checks passed
@aeschli
Martin Aeschlimann (aeschli) deleted the aeschli/agents/mcp-routing-tools-auth-implementation branch October 21, 2026 18:48
@vs-code-engineering vs-code-engineering Bot added this to the 1.144.0 milestone Oct 21, 2026
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