Skip to content

MCP server integration for agent-host sessions - #320854

Merged
Connor Peet (connor4312) merged 6 commits into
mainfrom
connor4312/agent-host-mcp-integration
Jun 10, 2026
Merged

Connor Peet (connor4312) merged 6 commits into
mainfrom
connor4312/agent-host-mcp-integration

Conversation

@connor4312

Copy link
Copy Markdown
Member

When a Copilot CLI (or any agent-host) session is running MCP servers, those servers are now visible and controllable from the workbench. They show up in MCP: List Servers and run through VS Code's standard MCP UI, alongside locally-configured servers.

What this changes

  • MCP: List Servers now defaults to the focused agent-host session's MCP servers when one is open. Each server shows its live status (Starting / Running / Error / etc.) and can be enabled or disabled in place. A trailing Show locally configured servers… entry switches back to the existing local picker.
  • MCP over the Agent Host Protocol: CopilotAgentSession advertises the standard MCP app capabilities (sampling + resources) and routes server notifications by channel scheme. The inventory is seeded from rpc.mcp.list at subscription time so restored sessions and eagerly-configured servers populate immediately.
  • MCP-only plugins (plugins that contribute only MCP servers, no prompt files) are now included in the customization refs sent to the harness, so their servers reach the session.
  • Per-nonce plugin caching: agent plugins are now cached under per-revision subdirectories so multiple plugin versions can coexist on disk. Fixes EBUSY failures when a long-running session was holding files open from an older revision. Stale revisions are evicted opportunistically once their locks release.
  • Active-client claim is deferred to the first turn (rather than on session open) so simply browsing a session doesn't dispossess another client that's mid-turn elsewhere.

Tests

118 → 119 in CopilotAgentSession (MCP seed success + failure paths). Added 3 plugin-manager tests (per-nonce materialization, locked-dir retention, startup-time eviction), 4 resolveCustomizationRefs tests (MCP-only plugin inclusion + dedup), and refreshed 2 active-client tests for the new claim on first turn semantics.

Connor Peet (connor4312) and others added 3 commits June 8, 2026 15:33
# Conflicts:
#	src/vs/platform/agentHost/node/copilot/copilotAgent.ts
#	src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts
#	src/vs/workbench/services/agentHost/browser/editorRemoteAgentHostServiceClient.ts
* Wire MCP servers and sampling from agent-host sessions over the
  Agent Host Protocol. CopilotAgentSession advertises the standard
  MCP app capabilities (sampling + resources) and routes
  notifications by channel scheme. Seeds the inventory from
  `rpc.mcp.list` at subscription time so restored sessions and
  eagerly-configured servers populate without waiting for live
  events.

* Expose MCP servers through a new `getMcpServers` method on
  `IAgentHostCustomizationService` (workbench layer) and
  `IAgentHostSessionsProvider` (sessions layer). Returns rich
  `IAgentHostMcpServer` objects that encapsulate the
  `SessionCustomizationToggled` dispatch so callers don't depend
  on the low-level action protocol.

* Extend `MCP: List Servers` to default to the agent-host
  session's servers when an agent-host chat is focused, with a
  "Show locally configured servers..." back entry to switch to the
  local picker. Adds a per-server detail picker with an
  enable/disable toggle, registered as
  `workbench.mcp.agentHostServerOptions`.

* Move the active-client claim from session-open paths to the
  first turn so that opening a session doesn't dispossess another
  client that's mid-turn elsewhere. Update affected tests to
  assert the new "claim on first turn" semantics.

* Rework agent plugin caching to use per-nonce subdirectories so
  multiple revisions of the same plugin can coexist on disk. A
  long-running session can keep referencing an older nonce while a
  newer one is materialized; stale nonces are evicted
  opportunistically once they're no longer locked. Includes tests
  for the new layout and the locked-directory retry path.

* Include MCP-only plugins (no prompt files) in the customization
  refs so their servers are still synced to the harness. Compute
  plugin nonces from `fileService.stat` mtime to keep the
  client-side fingerprint stable across syncs.

* Refresh `SessionCustomizationDiscovery` non-recursive watchers
  to use `e.contains` so they fire on the watched URI itself.

Adds tests for: MCP seeding (success + failure), per-nonce plugin
materialization and eviction, MCP-only plugin inclusion, and the
new active-client claim timing.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 10, 2026 22:33
@vs-code-engineering

vs-code-engineering Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminal/test/browser/agentHostPty.test.ts

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.

Pull request overview

This PR integrates agent-host session MCP servers into VS Code’s MCP UI and Agent Host Protocol, enabling session-scoped server listing/status/toggling, MCP request routing over mcp:// channels, and safer on-disk plugin revision caching.

Changes:

  • Add mcp:// side-channel support to Agent Host Protocol (request routing + broadcast notifications) and expose session MCP servers to the workbench MCP UI.
  • Include MCP-only plugins in customization refs and introduce per-nonce plugin materialization with opportunistic eviction.
  • Defer active-client claiming until first turn; expand coverage with new/updated tests.
Show a summary per file
File Description
src/vs/workbench/services/agentHost/browser/editorRemoteAgentHostServiceClient.ts Surface MCP notification event from the remote agent host client.
src/vs/workbench/contrib/terminal/test/browser/agentHostPty.test.ts Update terminal agent-host test mock to satisfy new MCP event shape.
src/vs/workbench/contrib/mcp/common/mcpCommandIds.ts Add command id for agent-host MCP server options.
src/vs/workbench/contrib/mcp/browser/mcpCommands.ts Extend “List Servers” to prefer agent-host session servers and add toggle UX.
src/vs/workbench/contrib/mcp/browser/mcp.contribution.ts Register the new agent-host MCP server options command.
src/vs/workbench/contrib/chat/test/browser/agentSessions/resolveCustomizationRefs.test.ts Add tests for MCP-only plugin inclusion and dedup behavior.
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts Update active-client semantics tests (“claim on first turn”).
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts Defer active-client claim until turn start.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostLocalCustomizations.ts Add MCP-only plugin refs + per-plugin nonce computation (mtime).
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCustomizationService.ts Add workbench API for reading/toggling agent-host MCP servers.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostActiveClientService.ts Wire fileService into customization ref resolution.
src/vs/sessions/services/agentHost/browser/agentHostCustomizationService.ts Forward MCP servers from sessions providers to the shared customization API.
src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostCustomizationHarness.test.ts Update provider test harness for new MCP-server API.
src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts Expose session MCP servers and dispatch toggles back to host.
src/vs/sessions/common/agentHostSessionsProvider.ts Extend provider interface with getMcpServers.
src/vs/platform/agentPlugins/common/pluginParsers.ts Ensure parsed MCP server customizations advertise default MCP app capabilities.
src/vs/platform/agentHost/test/node/shared/mcpCustomizationController.test.ts Add unit tests for MCP customization controller inventory/state behavior.
src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts Update mock agent service for MCP request/notification plumbing.
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts Add tests for MCP inventory seeding success/failure paths.
src/vs/platform/agentHost/test/node/agentPluginManager.test.ts Add tests for per-nonce materialization + locked-dir eviction behavior.
src/vs/platform/agentHost/node/shared/mcpCustomizationController.ts New controller translating SDK MCP state into AHP customization actions + channel parsing.
src/vs/platform/agentHost/node/protocolServerHandler.ts Route mcp:// requests via params.channel and broadcast MCP notifications.
src/vs/platform/agentHost/node/copilot/sessionCustomizationDiscovery.ts Adjust refresh scheduling based on recursive vs non-recursive watch roots.
src/vs/platform/agentHost/node/copilot/copilotSessionWrapper.ts Add SDK event hooks for MCP server inventory + tool refresh notifications.
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts Implement MCP request routing to SDK, inventory seeding, and notification fanout.
src/vs/platform/agentHost/node/copilot/copilotAgent.ts Plumb MCP notifications + MCP request handling through the agent provider surface.
src/vs/platform/agentHost/node/agentService.ts Add MCP channel routing and aggregate MCP notifications across providers.
src/vs/platform/agentHost/node/agentPluginManager.ts Materialize plugins per nonce and implement stale-nonce cleanup/eviction.
src/vs/platform/agentHost/electron-browser/localAgentHostService.ts Relay MCP notifications from local agent host service to clients.
src/vs/platform/agentHost/common/state/protocol/mcpAppDefaults.ts Define default MCP app capability declaration for server customizations.
src/vs/platform/agentHost/common/agentService.ts Add MCP notification type + MCP request API + connection event plumbing.
src/vs/platform/agentHost/browser/remoteAgentHostProtocolClient.ts Detect and emit MCP notifications received over JSON-RPC notifications.
src/vs/platform/agentHost/browser/nullAgentHostService.ts Add no-op MCP notification event to null agent host service.

Copilot's findings

  • Files reviewed: 33/33 changed files
  • Comments generated: 4

Connor Peet (connor4312) and others added 3 commits June 10, 2026 15:46
- copilotAgentSession: guard _seedMcpServersFromRpc against missing rpc.mcp surface (fixes copilotAgent.test.ts crash) and pass the error as a separate argument so the stack trace is preserved.

- agentHostLocalCustomizations: drop the unnecessary async on addPluginRef; the async work is in a nested IIFE.

- agentPluginManager: _evictIfNeeded now retains entries whose directory cannot be deleted (e.g. locked) and advances to the next LRU candidate instead of orphaning them. Added a test covering the locked-head/unlocked-tail case.

Co-authored-by: Copilot <[email protected]>
…-mcp-integration

# Conflicts:
#	src/vs/platform/agentHost/node/copilot/copilotAgent.ts
@connor4312
Connor Peet (connor4312) merged commit fccd1c7 into main Jun 10, 2026
25 checks passed
@connor4312
Connor Peet (connor4312) deleted the connor4312/agent-host-mcp-integration branch June 10, 2026 23:59
@vs-code-engineering vs-code-engineering Bot added this to the 1.125.0 milestone Jun 11, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants