Skip to content

Wire up MCP App support for agent-host sessions - #321016

Merged
Connor Peet (connor4312) merged 4 commits into
mainfrom
connor4312/agent-host-mcp-apps
Jun 11, 2026
Merged

Connor Peet (connor4312) merged 4 commits into
mainfrom
connor4312/agent-host-mcp-apps

Conversation

@connor4312

Copy link
Copy Markdown
Member

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/ui extension on a tool result) into the same ChatMcpAppModel plumbing that powers App UIs for locally-running MCP servers. As a result, an MCP server like @modelcontextprotocol/server-basic-vanillajs spawned by the Copilot CLI now renders its App webview in chat just like a server configured directly in VS Code.

Highlights

  • COPILOT_MCP_APPS=true env override is set when spawning the Copilot CLI subprocess (copilotAgent.ts). Without this runtime flag, the CLI silently drops the enableMcpApps: true session option, so MCP servers never see the App-capability extension and tools never come back tagged with App metadata.
  • Agent-host tool-call adapter (stateToProgressAdapter.ts) now populates state.resultDetails.mcpOutput for MCP App tools by translating our AHP ToolResultContent[] into an MCP.CallToolResult:
    • Text → TextContent
    • EmbeddedResource (image/audio) → ImageContent / AudioContent
    • Other EmbeddedResource → EmbeddedResource wrapping a synthetic data: URI
    • Resource refs → ResourceLink
  • Resource URIs in tool results are now consistently wrapped via toAgentHostUri(uri, connectionAuthority) so remote agent host resources resolve through the agent host filesystem provider on the client. This fixes a pre-existing inconsistency where the output: [{ type: 'ref', uri }] ref produced raw remote URIs.
  • resultDetails is no longer dropped when toolSpecificData carries 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-native clean
  • stateToProgressAdapter.test.ts (63 tests) pass, including the updated assertion that Resource output refs are wrapped via toAgentHostUri
  • Verified end-to-end against a self-contained SDK repro (vscode-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 receives ui/notifications/tool-result with real content.

Copilot AI review requested due to automatic review settings June 11, 2026 19:45
@connor4312
Connor Peet (connor4312) enabled auto-merge (squash) June 11, 2026 19:45
@vs-code-engineering

vs-code-engineering Bot commented Jun 11, 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 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 (local vs agentHost) 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 via toAgentHostUri.
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

@connor4312
Connor Peet (connor4312) merged commit a3634cd into main Jun 11, 2026
39 of 40 checks passed
@connor4312
Connor Peet (connor4312) deleted the connor4312/agent-host-mcp-apps branch June 11, 2026 22:02
}

async readResource(uri: string, _token: CancellationToken): Promise<MCP.ReadResourceResult> {
const result = await this._agentHostService.handleMcpRequest(this._channel, 'resources/read', { uri }) as MCP.ReadResourceResult;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(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,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we already have it inside uri, is it still necessary here? If blob is large, this may matter...

@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.

4 participants