Skip to content

Route host-discovered MCP server enablement to the agent host - #343350

Merged
Vritant Bhardwaj (vritant24) merged 2 commits into
mainfrom
agents/fix-mcp-server-forwarding-bug
Oct 22, 2026
Merged

Vritant Bhardwaj (vritant24) merged 2 commits into
mainfrom
agents/fix-mcp-server-forwarding-bug

Conversation

@vritant24

Copy link
Copy Markdown
Member

Fixes one bug from #343250 (comment): disabling an MCP server that comes from ~/.copilot/mcp-config.json never reached the agent host. The other bugs in that comment (per-profile storage, last-writer-wins merging, tool set switches) are not addressed here.

Problem

Copilot-home servers are discovered by the agent host, which owns their Global decision. The window never forwards them (CopilotHomeNotForwarded), but it also loads that file as a local MCP collection, so the row has a local twin (for example copilot.null.github).

In mcpListWidget.ts, whenever a local id existed:

  • setPrimaryMcpServerEnablement wrote only the window's profile mcp.enablement and never called setCustomizationEnablement.
  • isPrimaryMcpServerEnabled read that same local state, so the row showed "Disabled (Globally)".
  • The row menus offered the local "Disable (Globally)", with the same problem.

The host published enablement: null, never reconciled the server off, and the next turn started it again.

Change

When the active agent-host session server is not client-bundled (isClientBundled false, the same childEnablement rule the host uses to decide Global ownership), the local twin is ignored for enablement:

  • The primary switch writes to the host, and its displayed state comes from the session server's resolved enablement.
  • The built-in row menu offers the host's Global, Workspace and Session actions.
  • On mcp.json rows paired with a host-owned server, the local Global/Workspace actions are replaced by the host's.

Client-forwarded mcp.json servers (isClientBundled true) and non-agent-host harnesses keep their current behavior.

The local twin is not written or migrated. _syncClientMcpEnablement already mirrors an accepted host Global decision onto the single same-named local server, so the host stays the single source of truth.

Testing

  • ./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/mcpListWidget.test.ts: passed (126 passing). With the source change reverted, 2 tests fail.
  • New suite "MCP enablement routing for a server with a local twin" covers a host-discovered Copilot-home server with a stale local disable, a client-forwarded server, and no active agent-host session.
  • npm run typecheck-client: passed.
  • npm run eslint -- <changed files>: passed.
  • End to end in Code OSS (Copilot harness): toggling github (from ~/.copilot/mcp-config.json) off wrote {"global":{"mcpServers#github":false}} to agent-host-storage.json; the running session logged Reconciling MCP server 'github' enablement: disable; the next turn and a new session reported github only as disabled (stopped) and never started it.

Known trade-offs

  • Existing stale local disables (copilot.null.github: false) from the old bug are not migrated; they now only affect the Local harness.
  • Rows are matched by name, so a mcp.json server sharing a name with a host-discovered one now controls the host's server.
  • Workspace and Session decisions made in an agent-host session are not mirrored to the local twin, so the Local harness may still run a server that is off for the agent host.

Servers from ~/.copilot/mcp-config.json are discovered by the agent host,
which owns their Global decision, but the window also loads them as a local
MCP collection. The customizations editor saw that local twin and wrote only
the window's profile enablement, so disabling such a server never reached
the agent host and the next turn started it again.

When the active agent-host session server is not client-bundled, the primary
toggle, its displayed state and the row menus now read and write the session
server's enablement through the agent host. Client-forwarded servers and
non-agent-host harnesses keep their existing behavior.

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

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

Routes enablement decisions for host-discovered MCP servers (that have a same-named “local twin”) to the agent host so global disables actually take effect, fixing the “local twin disable never reaches host” bug referenced in #343250.

Changes:

  • Introduces “host-owned” server detection to ignore local enablement for host-discovered servers and to source state/actions from the agent host instead.
  • Updates built-in and server-item menus to replace local enablement actions with agent-host actions when appropriate.
  • Adds a dedicated test suite covering host-discovered servers with a stale local twin, client-forwarded servers, and no active agent-host session.
File Description
src/​vs/​workbench/​contrib/​chat/​browser/​aiCustomization/​mcpListWidget.ts Adds host-ownership routing logic and adjusts enablement/action selection to target the agent host for host-discovered servers.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​aiCustomization/​mcpListWidget.test.ts Adds/updates tests to validate routing behavior for host-owned vs client-owned servers and session/no-session cases.

Review effort: Lite

- Append agent-host enablement actions at most once when several menu groups hold local enablement actions.
- Pass the host-owned scope list explicitly instead of relying on the default parameter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vritant24
Vritant Bhardwaj (vritant24) marked this pull request as ready for review October 21, 2026 23:48
@vritant24
Vritant Bhardwaj (vritant24) merged commit 22fedb4 into main Oct 22, 2026
59 checks passed
@vritant24
Vritant Bhardwaj (vritant24) deleted the agents/fix-mcp-server-forwarding-bug branch October 22, 2026 00:12
@vs-code-engineering vs-code-engineering Bot added this to the 1.144.0 milestone Oct 22, 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.

3 participants