Repository navigation
feat: integrate MCP service into ClaudeCodeSession for improved gateway management - #4349
Conversation
There was a problem hiding this comment.
Pull request overview
Integrates the platform MCP service into ClaudeCodeSession so Claude sessions can start and reuse a per-session MCP Gateway and expose it to the Claude Agent SDK as an HTTP MCP server (supporting improved gateway management for the sessions workflow).
Changes:
- Inject
IMcpServiceintoClaudeCodeSession. - Start/reuse an MCP Gateway keyed by a Claude session resource (
ClaudeSessionUri) and register it asvscode-mcp-gatewayin the SDKmcpServersconfig.
You can also share your feedback on Copilot code review. Take the survey.
| // Create or reuse the MCP gateway for this session | ||
| // TODO: bring this back when connecting to the gateway MCP server is not as slow. | ||
| // this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId)) ?? undefined; | ||
| this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId)) ?? undefined; | ||
| if (this._gateway) { |
There was a problem hiding this comment.
Now that the MCP gateway is started as part of session startup, it can remain alive indefinitely on non-success paths: _startGatewayIdleTimer() is only called after a result message, but _cleanup() (triggered by cancellation, errors, or generator end) doesn't start the idle timer or dispose the gateway. This can leave an MCP gateway running for sessions that error out and are never invoked again (sessions are retained in ClaudeAgentManager). Consider disposing the gateway in _cleanup() (or starting the idle timer there) to ensure best-effort cleanup across all exit paths.
| // Create or reuse the MCP gateway for this session | ||
| // TODO: bring this back when connecting to the gateway MCP server is not as slow. | ||
| // this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId)) ?? undefined; | ||
| this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId)) ?? undefined; |
There was a problem hiding this comment.
await this.mcpService.startMcpGateway(...) ?? undefined is redundant since the awaited expression already yields McpGateway | undefined. Removing the ?? undefined will simplify the expression without changing behavior.
| this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId)) ?? undefined; | |
| this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId)); |
Fixes microsoft/vscode#287660