Repository navigation
Implement MCP gateway for Claude agent - #3863
Conversation
This will hook up any MCP servers installed via VS Code and available via VS Code to Claude. It think there should be some UX work in Core to enable/disable tools, but from an extension perspective this should be good. ref microsoft/vscode#287660
There was a problem hiding this comment.
Pull request overview
This PR implements an MCP (Model Context Protocol) gateway for the Claude agent, allowing Claude to access MCP servers installed in VS Code. The gateway creates an HTTP endpoint that the Claude SDK can connect to, effectively bridging VS Code's MCP server ecosystem with the Claude agent's tool-calling capabilities.
Changes:
- Added
getMcpGateway()method toIMcpServiceinterface and implementations to expose an HTTP MCP gateway - Integrated MCP gateway into Claude agent via
McpGatewayServerContributorthat registers the gateway as an HTTP-based MCP server - Added tool change detection in
ClaudeCodeSessionto restart sessions when the set of MCP tools changes - Updated test signatures to include
ChatRequestparameter for tool access - Added development MCP configuration file (
.vscode/mcp.json) for testing with vscode-playwright-mcp server
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/platform/mcp/vscode/mcpServiceImpl.ts | Implements getMcpGateway() with promise caching to start MCP gateway on demand |
| src/platform/mcp/common/mcpService.ts | Extends IMcpService interface and abstract base class with getMcpGateway() method |
| src/extension/vscode.proposed.mcpServerDefinitions.d.ts | Defines McpGateway interface and startMcpGateway() VS Code API |
| src/extension/agents/claude/node/claudeCodeAgent.ts | Adds ChatRequest parameter, tool change detection, and session restart logic |
| src/extension/agents/claude/common/mcpServers/mcpGatewayServer.ts | New contributor that registers VS Code MCP gateway as HTTP server for Claude SDK |
| src/extension/agents/claude/common/mcpServers/index.ts | Imports mcpGatewayServer to trigger registration |
| src/extension/agents/claude/node/test/claudeCodeAgent.spec.ts | Updates test invoke() calls with mock ChatRequest containing empty tools map |
| .vscode/mcp.json | Workspace MCP configuration for development/testing with vscode-playwright-mcp |
| ) { } | ||
|
|
||
| async getMcpServers(): Promise<Record<string, McpServerConfig>> { | ||
| const gateway = await this.mcpService.getMcpGateway(); |
There was a problem hiding this comment.
FYI in the future I will require you to pass the chat sessionResource so we know where to associate e.g. elicitation, sampling, and app requests
There was a problem hiding this comment.
Makes sense, when that comes, we can plumb that through
| return { | ||
| 'vscode-mcp-gateway': { | ||
| type: 'http', | ||
| url: gateway.address.toString(), |
There was a problem hiding this comment.
You'll want to dispose the gateway at some point too (especially once you do per-session)
There was a problem hiding this comment.
gateway is now disposed with the service. It does make me wonder when the best time to dispose will be when it's per-session.
There was a problem hiding this comment.
It's quite cheap to create, maintain, and tear down gateways. We have a singleton HTTP server and each gateway is just a route on that server. So you could have some handle that you dispose if the session isn't active for a minute or few.
This will hook up any MCP servers installed via VS Code and available via VS Code to Claude.
It think there should be some UX work in Core to enable/disable tools, but from an extension perspective this should be good.
ref microsoft/vscode#287660