Repository navigation
add option for MCP apps support - #69039
Conversation
Greptile SummaryThis PR adds opt-in MCP Apps host support ( The visibility-enforcement logic (three-state Confidence Score: 4/5Safe to merge with minor cleanup; the bridge resource-leak in the error path is the only non-trivial finding. All P0/P1 security controls (feature flag, tool visibility enforcement, sandboxed iframe, security audit warning) are in place and tested. The two findings are P2: a resource leak when the bridge handshake fails, and a readability note on the default-allow visibility logic. Neither blocks correct behaviour under the normal success path. ui/src/ui/components/mcp-app-view.ts — catch block in _setupBridge should call _teardown() to avoid leaving the bridge/transport alive on connect failure. Prompt To Fix All With AIThis is a comment left during a code review.
Path: ui/src/ui/components/mcp-app-view.ts
Line: 232-236
Comment:
**Bridge and transport not torn down on connect failure**
When `Promise.all([loadPromise, connectPromise])` rejects (e.g., the 15 s iframe-load timeout fires, or the bridge handshake fails), `this._bridge` and `this._closeTransport` are left set but the catch block only records the error string — it does not call `_teardown()`. The dangling bridge will keep its internal listeners alive until the next `_setupBridge` call or `disconnectedCallback`.
```suggestion
} catch (err) {
if (!this._disposed) {
this._error = err instanceof Error ? err.message : String(err);
this._teardown();
this._disposed = false; // keep component alive to show error
}
}
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/gateway/server-methods/mcp-app-proxy.ts
Line: 51-68
Comment:
**Implicit default-allow for tools with no `uiVisibility` annotation**
The guard `tool.uiVisibility?.includes("app") === false` throws only when `uiVisibility` is defined and excludes `"app"`. When `uiVisibility` is `undefined` the optional-chain short-circuits to `undefined`, and `undefined === false` is `false`, so the tool silently passes through. This is the same logic as `isAppCallableTool`, so the behavior is internally consistent, but the intent ("default-allow" for unannotated tools) is easy to misread.
A comment or a named helper that spells out the three-state semantics (undefined = both, ["model"] = model-only, ["app"] = app-only) would help reviewers and future maintainers avoid accidentally tightening this in a way that breaks unlabeled tools.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "add option for MCP apps support" | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a3a1489046
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
a3a1489 to
34f609a
Compare
🔒 Aisle Security AnalysisWe found 7 potential security issue(s) in this PR:
1. 🟠 Session key (bearer capability) and tool data embedded into MCP App canvas JSON and propagated to UI
DescriptionThe MCP App canvas metadata includes Security impact:
Vulnerable code: const mcpApp: McpAppViewMeta = {
serverName: params.serverName,
toolName: params.toolName,
uiResourceUri: params.uiResourceUri,
...(params.runtime.sessionKey ? { sessionKey: params.runtime.sessionKey } : {}),
};
...
const mcpApp = {
...params.view.mcpApp,
toolInput: params.toolInput,
toolResult: params.toolResult,
};
return JSON.stringify({ ..., mcpApp });Even though the iframe is sandboxed, the app does not need the RecommendationDo not serialize bearer credentials or sensitive tool payloads into chat/canvas JSON.
Example (server-side): // Do not include sessionKey in view metadata
const mcpApp: McpAppViewMeta = {
serverName: params.serverName,
toolName: params.toolName,
uiResourceUri: params.uiResourceUri,
};
// Persist only non-sensitive metadata
return JSON.stringify({
kind: "canvas",
...,
mcpApp,
});Example (client-side): // In mcp-app-view.ts
const sessionKey = ctx.sessionKey; // only from in-memory contextAdditionally: add automated tests/audits to ensure 2. 🟠 Default-allow app access to unannotated MCP tools via mcp-app proxy
DescriptionThe MCP app proxy gateway methods allow an app UI to list and invoke MCP tools based on
Vulnerable code: function isAppCallableTool(tool: McpCatalogTool): boolean {
// Unannotated tools predate MCP Apps and remain visible to both model and app callers.
return tool.uiVisibility === undefined || tool.uiVisibility.includes("app");
}RecommendationChange the policy to default-deny for app callers, requiring an explicit app visibility annotation. Suggested fix: function isAppCallableTool(tool: McpCatalogTool): boolean {
// Safer default: only explicitly app-visible tools can be called by apps.
return tool.uiVisibility?.includes("app") === true;
}If backward compatibility is required, gate legacy/default-allow behavior behind a config flag (e.g., 3. 🟠 Unbounded MCP UI resource decoding and persistence can cause memory/disk exhaustion (DoS)
Description
Vulnerable code: const html =
"text" in content && typeof content.text === "string"
? content.text
: "blob" in content && typeof content.blob === "string"
? Buffer.from(content.blob, "base64").toString("utf8")
: undefined;
...
entrypoint: { type: "html", value: html },RecommendationEnforce strict maximum sizes for MCP UI resources before decoding and before writing to disk. Suggested approach:
Example: const MAX_HTML_BYTES = 2 * 1024 * 1024; // 2MB
function assertMaxBytesUtf8(s: string, max: number) {
if (Buffer.byteLength(s, "utf8") > max) {
throw new Error(`MCP UI resource too large (${Buffer.byteLength(s, "utf8")} bytes)`);
}
}
let html: string | undefined;
if ("text" in content && typeof content.text === "string") {
assertMaxBytesUtf8(content.text, MAX_HTML_BYTES);
html = content.text;
} else if ("blob" in content && typeof content.blob === "string") {
// base64 length check (~4/3 expansion)
if (content.blob.length > Math.ceil(MAX_HTML_BYTES * 4 / 3) + 16) {
throw new Error("MCP UI resource blob too large");
}
const decoded = Buffer.from(content.blob, "base64");
if (decoded.length > MAX_HTML_BYTES) throw new Error("MCP UI resource too large");
html = decoded.toString("utf8");
}4. 🟠 IDOR/broken access control: MCP app proxy methods accept arbitrary sessionKey and recreate runtimes
DescriptionIn
Vulnerable flow: const sessionKey = requireString(params, "sessionKey");
const runtime = await resolveRuntime(sessionKey);
...
const result = await runtime.readResource(serverName, uri);and in const agentId = resolveSessionAgentId({ sessionKey, config: cfg });
...
return await getOrCreateSessionMcpRuntime({
sessionId: `mcp-app:${sessionKey}`,
sessionKey,
...
});
RecommendationBind Recommended approaches (pick what matches your architecture):
Example pattern (illustrative): "mcp.readResource": async ({ respond, params, client, context }) => {
const sessionKey = requireString(params, "sessionKey");
// 1) Verify sessionKey belongs to this authenticated client/principal
const allowed = await context.sessionAuth.canAccessSessionKey({
principal: client.connect?.principalId,
sessionKey,
});
if (!allowed) {
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "unauthorized session"));
return;
}
// 2) Only then resolve runtime
const runtime = await resolveRuntime(sessionKey);
requireMcpAppsEnabled(runtime);
...
}Additionally:
5. 🟠 Unrestricted MCP resource URI proxy allows untrusted MCP Apps to read arbitrary resources (SSRF/LFI)
DescriptionThe gateway handler This is dangerous because MCP Apps are rendered as untrusted HTML/JS in an iframe and can invoke the AppBridge methods:
Vulnerable code: const uri = requireString(params, "uri");
...
const result = await runtime.readResource(serverName, uri);RecommendationEnforce a strict allowlist for app-initiated resource reads. At minimum, only allow Example (scheme allowlist + optional length limit): function requireUiResourceUri(uri: string): string {
if (!uri.startsWith("ui://")) {
throw new Error("only ui:// resources may be read by MCP Apps");
}
if (uri.length > 2048) {
throw new Error("resource URI too long");
}
return uri;
}
// in handler
const uri = requireUiResourceUri(requireString(params, "uri"));
const result = await runtime.readResource(serverName, uri);Additionally consider:
6. 🟠 MCP App iframe can be rendered with `allow-same-origin`, enabling same-origin XSS/privilege escalation
DescriptionThe Control UI renders MCP server-supplied HTML inside an iframe. The iframe sandbox flags are derived from When
Vulnerable code paths:
Vulnerable code: // ui/src/ui/embed-sandbox.ts
case "trusted":
return "allow-scripts allow-same-origin";
// ui/src/ui/components/mcp-app-view.ts
iframe.setAttribute(
"sandbox",
`${resolveEmbedSandbox(this.sandboxMode)} allow-forms allow-popups`,
);Because the embedded content is explicitly fetched from an MCP server resource and stored as an HTML canvas document, treating it as "trusted" creates an XSS-equivalent condition (arbitrary script running with the app/control UI origin). RecommendationPrevent untrusted MCP App HTML from ever being embedded with Options:
// Always origin-isolate MCP apps
const sandbox = `allow-scripts allow-forms allow-popups`; // no allow-same-origin
iframe.setAttribute("sandbox", sandbox);
At minimum, ensure MCP Apps never receive 7. 🟡 MCP UI resource response is not strictly validated (content substitution / confused deputy)
Description
This lets a malicious/compromised MCP server return a different resource than requested (or omit Vulnerable code: const content =
resource.contents.find((item) => item.uri === params.uiResourceUri) ?? resource.contents[0];
...
if (
typeof content.mimeType === "string" &&
content.mimeType.trim() &&
content.mimeType !== MCP_APP_RESOURCE_MIME_TYPE
) {
return undefined;
}RecommendationTighten validation of the
Example: const content = resource.contents.find((item) => item.uri === params.uiResourceUri);
if (!content) throw new Error(`Resource response missing requested uri: ${params.uiResourceUri}`);
if (content.mimeType !== MCP_APP_RESOURCE_MIME_TYPE) {
throw new Error(`Unexpected mimeType: ${String(content.mimeType)}`);
}Analyzed PR: #69039 at commit Last updated on: 2026-04-20T01:56:00Z |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 34f609af9f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
34f609a to
8a5a40f
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a5a40f8d4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
8a5a40f to
bb2e842
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb2e8428d6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
bb2e842 to
12bd3f8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4f391fe898
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps specification support on exact head 381acc2a1afd4d27399b7cf10cf9dc4bc43422b8. |
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps specification support on exact head 495b882213f6f11e176889bcb170b3991edfb31e. |
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps specification support on exact head 8989d992d3840082af2dec07b5efd56e7f182b02. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8989d992d3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps specification support on exact head e8d5123dd5703a63b269865a7f6541bb5b07b740. |
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps specification support on exact head 5b56267baff43c08d3aabf0dd80fa6af4ef85e2a. |
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps specification support on exact head 3076a015bd1ec787391ac2ea4c9669a46d34810d. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3076a015bd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps support on exact head 3076a015bd1ec787391ac2ea4c9669a46d34810d. |
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps support on rebased exact head 0687d5387fcf17856d056d54cd08da5d4f882e35. |
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps support on consolidated exact head 1a2c400ee92c1134a737439206e0ed27980afdee. |
Land-ready maintainer proofReviewed and consolidated on exact head
Official app rendered
App-to-server bridge call updated live data
Refresh restored one app instance
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a2c400ee9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Implement stable opt-in MCP Apps negotiation, caller-specific tool visibility, bounded ephemeral UI resources, a dedicated-origin double iframe host, restrictive CSP, configuration, docs, and regression tests. Co-authored-by: Sally O'Malley <[email protected]>
|
/allow-dependencies-change Required official @modelcontextprotocol/ext-apps bridge dependency for stable MCP Apps support on final rebased exact head f08d45e. |
|
Merged via squash.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f08d45e78a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (hostOrigin === null) hostOrigin = event.origin; | ||
| if (event.origin !== hostOrigin) return; |
There was a problem hiding this comment.
Gate MCP App sandbox messages to the Control UI
When mcp.apps.enabled exposes the sandbox listener on localhost or a LAN address, any unrelated web page that can iframe /mcp-app-sandbox becomes the first parent here, because the proxy records that page's event.origin and later accepts sandbox-resource-ready HTML from it without a nonce, auth check, or frame-ancestors restriction. That turns the dedicated listener into an arbitrary-origin HTML execution gadget rather than a Control-UI-only MCP App host; require an unguessable token from mcp.app.view or restrict allowed parent origins before trusting the first message.
Useful? React with 👍 / 👎.



Summary
mcp.apps.enabled=true.mcp.apps.enabled; this does not add a marketplace, new MCP server examples, or plugin-only architecture.Change Type (select all)
Scope (select all touched areas)
Regression Test Plan (if applicable)
MCP app-only tools are not materialized for the model.
MCP Apps UI payloads are only fetched/rendered when
mcp.apps.enabled=true.App bridge calls are rejected when MCP Apps are disabled.
App bridge calls enforce app-callable tool visibility.
Persisted/restored app views can recreate an MCP runtime after gateway restart.
Existing
[embed]canvas rendering remains the fallback path when MCP Apps metadata is absent or disabled.Target test or file:
mcp.apps.enabled.openclaw security auditnow warns when MCP Apps are enabled.Scenario the test should lock in:
mcp.apps.enabled=true.Why this is the smallest reliable guardrail:
Existing test that already covers this (if any):
User-visible / Behavior Changes
mcp.apps.enabled.openclaw security auditnow warns when MCP Apps are enabled.Diagram (if applicable)
Security Impact (required)
New permissions/capabilities? (
Yes/No): YesSecrets/tokens handling changed? (
Yes/No): NoNew/changed network calls? (
Yes/No): No for normal MCP transport; Yes in the sense that enabled MCP Apps can make app-initiated MCP calls back through the existing MCP session runtime.Command/tool execution surface changed? (
Yes/No): YesData access scope changed? (
Yes/No): YesIf any
Yes, explain risk + mitigation:mcp.apps.enabled=true.mcp.*gateway methods.openclaw security auditwarns when MCP Apps are enabled.Trust model: enabling MCP Apps means trusting the configured MCP servers not only as tool providers, but also as UI code providers.
Repro + Verification
Environment
{ "mcp": { "apps": { "enabled": true }, "servers": { "system-monitor": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-system-monitor", "--stdio"] }, "pdf": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-pdf", "--stdio"] }, "qr": { "url": "http://127.0.0.1:3108/mcp", "transport": "streamable-http" } } } }Steps
Expected
Actual
Attach at least one:
Human Verification (required)
poc-mcp-apps.mp4
Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes/No) YesYes/No) YesYes/No) Nomcp-uiresources.Risks and Mitigations
mcp.apps.enabled; app UI renders in a sandboxed iframe; docs and security audit call out the trust boundary.