feat: limited MCP App support (#10132)

* feat: MCP apps part 1

* feat: MCP app support part 3

* chore: cleanup PR

* chore: clean up mcp ui app types

* fix: address cubic feedback
This commit is contained in:
Dallin Romney 2026-02-05 19:07:44 -08:00 • committed by GitHub
parent e33378a4bc
commit a7a5351b9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1934 additions and 43 deletions

View file

@ -235,6 +235,7 @@ export default async function doLoadConfig(options: {
uri: encodeMCPToolUri(server.id, tool.name),
group: server.name,
originalFunctionName: tool.name,
mcpMeta: tool._meta,
}));
newConfig.tools.push(...serverTools);

View file

@ -603,6 +603,15 @@ Org-level secrets can only be used for MCP by Background Agents (https://docs.co
return transport;
}
async getResource(uri: string) {
return await this.client.readResource(
{ uri },
{
timeout: this.options.timeout,
},
);
}
}
export default MCPConnection;

View file

@ -74,9 +74,8 @@ class MCPContextProvider extends BaseContextProvider {
throw new Error(`No MCP connection found for ${mcpId}`);
}
const { contents } = await connection.client.readResource({
uri: this.insertInputToUriTemplate(uri, extras.fullInput),
});
const resourceuri = this.insertInputToUriTemplate(uri, extras.fullInput);
const { contents } = await connection.getResource(resourceuri);
return await Promise.all(
contents.map(async (resource) => {

22
core/index.d.ts vendored
View file

@ -4,6 +4,8 @@ import {
PromptTemplates,
ToolOverrideConfig,
} from "@continuedev/config-yaml";
import { McpUiResourceMeta } from "@modelcontextprotocol/ext-apps";
import { TextResourceContents } from "@modelcontextprotocol/sdk/types.js";
import Parser from "web-tree-sitter";
import { CodebaseIndexer } from "./indexing/CodebaseIndexer";
import { LLMConfigurationStatuses } from "./llm/constants";
@ -499,6 +501,16 @@ export type ToolStatus =
| "done" // Tool execution completed successfully
| "canceled"; // Tool call was canceled by user or system
interface McpUiResourceContents extends TextResourceContents {
_meta?: {
ui?: McpUiResourceMeta;
};
}
interface McpUiState {
content: McpUiResourceContents;
}
// Will exist only on "assistant" messages with tool calls
interface ToolCallState {
toolCallId: string;
@ -508,6 +520,7 @@ interface ToolCallState {
processedArgs?: Record<string, any>; // Added in preprocesing step
output?: ContextItem[];
tool?: Tool;
mcpUiState?: McpUiState;
}
interface Reasoning {
@ -1109,6 +1122,13 @@ export interface ToolExtras {
codeBaseIndexer?: CodebaseIndexer;
}
export interface McpToolMeta {
ui?: {
resourceUri?: string;
};
"ui/resourceUri"?: string;
}
export interface Tool {
type: "function";
function: {
@ -1144,6 +1164,7 @@ export interface Tool {
parsedArgs: Record<string, unknown>,
processedArgs?: Record<string, unknown>,
) => ToolPolicy;
mcpMeta?: McpToolMeta;
}
/**
@ -1371,6 +1392,7 @@ export interface MCPTool {
type: "object";
properties?: Record<string, any>;
};
_meta?: Record<string, unknown> | undefined;
}
type BaseInternalMCPOptions = {

283
core/package-lock.json generated
View file

@ -91,6 +91,7 @@
"@babel/preset-env": "^7.24.7",
"@biomejs/biome": "1.6.4",
"@google/generative-ai": "^0.11.4",
"@modelcontextprotocol/ext-apps": "^1.0.1",
"@shikijs/colorized-brackets": "^3.7.0",
"@shikijs/transformers": "^3.7.0",
"@types/diff": "^7.0.1",
@ -5385,6 +5386,134 @@
"win32"
]
},
"node_modules/@modelcontextprotocol/ext-apps": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/ext-apps/-/ext-apps-1.0.1.tgz",
"integrity": "sha512-rAPzBbB5GNgYk216paQjGKUgbNXSy/yeR95c0ni6Y4uvhWI2AeF+ztEOqQFLBMQy/MPM+02pbVK1HaQmQjMwYQ==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"workspaces": [
"examples/*"
],
"optionalDependencies": {
"@oven/bun-darwin-aarch64": "^1.2.21",
"@oven/bun-darwin-x64": "^1.2.21",
"@oven/bun-darwin-x64-baseline": "^1.2.21",
"@oven/bun-linux-aarch64": "^1.2.21",
"@oven/bun-linux-aarch64-musl": "^1.2.21",
"@oven/bun-linux-x64": "^1.2.21",
"@oven/bun-linux-x64-baseline": "^1.2.21",
"@oven/bun-linux-x64-musl": "^1.2.21",
"@oven/bun-linux-x64-musl-baseline": "^1.2.21",
"@oven/bun-windows-x64": "^1.2.21",
"@oven/bun-windows-x64-baseline": "^1.2.21",
"@rollup/rollup-darwin-arm64": "^4.53.3",
"@rollup/rollup-darwin-x64": "^4.53.3",
"@rollup/rollup-linux-arm64-gnu": "^4.53.3",
"@rollup/rollup-linux-x64-gnu": "^4.53.3",
"@rollup/rollup-win32-arm64-msvc": "^4.53.3",
"@rollup/rollup-win32-x64-msvc": "^4.53.3"
},
"peerDependencies": {
"@modelcontextprotocol/sdk": "^1.24.0",
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
"zod": "^3.25.0 || ^4.0.0"
},
"peerDependenciesMeta": {
"react": {
"optional": true
},
"react-dom": {
"optional": true
}
}
},
"node_modules/@modelcontextprotocol/ext-apps/node_modules/@rollup/rollup-darwin-arm64": {
"version": "4.57.1",
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.57.1.tgz",
"integrity": "sha512-crNPrwJOrRxagUYeMn/DZwqN88SDmwaJ8Cvi/TN1HnWBU7GwknckyosC2gd0IqYRsHDEnXf328o9/HC6OkPgOg==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@modelcontextprotocol/ext-apps/node_modules/@rollup/rollup-darwin-x64": {
"version": "4.57.1",
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.57.1.tgz",
"integrity": "sha512-Ji8g8ChVbKrhFtig5QBV7iMaJrGtpHelkB3lsaKzadFBe58gmjfGXAOfI5FV0lYMH8wiqsxKQ1C9B0YTRXVy4w==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@modelcontextprotocol/ext-apps/node_modules/@rollup/rollup-linux-arm64-gnu": {
"version": "4.57.1",
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.57.1.tgz",
"integrity": "sha512-MMtej3YHWeg/0klK2Qodf3yrNzz6CGjo2UntLvk2RSPlhzgLvYEB3frRvbEF2wRKh1Z2fDIg9KRPe1fawv7C+g==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@modelcontextprotocol/ext-apps/node_modules/@rollup/rollup-linux-x64-gnu": {
"version": "4.57.1",
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.57.1.tgz",
"integrity": "sha512-ABca4ceT4N+Tv/GtotnWAeXZUZuM/9AQyCyKYyKnpk4yoA7QIAuBt6Hkgpw8kActYlew2mvckXkvx0FfoInnLg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@modelcontextprotocol/ext-apps/node_modules/@rollup/rollup-win32-arm64-msvc": {
"version": "4.57.1",
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.57.1.tgz",
"integrity": "sha512-O54mtsV/6LW3P8qdTcamQmuC990HDfR71lo44oZMZlXU4tzLrbvTii87Ni9opq60ds0YzuAlEr/GNwuNluZyMQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@modelcontextprotocol/ext-apps/node_modules/@rollup/rollup-win32-x64-msvc": {
"version": "4.57.1",
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.57.1.tgz",
"integrity": "sha512-mxRFDdHIWRxg3UfIIAwCm6NzvxG0jDX/wBN6KsQFTvKFqqg9vTrWUE68qEjHt19A5wwx5X5aUi2zuZT7YR0jrA==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@modelcontextprotocol/sdk": {
"version": "1.26.0",
"resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.26.0.tgz",
@ -6306,6 +6435,160 @@
"@opentelemetry/api": "^1.1.0"
}
},
"node_modules/@oven/bun-darwin-aarch64": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.3.8.tgz",
"integrity": "sha512-hPERz4IgXCM6Y6GdEEsJAFceyJMt29f3HlFzsvE/k+TQjChRhar6S+JggL35b9VmFfsdxyCOOTPqgnSrdV0etA==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@oven/bun-darwin-x64": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.3.8.tgz",
"integrity": "sha512-SaWIxsRQYiT/eA60bqA4l8iNO7cJ6YD8ie82RerRp9voceBxPIZiwX4y20cTKy5qNaSGr9LxfYq7vDywTipiog==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@oven/bun-darwin-x64-baseline": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64-baseline/-/bun-darwin-x64-baseline-1.3.8.tgz",
"integrity": "sha512-ArHVWpCRZI3vGLoN2/8ud8Kzqlgn1Gv+fNw+pMB9x18IzgAEhKxFxsWffnoaH21amam4tAOhpeewRIgdNtB0Cw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
]
},
"node_modules/@oven/bun-linux-aarch64": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.3.8.tgz",
"integrity": "sha512-rq0nNckobtS+ONoB95/Frfqr8jCtmSjjjEZlN4oyUx0KEBV11Vj4v3cDVaWzuI34ryL8FCog3HaqjfKn8R82Tw==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-aarch64-musl": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-musl/-/bun-linux-aarch64-musl-1.3.8.tgz",
"integrity": "sha512-HvJmhrfipL7GtuqFz6xNpmf27NGcCOMwCalPjNR6fvkLpe8A7Z1+QbxKKjOglelmlmZc3Vi2TgDUtxSqfqOToQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.3.8.tgz",
"integrity": "sha512-YDgqVx1MI8E0oDbCEUSkAMBKKGnUKfaRtMdLh9Bjhu7JQacQ/ZCpxwi4HPf5Q0O1TbWRrdxGw2tA2Ytxkn7s1Q==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64-baseline": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-baseline/-/bun-linux-x64-baseline-1.3.8.tgz",
"integrity": "sha512-3IkS3TuVOzMqPW6Gg9/8FEoKF/rpKZ9DZUfNy9GQ54+k4PGcXpptU3+dy8D4iDFCt4qe6bvoiAOdM44OOsZ+Wg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64-musl": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl/-/bun-linux-x64-musl-1.3.8.tgz",
"integrity": "sha512-o7Jm5zL4aw9UBs3BcZLVbgGm2V4F10MzAQAV+ziKzoEfYmYtvDqRVxgKEq7BzUOVy4LgfrfwzEXw5gAQGRrhQQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-linux-x64-musl-baseline": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl-baseline/-/bun-linux-x64-musl-baseline-1.3.8.tgz",
"integrity": "sha512-5g8XJwHhcTh8SGoKO7pR54ILYDbuFkGo+68DOMTiVB5eLxuLET+Or/camHgk4QWp3nUS5kNjip4G8BE8i0rHVQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
]
},
"node_modules/@oven/bun-windows-x64": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.3.8.tgz",
"integrity": "sha512-UDI3rowMm/tI6DIynpE4XqrOhr+1Ztk1NG707Wxv2nygup+anTswgCwjfjgmIe78LdoRNFrux2GpeolhQGW6vQ==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@oven/bun-windows-x64-baseline": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/@oven/bun-windows-x64-baseline/-/bun-windows-x64-baseline-1.3.8.tgz",
"integrity": "sha512-K6qBUKAZLXsjAwFxGTG87dsWlDjyDl2fqjJr7+x7lmv2m+aSEzmLOK+Z5pSvGkpjBp3LXV35UUgj8G0UTd0pPg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
]
},
"node_modules/@pkgjs/parseargs": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",

View file

@ -20,6 +20,7 @@
"@babel/preset-env": "^7.24.7",
"@biomejs/biome": "1.6.4",
"@google/generative-ai": "^0.11.4",
"@modelcontextprotocol/ext-apps": "^1.0.1",
"@shikijs/colorized-brackets": "^3.7.0",
"@shikijs/transformers": "^3.7.0",
"@types/diff": "^7.0.1",

View file

@ -28,6 +28,7 @@ import {
FileSymbolMap,
IdeSettings,
LLMFullCompletionOptions,
McpUiState,
MessageOption,
ModelDescription,
PromptLog,
@ -316,6 +317,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
contextItems: ContextItem[];
errorMessage?: string;
errorReason?: ContinueErrorReason;
mcpUiState?: McpUiState;
},
];
"tools/evaluatePolicy": [

View file

@ -1,5 +1,5 @@
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
import { ContextItem, Tool, ToolCall, ToolExtras } from "..";
import { ContextItem, McpUiState, Tool, ToolCall, ToolExtras } from "..";
import { MCPManagerSingleton } from "../context/mcp/MCPManagerSingleton";
import { ContinueError, ContinueErrorReason } from "../util/errors";
import { canParseUrl } from "../util/url";
@ -68,7 +68,10 @@ async function callToolFromUri(
uri: string,
args: any,
extras: ToolExtras,
): Promise<ContextItem[]> {
): Promise<{
contextItems: ContextItem[];
mcpUiState?: McpUiState;
}> {
const parseable = canParseUrl(uri);
if (!parseable) {
throw new Error(`Invalid URI: ${uri}`);
@ -78,7 +81,9 @@ async function callToolFromUri(
switch (parsedUri?.protocol) {
case "http:":
case "https:":
return callHttpTool(uri, args, extras);
return {
contextItems: await callHttpTool(uri, args, extras),
};
case "mcp:":
const decoded = decodeMCPToolUri(uri);
if (!decoded) {
@ -103,6 +108,35 @@ async function callToolFromUri(
throw new Error(JSON.stringify(response.content));
}
let mcpUiState: McpUiState | undefined = undefined;
const uiResourceUri =
extras.tool?.mcpMeta?.ui?.resourceUri ||
extras.tool?.mcpMeta?.["ui/resourceUri"];
if (uiResourceUri) {
try {
const resource = await client.getResource(uiResourceUri);
// only single content supported for UI for now
if (resource.contents?.length) {
for (const c of resource.contents) {
if ("text" in c && typeof c.text === "string") {
mcpUiState = {
content: c,
};
}
}
}
if (!mcpUiState) {
console.error(
"Invalid MCP UI resource content",
JSON.stringify(resource),
);
}
} catch (e) {
console.error("Error fetching MCP UI resource", e);
}
}
const contextItems: ContextItem[] = [];
(response.content as any).forEach((item: any) => {
if (item.type === "text") {
@ -140,7 +174,7 @@ async function callToolFromUri(
});
}
});
return contextItems;
return { contextItems, mcpUiState };
default:
throw new Error(`Unsupported protocol: ${parsedUri?.protocol}`);
}
@ -202,20 +236,25 @@ export async function callTool(
contextItems: ContextItem[];
errorMessage: string | undefined;
errorReason?: ContinueErrorReason;
mcpUiState?: McpUiState;
}> {
try {
const args = safeParseToolCallArgs(toolCall);
const contextItems = tool.uri
const { contextItems, mcpUiState } = tool.uri
? await callToolFromUri(tool.uri, args, extras)
: await callBuiltInTool(tool.function.name, args, extras);
: {
contextItems: await callBuiltInTool(tool.function.name, args, extras),
};
if (tool.faviconUrl) {
contextItems.forEach((item) => {
item.icon = tool.faviconUrl;
});
}
return {
contextItems,
errorMessage: undefined,
mcpUiState,
};
} catch (e) {
let errorMessage = `${e}`;

View file

@ -1,14 +1,18 @@
import { MCPServerStatus, MCPTool } from "..";
export function getMCPToolName(server: MCPServerStatus, tool: MCPTool) {
return getToolNameFromMCPServer(server.name, tool.name);
}
export function getToolNameFromMCPServer(serverName: string, toolName: string) {
// Replace any sequence of non-alphanumeric characters with a single underscore
const serverPrefix = server.name
const serverPrefix = serverName
.toLowerCase()
.replace(/[^a-z0-9]+/g, "_")
.replace(/^_+|_+$/g, "") // Remove leading/trailing underscores
.replace(/_+/g, "_"); // Replace multiple sequential underscores with single underscore
if (tool.name.startsWith(serverPrefix)) {
return tool.name;
if (toolName.startsWith(serverPrefix)) {
return toolName;
}
return `${serverPrefix}_${tool.name}`;
return `${serverPrefix}_${toolName}`;
}

1146
gui/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -20,6 +20,7 @@
"@continuedev/terminal-security": "file:../packages/terminal-security",
"@headlessui/react": "^2.2.0",
"@heroicons/react": "^2.0.18",
"@modelcontextprotocol/ext-apps": "^1.0.1",
"@panzoom/panzoom": "^4.6.0",
"@reduxjs/toolkit": "^2.11.2",
"@sentry/react": "^9.43.0",

View file

@ -0,0 +1,414 @@
import {
McpUiResourceCsp,
McpUiResourcePermissions,
PostMessageTransport,
} from "@modelcontextprotocol/ext-apps";
import {
AppBridge,
buildAllowAttribute,
} from "@modelcontextprotocol/ext-apps/app-bridge";
import { ToolCallState } from "core";
import { getToolNameFromMCPServer } from "core/tools/mcpToolName";
import { generateOpenAIToolCallId } from "core/tools/systemMessageTools/systemToolUtils";
import { renderContextItems } from "core/util/messageContent";
import {
useCallback,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { useAppDispatch } from "../../../redux/hooks";
import { streamResponseThunk } from "../../../redux/thunks/streamResponse";
/**
* Build a CSP meta tag content string from McpUiResourceCsp configuration.
* This allows the iframe to make network requests to the specified domains.
*/
function buildCspMetaContent(csp: McpUiResourceCsp | undefined): string {
const resourceDomains = csp?.resourceDomains ?? [];
const connectDomains = csp?.connectDomains ?? [];
// Combine all external domains for resource loading
const allDomains = [...new Set([...resourceDomains, ...connectDomains])];
const defaultSrc = [
"'self'",
"'unsafe-inline'",
"'unsafe-eval'",
"blob:",
"data:",
...allDomains,
].join(" ");
const scriptSrc = [
"'self'",
"'unsafe-inline'",
"'unsafe-eval'",
"blob:",
...allDomains,
].join(" ");
const styleSrc = ["'self'", "'unsafe-inline'", ...allDomains].join(" ");
const imgSrc = ["'self'", "blob:", "data:", ...allDomains].join(" ");
const fontSrc = ["'self'", "data:", ...allDomains].join(" ");
const connectSrc = ["'self'", "blob:", "data:", ...allDomains].join(" ");
const mediaSrc = ["'self'", "blob:", "data:", ...allDomains].join(" ");
const frameSrc = ["'self'", "blob:", "data:", ...allDomains].join(" ");
const workerSrc = ["'self'", "blob:", ...allDomains].join(" ");
const directives = [
`default-src ${defaultSrc}`,
`script-src ${scriptSrc}`,
`style-src ${styleSrc}`,
`img-src ${imgSrc}`,
`font-src ${fontSrc}`,
`connect-src ${connectSrc}`,
`media-src ${mediaSrc}`,
`frame-src ${frameSrc}`,
`worker-src ${workerSrc}`,
];
return directives.join("; ");
}
/**
* MCP App renderer using AppBridge with srcdoc iframe.
* VS Code webviews have restrictive CSP that blocks iframe src URLs,
* so we embed HTML directly via srcdoc and use AppBridge for the protocol.
*
* Handles MCP UI resource metadata:
* - `permissions`: Sets iframe `allow` attribute (camera, microphone, geolocation, clipboard-write)
* - `csp`: Passes CSP config to the app via sendSandboxResourceReady
* - `prefersBorder`: Controls iframe border styling
*
* Note on permissions: We properly set the iframe's `allow` attribute based on
* the MCP resource metadata. However, VS Code's webview runs in a sandboxed
* Electron context with its own Permissions-Policy that doesn't allow delegating
* sensitive permissions (microphone, camera, etc.) to nested iframes. This is a
* VS Code/Electron security limitation that cannot be overridden from extensions.
*/
export function McpAppRenderer({
toolCallState,
}: {
toolCallState: ToolCallState;
}) {
const ideMessenger = useContext(IdeMessengerContext);
const dispatch = useAppDispatch();
const iframeRef = useRef<HTMLIFrameElement>(null);
const appBridgeRef = useRef<AppBridge | null>(null);
const [iframeHeight, setIframeHeight] = useState(300);
const [isInitialized, setIsInitialized] = useState(false);
const [error, setError] = useState<Error | null>(null);
const html = toolCallState.mcpUiState?.content.text;
const uiMeta = toolCallState.mcpUiState?.content._meta?.ui;
const toolInput = toolCallState.parsedArgs;
const toolResult = toolCallState.output;
// Extract metadata from the MCP UI resource
const csp: McpUiResourceCsp | undefined = uiMeta?.csp;
const permissions: McpUiResourcePermissions | undefined = uiMeta?.permissions;
const prefersBorder = uiMeta?.prefersBorder ?? true;
const [permissionWarningDismissed, setPermissionWarningDismissed] =
useState(false);
const restrictedPermissions = useMemo(() => {
const restricted: string[] = [];
if (permissions?.microphone) restricted.push("microphone");
if (permissions?.camera) restricted.push("camera");
if (permissions?.geolocation) restricted.push("geolocation");
return restricted;
}, [permissions]);
const hasRestrictedPermissions = restrictedPermissions.length > 0;
const sandboxAttribute = useMemo(() => {
// SECURITY: Do NOT add 'allow-same-origin' together with 'allow-scripts'.
// This combination allows untrusted MCP HTML to access the parent webview
// via window.parent, defeating iframe sandboxing. Communication via
// PostMessageTransport works without same-origin access.
const sandboxPermissions = [
"allow-scripts", // Required for MCP app JavaScript execution
"allow-forms", // Allow form submissions within the iframe
];
return sandboxPermissions.join(" ");
}, []);
const allowAttribute = useMemo(() => {
const attr = buildAllowAttribute(permissions);
return attr || undefined;
}, [permissions]);
useEffect(() => {
const bridge = new AppBridge(
null,
{ name: "Continue", version: "1.0.0" },
{
openLinks: {},
logging: {},
message: { text: {} },
updateModelContext: { text: {}, structuredContent: {} },
serverTools: {},
},
);
bridge.onsizechange = (params: { width?: number; height?: number }) => {
if (params.height !== undefined) {
setIframeHeight(Math.min(Math.max(params.height + 20, 100), 800));
}
};
bridge.oninitialized = () => {
setIsInitialized(true);
};
bridge.onopenlink = async (params: { url: string }) => {
if (params.url) {
ideMessenger.post("openUrl", params.url);
}
return {};
};
bridge.onmessage = async (params: { role: string; content: unknown[] }) => {
const text = params.content
.filter((item: any) => item.type === "text" && item.text)
.map((item: any) => item.text)
.join("\n");
if (!text) {
console.warn(
"[McpAppRenderer] onMessage received with no text content",
);
return {};
}
const editorState = {
type: "doc",
content: [
{
type: "paragraph",
content: [{ type: "text", text }],
},
],
};
void dispatch(
streamResponseThunk({
editorState,
modifiers: { noContext: true, useCodebase: false },
}),
);
return {};
};
bridge.oncalltool = async (params: any) => {
const output = await ideMessenger.request("tools/call", {
toolCall: {
function: {
name: getToolNameFromMCPServer(
toolCallState.tool?.group ?? "",
params.name,
),
arguments: JSON.stringify(params.arguments),
},
id: generateOpenAIToolCallId(),
type: "function",
},
});
if (output.status === "error") {
throw new Error(`Failed to call tool from MCP UI: ${output.error}`);
}
return {
content: output.content.contextItems.map((ci) => ({
type: "text",
text: renderContextItems([ci]),
})),
isError: false,
};
};
bridge.onlistresources = async () => {
return { resources: [] };
};
bridge.onreadresource = async () => {
throw new Error("Resource reads not supported in this context");
};
bridge.onloggingmessage = (params: {
level: string;
logger?: string;
data: unknown;
}) => {
const logFn =
params.level === "error" || params.level === "critical"
? console.error
: params.level === "warning"
? console.warn
: console.log;
logFn(
`[MCP App${params.logger ? ` - ${params.logger}` : ""}]`,
params.data,
);
};
bridge.onupdatemodelcontext = async () => {
return {};
};
appBridgeRef.current = bridge;
return () => {
appBridgeRef.current = null;
};
}, [ideMessenger, dispatch]);
// Connect bridge to iframe when it loads
const handleIframeLoad = useCallback(async () => {
const iframe = iframeRef.current;
const bridge = appBridgeRef.current;
if (!iframe?.contentWindow || !bridge) return;
try {
const transport = new PostMessageTransport(
iframe.contentWindow,
iframe.contentWindow,
);
await bridge.connect(transport);
if (html) {
await bridge.sendSandboxResourceReady({
html,
csp,
permissions,
});
}
} catch (err) {
console.error("[Continue] Failed to connect bridge to MCP App UI:", err);
setError(err instanceof Error ? err : new Error(String(err)));
}
}, [html, csp, permissions]);
useEffect(() => {
const bridge = appBridgeRef.current;
if (!bridge || !isInitialized || !toolInput) return;
bridge.sendToolInput({ arguments: toolInput });
}, [isInitialized, toolInput]);
useEffect(() => {
const bridge = appBridgeRef.current;
if (!bridge || !isInitialized || !toolResult) return;
bridge.sendToolResult({
content: toolResult.map((o) => ({
type: "text" as const,
text: o.content,
})),
});
}, [isInitialized, toolResult]);
if (!toolCallState.mcpUiState || !html) {
return null;
}
if (error) {
return (
<div className="rounded border border-red-500 bg-red-500/10 p-3 text-sm">
<p className="font-medium text-red-500">MCP UI Error</p>
<p className="text-red-400">{error.message}</p>
</div>
);
}
const cspMetaContent = buildCspMetaContent(csp);
const srcdoc = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="${cspMetaContent}">
<style>
html, body {
margin: 0;
padding: 0;
}
/* Minimal scrollbar styling */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: rgba(128, 128, 128, 0.4);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(128, 128, 128, 0.6);
}
::-webkit-scrollbar-corner {
background: transparent;
}
/* Firefox */
html {
scrollbar-width: thin;
scrollbar-color: rgba(128, 128, 128, 0.4) transparent;
}
</style>
</head>
<body>
${html}
</body>
</html>`;
return (
<div style={{ position: "relative", width: "100%" }}>
<iframe
ref={iframeRef}
srcDoc={srcdoc}
sandbox={sandboxAttribute}
allow={allowAttribute}
onLoad={handleIframeLoad}
className={`bg-input w-full ${
prefersBorder ? "border-input rounded border" : "border-none"
}`}
style={{ height: iframeHeight }}
title={`MCP App - ${toolCallState.toolCall.function.name}`}
/>
{hasRestrictedPermissions && !permissionWarningDismissed && (
<div
className={`absolute inset-0 z-10 flex flex-col items-center justify-center bg-black/85 p-5 ${
prefersBorder ? "rounded" : ""
}`}
>
<div className="max-w-[25rem] text-center">
<div className="mb-3 text-2xl">⚠️</div>
<p className="text-foreground mb-2 text-sm font-medium">
Limited Functionality
</p>
<p className="text-description mb-4 text-xs leading-relaxed">
This app requires{" "}
<strong className="text-foreground">
{restrictedPermissions.join(", ")}
</strong>{" "}
access, which is not currently supported. Some features may not
work.
</p>
<button
onClick={() => setPermissionWarningDismissed(true)}
className="bg-primary text-primary-foreground hover:bg-primary-hover cursor-pointer rounded border-none px-4 py-2 text-xs font-medium"
>
Continue Anyway
</button>
</div>
</div>
)}
</div>
);
}

View file

@ -3,8 +3,10 @@ import { ToolCallState } from "core";
import { BuiltInToolNames } from "core/tools/builtIn";
import { useState } from "react";
import { useAppSelector } from "../../../redux/hooks";
import { RootState } from "../../../redux/store";
import FunctionSpecificToolCallDiv from "./FunctionSpecificToolCallDiv";
import { GroupedToolCallHeader } from "./GroupedToolCallHeader";
import { McpAppRenderer } from "./MCPAppRenderer";
import { SimpleToolCallUI } from "./SimpleToolCallUI";
import { ToolCallDisplay } from "./ToolCallDisplay";
import { getIconByName, getStatusIcon } from "./utils";
@ -19,7 +21,9 @@ export function ToolCallDiv({
historyIndex,
}: ToolCallDivProps) {
const [open, setOpen] = useState(true);
const availableTools = useAppSelector((state) => state.config.config.tools);
const availableTools = useAppSelector(
(state: RootState) => state.config.config.tools,
);
if (!toolCallStates?.length) return null;
@ -43,6 +47,19 @@ export function ToolCallDiv({
? getIconByName(tool.toolCallIcon)
: undefined;
if (toolCallState.mcpUiState) {
return (
<ToolCallDisplay
icon={getStatusIcon(toolCallState.status)}
tool={tool}
toolCallState={toolCallState}
historyIndex={historyIndex}
>
<McpAppRenderer toolCallState={toolCallState} />
</ToolCallDisplay>
);
}
if (icon) {
return (
<SimpleToolCallUI

View file

@ -0,0 +1,3 @@
declare module "@modelcontextprotocol/ext-apps/app-bridge" {
export * from "@modelcontextprotocol/ext-apps/dist/src/app-bridge";
}

View file

@ -15,6 +15,7 @@ import {
ContextItem,
ContextItemWithId,
FileSymbolMap,
McpUiState,
MessageModes,
PromptLog,
RuleMetadata,
@ -859,6 +860,7 @@ export const sessionSlice = createSlice({
action: PayloadAction<{
toolCallId: string;
contextItems: ContextItem[];
mcpUiState?: McpUiState;
}>,
) => {
// Update tool call state and corresponding tool output message
@ -868,6 +870,7 @@ export const sessionSlice = createSlice({
);
if (toolCallState) {
toolCallState.output = action.payload.contextItems;
toolCallState.mcpUiState = action.payload.mcpUiState;
}
const toolItem = findChatHistoryItemByToolCallId(
state.history,

View file

@ -1,5 +1,5 @@
import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
import { ContextItem } from "core";
import { ContextItem, McpUiState } from "core";
import { CLIENT_TOOLS_IMPLS } from "core/tools/builtIn";
import { ContinueError, ContinueErrorReason } from "core/util/errors";
import posthog from "posthog-js";
@ -57,6 +57,7 @@ export const callToolById = createAsyncThunk<
);
let output: ContextItem[] | undefined = undefined;
let mcpUiState: McpUiState | undefined = undefined;
let error: ContinueError | undefined = undefined;
let streamResponse: boolean;
@ -92,6 +93,7 @@ export const callToolById = createAsyncThunk<
throw new Error(result.error);
} else {
output = result.content.contextItems;
mcpUiState = result.content.mcpUiState;
error = result.content.errorMessage
? new ContinueError(
result.content.errorReason || ContinueErrorReason.Unspecified,
@ -122,6 +124,7 @@ export const callToolById = createAsyncThunk<
updateToolCallOutput({
toolCallId,
contextItems: output,
mcpUiState,
}),
);
}