-
Notifications
You must be signed in to change notification settings - Fork 78
feat: add sandbox flags negotiation #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { RESOURCE_MIME_TYPE, getToolUiResourceUri, type McpUiSandboxProxyReadyNotification, AppBridge, PostMessageTransport, type McpUiResourceCsp, type McpUiResourcePermissions, buildAllowAttribute, type McpUiUpdateModelContextRequest, type McpUiMessageRequest } from "@modelcontextprotocol/ext-apps/app-bridge"; | ||
| import { RESOURCE_MIME_TYPE, getToolUiResourceUri, type McpUiSandboxProxyReadyNotification, AppBridge, PostMessageTransport, type McpUiResourceCsp, type McpUiResourcePermissions, type McpUiResourceSandbox, buildAllowAttribute, buildSandboxAttribute, type McpUiUpdateModelContextRequest, type McpUiMessageRequest } from "@modelcontextprotocol/ext-apps/app-bridge"; | ||
| import { Client } from "@modelcontextprotocol/sdk/client/index.js"; | ||
| import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; | ||
| import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"; | ||
|
|
@@ -66,6 +66,7 @@ interface UiResourceData { | |
| html: string; | ||
| csp?: McpUiResourceCsp; | ||
| permissions?: McpUiResourcePermissions; | ||
| sandbox?: McpUiResourceSandbox; | ||
| } | ||
|
|
||
| export interface ToolCallInfo { | ||
|
|
@@ -136,20 +137,23 @@ async function getUiResource(serverInfo: ServerInfo, uri: string): Promise<UiRes | |
| const contentMeta = (content as any)._meta || (content as any).meta; | ||
| const csp = contentMeta?.ui?.csp; | ||
| const permissions = contentMeta?.ui?.permissions; | ||
| const sandbox = contentMeta?.ui?.sandbox; | ||
|
|
||
| return { html, csp, permissions }; | ||
| return { html, csp, permissions, sandbox }; | ||
| } | ||
|
|
||
|
|
||
| export function loadSandboxProxy( | ||
| iframe: HTMLIFrameElement, | ||
| csp?: McpUiResourceCsp, | ||
| permissions?: McpUiResourcePermissions, | ||
| sandbox?: McpUiResourceSandbox, | ||
|
||
| ): Promise<boolean> { | ||
| // Prevent reload | ||
| if (iframe.src) return Promise.resolve(false); | ||
|
|
||
| iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms"); | ||
| // Set sandbox attribute on outer iframe (must match inner iframe capabilities) | ||
| iframe.setAttribute("sandbox", buildSandboxAttribute(sandbox)); | ||
idosal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Set Permission Policy allow attribute based on requested permissions | ||
| const allowAttribute = buildAllowAttribute(permissions); | ||
|
|
@@ -199,10 +203,10 @@ export async function initializeApp( | |
| new PostMessageTransport(iframe.contentWindow!, iframe.contentWindow!), | ||
| ); | ||
|
|
||
| // Load inner iframe HTML with CSP and permissions metadata | ||
| const { html, csp, permissions } = await appResourcePromise; | ||
| log.info("Sending UI resource HTML to MCP App", csp ? `(CSP: ${JSON.stringify(csp)})` : "", permissions ? `(Permissions: ${JSON.stringify(permissions)})` : ""); | ||
| await appBridge.sendSandboxResourceReady({ html, csp, permissions }); | ||
| // Load inner iframe HTML with CSP, permissions, and sandbox metadata | ||
| const { html, csp, permissions, sandbox } = await appResourcePromise; | ||
| log.info("Sending UI resource HTML to MCP App", csp ? `(CSP: ${JSON.stringify(csp)})` : "", permissions ? `(Permissions: ${JSON.stringify(permissions)})` : "", sandbox ? `(Sandbox: ${JSON.stringify(sandbox)})` : ""); | ||
| await appBridge.sendSandboxResourceReady({ html, csp, permissions, sandbox }); | ||
|
|
||
| // Wait for inner iframe to be ready | ||
| log.info("Waiting for MCP App to initialize..."); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.