Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

feat: integrate MCP service into ClaudeCodeSession for improved gateway management - #4349

Merged
TylerLeonhardt merged 1 commit into
mainfrom
tyler/cuddly-stoat
Mar 11, 2026
Merged

TylerLeonhardt merged 1 commit into
mainfrom
tyler/cuddly-stoat

Conversation

@TylerLeonhardt

Copy link
Copy Markdown
Member

Copilot AI review requested due to automatic review settings March 11, 2026 01:01
@TylerLeonhardt TylerLeonhardt self-assigned this Mar 11, 2026
@vs-code-engineering vs-code-engineering Bot added this to the 1.112.0 milestone Mar 11, 2026

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

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 IMcpService into ClaudeCodeSession.
  • Start/reuse an MCP Gateway keyed by a Claude session resource (ClaudeSessionUri) and register it as vscode-mcp-gateway in the SDK mcpServers config.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 456 to 458
// 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) {

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
// 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;

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId)) ?? undefined;
this._gateway ??= await this.mcpService.startMcpGateway(ClaudeSessionUri.forSessionId(this.sessionId));

Copilot uses AI. Check for mistakes.
@TylerLeonhardt
TylerLeonhardt added this pull request to the merge queue Mar 11, 2026
Merged via the queue into main with commit 914a6d8 Mar 11, 2026
23 checks passed
@TylerLeonhardt
TylerLeonhardt deleted the tyler/cuddly-stoat branch March 11, 2026 01:34
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.

[Claude Code] MCP (Model Context Protocol) integration

3 participants