Repository navigation
Wire up MCP App support for agent-host sessions - #321016
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
There was a problem hiding this comment.
Pull request overview
This PR wires MCP App UI support through the agent-host session pipeline so MCP servers owned by agent-host sessions (e.g. Copilot CLI) can render MCP App webviews in the chat UI, using the same ChatMcpAppModel plumbing as locally-configured MCP servers.
Changes:
- Adds an agent-host MCP side-channel request path (
handleMcpRequest) and routes MCP App sub-RPCs (tools/call,resources/read,sampling/createMessage) through it. - Extends MCP App UI metadata to be a discriminated union (
localvsagentHost) and plumbs agent-host routing data into chat tool invocation rendering. - Translates agent-host tool result content blocks into MCP
CallToolResult-compatible output for MCP Apps, and consistently wraps tool-result resource URIs viatoAgentHostUri.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/services/agentHost/browser/editorRemoteAgentHostServiceClient.ts | Adds handleMcpRequest forwarding to the remote agent host client. |
| src/vs/workbench/contrib/terminal/test/browser/agentHostPty.test.ts | Updates test mock to satisfy the new IAgentConnection.handleMcpRequest API. |
| src/vs/workbench/contrib/mcp/common/mcpTypes.ts | Changes MCP App UI data to a discriminated union supporting agentHost routing info. |
| src/vs/workbench/contrib/mcp/common/mcpLanguageModelToolContribution.ts | Marks locally-configured MCP App UI data as kind: 'local'. |
| src/vs/workbench/contrib/mcp/browser/mcpToolCallUI.ts | Introduces transport abstraction to route MCP App sub-RPCs via local MCP service or agent-host side-channel and exposes notifications. |
| src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts | Updates tests for required connectionAuthority and verifies resource URI wrapping behavior. |
| src/vs/workbench/contrib/chat/common/chatService/chatService.ts | Introduces ChatMcpAppData union for routing MCP App sub-RPCs (local vs agentHost). |
| src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatToolInvocationPart.ts | Reworks MCP App subpart mounting to be driven by an observable render-data signal. |
| src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatMcpAppSubPart.ts | Updates render-data type to reuse ChatMcpAppData (local/agentHost). |
| src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatMcpAppModel.ts | Keys webview origin by server discriminator, forwards notifications to the webview, and adds sampling request handling. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/stateToProgressAdapter.ts | Populates MCP App render data for agent-host MCP calls and translates tool output into MCP CallToolResult; wraps resource URIs via toAgentHostUri. |
| src/vs/platform/mcp/common/modelContextProtocolApps.ts | Extends MCP Apps request/result unions to include sampling/createMessage. |
| src/vs/platform/agentHost/node/shared/mcpCustomizationController.ts | Exposes helpers to get customization id and active mcp:// channel per server for tagging/routing. |
| src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts | Enables MCP Apps in Copilot SDK session options (enableMcpApps: true). |
| src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts | Tags MCP tool calls with contributor customization ids and attaches _meta.ui channel/resource data on completion. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Sets COPILOT_MCP_APPS=true when spawning the Copilot CLI subprocess. |
| src/vs/platform/agentHost/electron-browser/localAgentHostService.ts | Adds handleMcpRequest proxy method for the local agent host service. |
| src/vs/platform/agentHost/common/state/protocol/channels-session/reducer.ts | Preserves/overrides tool-call _meta across state transitions using action-provided meta. |
| src/vs/platform/agentHost/common/agentService.ts | Adds handleMcpRequest to IAgentConnection for mcp:// side-channel routing. |
| src/vs/platform/agentHost/browser/remoteAgentHostProtocolClient.ts | Implements handleMcpRequest by dispatching raw MCP methods and injecting the channel envelope field. |
| src/vs/platform/agentHost/browser/nullAgentHostService.ts | Adds handleMcpRequest stub to the null agent host service. |
Copilot's findings
- Files reviewed: 21/21 changed files
- Comments generated: 4
| } | ||
|
|
||
| async readResource(uri: string, _token: CancellationToken): Promise<MCP.ReadResourceResult> { | ||
| const result = await this._agentHostService.handleMcpRequest(this._channel, 'resources/read', { uri }) as MCP.ReadResourceResult; |
There was a problem hiding this comment.
Should this take cancellation token to avoid hanging requests?
| * routes by `params.channel` so we inject it automatically. | ||
| */ | ||
| async handleMcpRequest(channel: string, method: string, params: Record<string, unknown> | undefined): Promise<unknown> { | ||
| return await this._dispatchRequest<unknown>(method, { ...(params ?? {}), channel }); |
There was a problem hiding this comment.
If MCP method has a channel parameter, we will override it...
| * (enough for webview state to persist across re-renders) without | ||
| * touching application storage. | ||
| */ | ||
| private static readonly _agentHostOrigins = new Map<string, string>(); |
There was a problem hiding this comment.
(minor) Perhaps we can find a way to make this per session so it gets cleaned up eventually?
| resource: { | ||
| uri: `data:${block.contentType};base64,${block.data}`, | ||
| mimeType: block.contentType, | ||
| blob: block.data, |
There was a problem hiding this comment.
Since we already have it inside uri, is it still necessary here? If blob is large, this may matter...
Wires up MCP App support through the agent host pipeline so MCP servers exposed by agent-host sessions (currently the Copilot CLI agent) feed the chat UI's MCP App webviews end-to-end.
What's new
MCP Apps over the agent host protocol. Tool calls routed through agent-host MCP servers now surface their MCP App metadata (the
extensions.io.modelcontextprotocol/uiextension on a tool result) into the sameChatMcpAppModelplumbing that powers App UIs for locally-running MCP servers. As a result, an MCP server like@modelcontextprotocol/server-basic-vanillajsspawned by the Copilot CLI now renders its App webview in chat just like a server configured directly in VS Code.Highlights
COPILOT_MCP_APPS=trueenv override is set when spawning the Copilot CLI subprocess (copilotAgent.ts). Without this runtime flag, the CLI silently drops theenableMcpApps: truesession option, so MCP servers never see the App-capability extension and tools never come back tagged with App metadata.stateToProgressAdapter.ts) now populatesstate.resultDetails.mcpOutputfor MCP App tools by translating our AHPToolResultContent[]into anMCP.CallToolResult:TextContentImageContent/AudioContentEmbeddedResourcewrapping a syntheticdata:URIResourceLinktoAgentHostUri(uri, connectionAuthority)so remote agent host resources resolve through the agent host filesystem provider on the client. This fixes a pre-existing inconsistency where theoutput: [{ type: 'ref', uri }]ref produced raw remote URIs.resultDetailsis no longer dropped whentoolSpecificDatacarries MCP App input data — the gating condition was widened so MCP-app tool invocations get details populated for both the serialized (history) and live (active-turn) paths.Testing
npm run compile-check-ts-nativecleanstateToProgressAdapter.test.ts(63 tests) pass, including the updated assertion thatResourceoutput refs are wrapped viatoAgentHostUrivscode-team-kit/mcp-apps-sdk-repro) and in VS Code itself by invoking an MCP App tool through a Copilot CLI agent-host session and confirming the App webview receivesui/notifications/tool-resultwith real content.