@modelcontextprotocol/ext-apps 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/app-bridge.d.ts +28 -1
- package/dist/src/app-bridge.js +6 -6
- package/dist/src/app-with-deps.js +6 -6
- package/dist/src/app.d.ts +40 -2
- package/dist/src/app.js +6 -6
- package/dist/src/generated/schema.d.ts +12 -0
- package/dist/src/generated/schema.json +17 -0
- package/dist/src/generated/schema.test.d.ts +1 -0
- package/dist/src/react/index.js +6 -6
- package/dist/src/react/react-with-deps.js +10 -10
- package/dist/src/server/index.js +5 -5
- package/dist/src/spec.types.d.ts +13 -0
- package/dist/src/types.d.ts +5 -5
- package/package.json +1 -1
package/dist/src/app-bridge.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
|
2
2
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
3
3
|
import { CallToolRequest, CallToolResult, EmptyResult, Implementation, ListPromptsRequest, ListPromptsResult, ListResourcesRequest, ListResourcesResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, LoggingMessageNotification, PingRequest, PromptListChangedNotification, ReadResourceRequest, ReadResourceResult, ResourceListChangedNotification, Tool, ToolListChangedNotification } from "@modelcontextprotocol/sdk/types.js";
|
|
4
4
|
import { Protocol, ProtocolOptions, RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
|
-
import { type AppNotification, type AppRequest, type AppResult, type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolCancelledNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiInitializedNotification, McpUiMessageRequest, McpUiMessageResult, McpUiOpenLinkRequest, McpUiOpenLinkResult, McpUiDownloadFileRequest, McpUiDownloadFileResult, McpUiResourceTeardownRequest, McpUiSandboxProxyReadyNotification, McpUiRequestDisplayModeRequest, McpUiRequestDisplayModeResult, McpUiResourcePermissions } from "./types";
|
|
5
|
+
import { type AppNotification, type AppRequest, type AppResult, type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolCancelledNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiInitializedNotification, McpUiMessageRequest, McpUiMessageResult, McpUiOpenLinkRequest, McpUiOpenLinkResult, McpUiDownloadFileRequest, McpUiDownloadFileResult, McpUiResourceTeardownRequest, McpUiRequestTeardownNotification, McpUiSandboxProxyReadyNotification, McpUiRequestDisplayModeRequest, McpUiRequestDisplayModeResult, McpUiResourcePermissions } from "./types";
|
|
6
6
|
export * from "./types";
|
|
7
7
|
export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE } from "./app";
|
|
8
8
|
export { PostMessageTransport } from "./message-transport";
|
|
@@ -447,6 +447,33 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
447
447
|
* @see {@link McpUiDownloadFileResult `McpUiDownloadFileResult`} for the result type
|
|
448
448
|
*/
|
|
449
449
|
set ondownloadfile(callback: (params: McpUiDownloadFileRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiDownloadFileResult>);
|
|
450
|
+
/**
|
|
451
|
+
* Register a handler for app-initiated teardown request notifications from the view.
|
|
452
|
+
*
|
|
453
|
+
* The view sends `ui/notifications/request-teardown` when it wants the host to tear it down.
|
|
454
|
+
* If the host decides to proceed, it should send
|
|
455
|
+
* `ui/resource-teardown` (via {@link teardownResource `teardownResource`}) to allow
|
|
456
|
+
* the view to perform gracefull termination, then unmount the iframe after the view responds.
|
|
457
|
+
*
|
|
458
|
+
* @param callback - Handler that receives teardown request params
|
|
459
|
+
* - params - Empty object (reserved for future use)
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* bridge.onrequestteardown = async (params) => {
|
|
464
|
+
* console.log("App requested teardown");
|
|
465
|
+
* // Initiate teardown to allow the app to persist unsaved state
|
|
466
|
+
* // Alternatively, the callback can early return to prevent teardown
|
|
467
|
+
* await bridge.teardownResource({});
|
|
468
|
+
* // Now safe to unmount the iframe
|
|
469
|
+
* iframe.remove();
|
|
470
|
+
* };
|
|
471
|
+
* ```
|
|
472
|
+
*
|
|
473
|
+
* @see {@link McpUiRequestTeardownNotification `McpUiRequestTeardownNotification`} for the notification type
|
|
474
|
+
* @see {@link teardownResource `teardownResource`} for initiating teardown
|
|
475
|
+
*/
|
|
476
|
+
set onrequestteardown(callback: (params: McpUiRequestTeardownNotification["params"]) => void);
|
|
450
477
|
/**
|
|
451
478
|
* Register a handler for display mode change requests from the view.
|
|
452
479
|
*
|
package/dist/src/app-bridge.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{CallToolRequestSchema as
|
|
1
|
+
import{CallToolRequestSchema as yQ,CallToolResultSchema as kQ,ListPromptsRequestSchema as fQ,ListPromptsResultSchema as dQ,ListResourcesRequestSchema as bQ,ListResourcesResultSchema as xQ,ListResourceTemplatesRequestSchema as uQ,ListResourceTemplatesResultSchema as hQ,LoggingMessageNotificationSchema as mQ,PingRequestSchema as pQ,PromptListChangedNotificationSchema as cQ,ReadResourceRequestSchema as nQ,ReadResourceResultSchema as iQ,ResourceListChangedNotificationSchema as lQ,ToolListChangedNotificationSchema as rQ}from"@modelcontextprotocol/sdk/types.js";import{Protocol as oQ}from"@modelcontextprotocol/sdk/shared/protocol.js";var G="2026-01-26",s="ui/open-link",e="ui/download-file",QQ="ui/message",XQ="ui/notifications/sandbox-proxy-ready",YQ="ui/notifications/sandbox-resource-ready",ZQ="ui/notifications/size-changed",$Q="ui/notifications/tool-input",_="ui/notifications/tool-input-partial",JQ="ui/notifications/tool-result",KQ="ui/notifications/tool-cancelled",GQ="ui/notifications/host-context-changed",DQ="ui/notifications/request-teardown",NQ="ui/resource-teardown",jQ="ui/initialize",EQ="ui/notifications/initialized",WQ="ui/request-display-mode";import{z as Q}from"zod/v4";import{ContentBlockSchema as h,CallToolResultSchema as zQ,EmbeddedResourceSchema as BQ,ImplementationSchema as m,RequestIdSchema as _Q,ResourceLinkSchema as OQ,ToolSchema as VQ}from"@modelcontextprotocol/sdk/types.js";var p=Q.union([Q.literal("light"),Q.literal("dark")]).describe("Color theme preference for the host environment."),D=Q.union([Q.literal("inline"),Q.literal("fullscreen"),Q.literal("pip")]).describe("Display mode for UI presentation."),IQ=Q.union([Q.literal("--color-background-primary"),Q.literal("--color-background-secondary"),Q.literal("--color-background-tertiary"),Q.literal("--color-background-inverse"),Q.literal("--color-background-ghost"),Q.literal("--color-background-info"),Q.literal("--color-background-danger"),Q.literal("--color-background-success"),Q.literal("--color-background-warning"),Q.literal("--color-background-disabled"),Q.literal("--color-text-primary"),Q.literal("--color-text-secondary"),Q.literal("--color-text-tertiary"),Q.literal("--color-text-inverse"),Q.literal("--color-text-ghost"),Q.literal("--color-text-info"),Q.literal("--color-text-danger"),Q.literal("--color-text-success"),Q.literal("--color-text-warning"),Q.literal("--color-text-disabled"),Q.literal("--color-border-primary"),Q.literal("--color-border-secondary"),Q.literal("--color-border-tertiary"),Q.literal("--color-border-inverse"),Q.literal("--color-border-ghost"),Q.literal("--color-border-info"),Q.literal("--color-border-danger"),Q.literal("--color-border-success"),Q.literal("--color-border-warning"),Q.literal("--color-border-disabled"),Q.literal("--color-ring-primary"),Q.literal("--color-ring-secondary"),Q.literal("--color-ring-inverse"),Q.literal("--color-ring-info"),Q.literal("--color-ring-danger"),Q.literal("--color-ring-success"),Q.literal("--color-ring-warning"),Q.literal("--font-sans"),Q.literal("--font-mono"),Q.literal("--font-weight-normal"),Q.literal("--font-weight-medium"),Q.literal("--font-weight-semibold"),Q.literal("--font-weight-bold"),Q.literal("--font-text-xs-size"),Q.literal("--font-text-sm-size"),Q.literal("--font-text-md-size"),Q.literal("--font-text-lg-size"),Q.literal("--font-heading-xs-size"),Q.literal("--font-heading-sm-size"),Q.literal("--font-heading-md-size"),Q.literal("--font-heading-lg-size"),Q.literal("--font-heading-xl-size"),Q.literal("--font-heading-2xl-size"),Q.literal("--font-heading-3xl-size"),Q.literal("--font-text-xs-line-height"),Q.literal("--font-text-sm-line-height"),Q.literal("--font-text-md-line-height"),Q.literal("--font-text-lg-line-height"),Q.literal("--font-heading-xs-line-height"),Q.literal("--font-heading-sm-line-height"),Q.literal("--font-heading-md-line-height"),Q.literal("--font-heading-lg-line-height"),Q.literal("--font-heading-xl-line-height"),Q.literal("--font-heading-2xl-line-height"),Q.literal("--font-heading-3xl-line-height"),Q.literal("--border-radius-xs"),Q.literal("--border-radius-sm"),Q.literal("--border-radius-md"),Q.literal("--border-radius-lg"),Q.literal("--border-radius-xl"),Q.literal("--border-radius-full"),Q.literal("--border-width-regular"),Q.literal("--shadow-hairline"),Q.literal("--shadow-sm"),Q.literal("--shadow-md"),Q.literal("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),AQ=Q.record(IQ.describe(`Style variables for theming MCP apps.
|
|
2
2
|
|
|
3
3
|
Individual style keys are optional - hosts may provide any subset of these values.
|
|
4
4
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
@@ -16,10 +16,10 @@ Individual style keys are optional - hosts may provide any subset of these value
|
|
|
16
16
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
17
17
|
|
|
18
18
|
Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Record<K, string>>\`
|
|
19
|
-
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),V=Q.object({method:Q.literal("ui/open-link"),params:Q.object({url:Q.string().describe("URL to open in the host's browser")})}),I=Q.object({isError:Q.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),A=Q.object({isError:Q.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),
|
|
19
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),V=Q.object({method:Q.literal("ui/open-link"),params:Q.object({url:Q.string().describe("URL to open in the host's browser")})}),I=Q.object({isError:Q.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),A=Q.object({isError:Q.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),F=Q.object({isError:Q.boolean().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),L=Q.object({method:Q.literal("ui/notifications/sandbox-proxy-ready"),params:Q.object({})}),j=Q.object({connectDomains:Q.array(Q.string()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
|
|
20
20
|
|
|
21
21
|
- Maps to CSP \`connect-src\` directive
|
|
22
|
-
- Empty or omitted → no network connections (secure default)`),resourceDomains:Q.array(Q.string()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:Q.array(Q.string()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:Q.array(Q.string()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),E=Q.object({camera:Q.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:Q.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:Q.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:Q.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),P=Q.object({method:Q.literal("ui/notifications/size-changed"),params:Q.object({width:Q.number().optional().describe("New width in pixels."),height:Q.number().optional().describe("New height in pixels.")})}),T=Q.object({method:Q.literal("ui/notifications/tool-input"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),w=Q.object({method:Q.literal("ui/notifications/tool-input-partial"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),
|
|
22
|
+
- Empty or omitted → no network connections (secure default)`),resourceDomains:Q.array(Q.string()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:Q.array(Q.string()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:Q.array(Q.string()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),E=Q.object({camera:Q.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:Q.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:Q.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:Q.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),P=Q.object({method:Q.literal("ui/notifications/size-changed"),params:Q.object({width:Q.number().optional().describe("New width in pixels."),height:Q.number().optional().describe("New height in pixels.")})}),T=Q.object({method:Q.literal("ui/notifications/tool-input"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),w=Q.object({method:Q.literal("ui/notifications/tool-input-partial"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),R=Q.object({method:Q.literal("ui/notifications/tool-cancelled"),params:Q.object({reason:Q.string().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),c=Q.object({fonts:Q.string().optional()}),n=Q.object({variables:AQ.optional().describe("CSS variables for theming the app."),css:c.optional().describe("CSS blocks that apps can inject.")}),U=Q.object({method:Q.literal("ui/resource-teardown"),params:Q.object({})}),H=Q.record(Q.string(),Q.unknown()),O=Q.object({text:Q.object({}).optional().describe("Host supports text content blocks."),image:Q.object({}).optional().describe("Host supports image content blocks."),audio:Q.object({}).optional().describe("Host supports audio content blocks."),resource:Q.object({}).optional().describe("Host supports resource content blocks."),resourceLink:Q.object({}).optional().describe("Host supports resource link content blocks."),structuredContent:Q.object({}).optional().describe("Host supports structured content.")}),M=Q.object({method:Q.literal("ui/notifications/request-teardown"),params:Q.object({}).optional()}),i=Q.object({experimental:Q.object({}).optional().describe("Experimental features (structure TBD)."),openLinks:Q.object({}).optional().describe("Host supports opening external URLs."),downloadFile:Q.object({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:Q.object({listChanged:Q.boolean().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:Q.object({listChanged:Q.boolean().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:Q.object({}).optional().describe("Host accepts log messages."),sandbox:Q.object({permissions:E.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:j.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:O.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:O.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),l=Q.object({experimental:Q.object({}).optional().describe("Experimental features (structure TBD)."),tools:Q.object({listChanged:Q.boolean().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:Q.array(D).optional().describe("Display modes the app supports.")}),v=Q.object({method:Q.literal("ui/notifications/initialized"),params:Q.object({}).optional()}),FQ=Q.object({csp:j.optional().describe("Content Security Policy configuration for UI resources."),permissions:E.optional().describe("Sandbox permissions requested by the UI resource."),domain:Q.string().optional().describe(`Dedicated origin for view sandbox.
|
|
23
23
|
|
|
24
24
|
Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
|
|
25
25
|
|
|
@@ -33,7 +33,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
33
33
|
|
|
34
34
|
- \`true\`: request visible border + background
|
|
35
35
|
- \`false\`: request no visible border + background
|
|
36
|
-
- omitted: host decides border`)}),W=Q.object({method:Q.literal("ui/request-display-mode"),params:Q.object({mode:D.describe("The display mode being requested.")})}),
|
|
36
|
+
- omitted: host decides border`)}),W=Q.object({method:Q.literal("ui/request-display-mode"),params:Q.object({mode:D.describe("The display mode being requested.")})}),g=Q.object({mode:D.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),r=Q.union([Q.literal("model"),Q.literal("app")]).describe("Tool visibility scope - who can access the tool."),LQ=Q.object({resourceUri:Q.string().optional(),visibility:Q.array(r).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
37
37
|
- "model": Tool visible to and callable by the agent
|
|
38
|
-
- "app": Tool callable by the app from this server only`)}),
|
|
39
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:Q.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:Q.string().optional().describe("User's timezone in IANA format."),userAgent:Q.string().optional().describe("Host application identifier."),platform:Q.union([Q.literal("web"),Q.literal("desktop"),Q.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:Q.object({touch:Q.boolean().optional().describe("Whether the device supports touch input."),hover:Q.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:Q.object({top:Q.number().describe("Top safe area inset in pixels."),right:Q.number().describe("Right safe area inset in pixels."),bottom:Q.number().describe("Bottom safe area inset in pixels."),left:Q.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),k=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:q.describe("Partial context update containing only changed fields.")}),y=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(u).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:Q.record(Q.string(),Q.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),f=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:h.describe("App identification (name and version)."),appCapabilities:i.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),d=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:h.describe("Host application identification and version."),hostCapabilities:n.describe("Features and capabilities provided by the host."),hostContext:q.describe("Rich context about the host environment.")}).passthrough();import{Protocol as PQ}from"@modelcontextprotocol/sdk/shared/protocol.js";import{CallToolRequestSchema as TQ,CallToolResultSchema as wQ,EmptyResultSchema as UQ,ListResourcesResultSchema as HQ,ListToolsRequestSchema as RQ,PingRequestSchema as MQ,ReadResourceResultSchema as vQ}from"@modelcontextprotocol/sdk/types.js";import{JSONRPCMessageSchema as FQ}from"@modelcontextprotocol/sdk/types.js";class N{eventTarget;eventSource;messageListener;constructor(X=window.parent,Y){this.eventTarget=X;this.eventSource=Y;this.messageListener=(Z)=>{if(Y&&Z.source!==this.eventSource){console.debug("Ignoring message from unknown source",Z);return}let $=FQ.safeParse(Z.data);if($.success)console.debug("Parsed message",$.data),this.onmessage?.($.data);else if(Z.data?.jsonrpc!=="2.0")console.debug("Ignoring non-JSON-RPC message",$.error.message,Z);else console.error("Failed to parse message",$.error.message,Z),this.onerror?.(Error("Invalid JSON-RPC message received: "+$.error.message))}}async start(){window.addEventListener("message",this.messageListener)}async send(X,Y){if(X.method!==_)console.debug("Sending message",X);this.eventTarget.postMessage(X,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}var b="ui/resourceUri",SQ="text/html;profile=mcp-app";class CQ extends PQ{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(X,Y={},Z={autoResize:!0}){super(Z);this._appInfo=X;this._capabilities=Y;this.options=Z;this.setRequestHandler(MQ,($)=>{return console.log("Received ping:",$.params),{}}),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(X){this.setNotificationHandler(T,(Y)=>X(Y.params))}set ontoolinputpartial(X){this.setNotificationHandler(w,(Y)=>X(Y.params))}set ontoolresult(X){this.setNotificationHandler(g,(Y)=>X(Y.params))}set ontoolcancelled(X){this.setNotificationHandler(U,(Y)=>X(Y.params))}set onhostcontextchanged(X){this.setNotificationHandler(k,(Y)=>{this._hostContext={...this._hostContext,...Y.params},X(Y.params)})}set onteardown(X){this.setRequestHandler(H,(Y,Z)=>X(Y.params,Z))}set oncalltool(X){this.setRequestHandler(TQ,(Y,Z)=>X(Y.params,Z))}set onlisttools(X){this.setRequestHandler(RQ,(Y,Z)=>X(Y.params,Z))}assertCapabilityForMethod(X){}assertRequestHandlerCapability(X){switch(X){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${X})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${X} registered`)}}assertNotificationCapability(X){}assertTaskCapability(X){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(X){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(X,Y){if(typeof X==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${X}"). Did you mean: callServerTool({ name: "${X}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:X},wQ,Y)}async readServerResource(X,Y){return await this.request({method:"resources/read",params:X},vQ,Y)}async listServerResources(X,Y){return await this.request({method:"resources/list",params:X},HQ,Y)}sendMessage(X,Y){return this.request({method:"ui/message",params:X},L,Y)}sendLog(X){return this.notification({method:"notifications/message",params:X})}updateModelContext(X,Y){return this.request({method:"ui/update-model-context",params:X},UQ,Y)}openLink(X,Y){return this.request({method:"ui/open-link",params:X},I,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this.request({method:"ui/download-file",params:X},A,Y)}requestDisplayMode(X,Y){return this.request({method:"ui/request-display-mode",params:X},v,Y)}sendSizeChanged(X){return this.notification({method:"ui/notifications/size-changed",params:X})}setupSizeChangedNotifications(){let X=!1,Y=0,Z=0,$=()=>{if(X)return;X=!0,requestAnimationFrame(()=>{X=!1;let J=document.documentElement,r=J.style.width,o=J.style.height;J.style.width="fit-content",J.style.height="max-content";let x=J.getBoundingClientRect();J.style.width=r,J.style.height=o;let a=window.innerWidth-J.clientWidth,z=Math.ceil(x.width+a),B=Math.ceil(x.height);if(z!==Y||B!==Z)Y=z,Z=B,this.sendSizeChanged({width:z,height:B})})};$();let K=new ResizeObserver($);return K.observe(document.documentElement),K.observe(document.body),()=>K.disconnect()}async connect(X=new N(window.parent,window.parent),Y){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(X);try{let Z=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:G}},d,Y);if(Z===void 0)throw Error(`Server sent invalid initialize result: ${Z}`);if(this._hostCapabilities=Z.hostCapabilities,this._hostInfo=Z.hostInfo,this._hostContext=Z.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(Z){throw this.close(),Z}}}function hY(X){let Z=X._meta?.ui?.resourceUri;if(Z===void 0)Z=X._meta?.[b];if(typeof Z==="string"&&Z.startsWith("ui://"))return Z;else if(Z!==void 0)throw Error(`Invalid UI resource URI: ${JSON.stringify(Z)}`);return}function mY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="model")return!0;return!1}function pY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="app")return!0;return!1}function cY(X){if(!X)return"";let Y=[];if(X.camera)Y.push("camera");if(X.microphone)Y.push("microphone");if(X.geolocation)Y.push("geolocation");if(X.clipboardWrite)Y.push("clipboard-write");return Y.join("; ")}var rQ=[G];class oQ extends lQ{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;constructor(X,Y,Z,$){super($);this._client=X;this._hostInfo=Y;this._capabilities=Z;this._hostContext=$?.hostContext||{},this.setRequestHandler(f,(K)=>this._oninitialize(K)),this.setRequestHandler(hQ,(K,J)=>{return this.onping?.(K.params,J),{}}),this.setRequestHandler(W,(K)=>{return{mode:this._hostContext.displayMode??"inline"}})}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(X){this.setNotificationHandler(P,(Y)=>X(Y.params))}set onsandboxready(X){this.setNotificationHandler(F,(Y)=>X(Y.params))}set oninitialized(X){this.setNotificationHandler(M,(Y)=>X(Y.params))}set onmessage(X){this.setRequestHandler(C,async(Y,Z)=>{return X(Y.params,Z)})}set onopenlink(X){this.setRequestHandler(V,async(Y,Z)=>{return X(Y.params,Z)})}set ondownloadfile(X){this.setRequestHandler(S,async(Y,Z)=>{return X(Y.params,Z)})}set onrequestdisplaymode(X){this.setRequestHandler(W,async(Y,Z)=>{return X(Y.params,Z)})}set onloggingmessage(X){this.setNotificationHandler(uQ,async(Y)=>{X(Y.params)})}set onupdatemodelcontext(X){this.setRequestHandler(y,async(Y,Z)=>{return X(Y.params,Z)})}set oncalltool(X){this.setRequestHandler(gQ,async(Y,Z)=>{return X(Y.params,Z)})}sendToolListChanged(X={}){return this.notification({method:"notifications/tools/list_changed",params:X})}set onlistresources(X){this.setRequestHandler(fQ,async(Y,Z)=>{return X(Y.params,Z)})}set onlistresourcetemplates(X){this.setRequestHandler(bQ,async(Y,Z)=>{return X(Y.params,Z)})}set onreadresource(X){this.setRequestHandler(pQ,async(Y,Z)=>{return X(Y.params,Z)})}sendResourceListChanged(X={}){return this.notification({method:"notifications/resources/list_changed",params:X})}set onlistprompts(X){this.setRequestHandler(kQ,async(Y,Z)=>{return X(Y.params,Z)})}sendPromptListChanged(X={}){return this.notification({method:"notifications/prompts/list_changed",params:X})}assertCapabilityForMethod(X){}assertRequestHandlerCapability(X){}assertNotificationCapability(X){}assertTaskCapability(X){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(X){throw Error("Task handlers are not supported in MCP Apps")}getCapabilities(){return this._capabilities}async _oninitialize(X){let Y=X.params.protocolVersion;return this._appCapabilities=X.params.appCapabilities,this._appInfo=X.params.appInfo,{protocolVersion:rQ.includes(Y)?Y:G,hostCapabilities:this.getCapabilities(),hostInfo:this._hostInfo,hostContext:this._hostContext}}setHostContext(X){let Y={},Z=!1;for(let $ of Object.keys(X)){let K=this._hostContext[$],J=X[$];if(aQ(K,J))continue;Y[$]=J,Z=!0}if(Z)this._hostContext=X,this.sendHostContextChange(Y)}sendHostContextChange(X){return this.notification({method:"ui/notifications/host-context-changed",params:X})}sendToolInput(X){return this.notification({method:"ui/notifications/tool-input",params:X})}sendToolInputPartial(X){return this.notification({method:"ui/notifications/tool-input-partial",params:X})}sendToolResult(X){return this.notification({method:"ui/notifications/tool-result",params:X})}sendToolCancelled(X){return this.notification({method:"ui/notifications/tool-cancelled",params:X})}sendSandboxResourceReady(X){return this.notification({method:"ui/notifications/sandbox-resource-ready",params:X})}teardownResource(X,Y){return this.request({method:"ui/resource-teardown",params:X},R,Y)}sendResourceTeardown=this.teardownResource;async connect(X){if(this.transport)throw Error("AppBridge is already connected. Call close() before connecting again.");if(this._client){let Y=this._client.getServerCapabilities();if(!Y)throw Error("Client server capabilities not available");if(Y.tools){if(this.oncalltool=async(Z,$)=>{return this._client.request({method:"tools/call",params:Z},qQ,{signal:$.signal})},Y.tools.listChanged)this._client.setNotificationHandler(iQ,(Z)=>this.sendToolListChanged(Z.params))}if(Y.resources){if(this.onlistresources=async(Z,$)=>{return this._client.request({method:"resources/list",params:Z},dQ,{signal:$.signal})},this.onlistresourcetemplates=async(Z,$)=>{return this._client.request({method:"resources/templates/list",params:Z},xQ,{signal:$.signal})},this.onreadresource=async(Z,$)=>{return this._client.request({method:"resources/read",params:Z},cQ,{signal:$.signal})},Y.resources.listChanged)this._client.setNotificationHandler(nQ,(Z)=>this.sendResourceListChanged(Z.params))}if(Y.prompts){if(this.onlistprompts=async(Z,$)=>{return this._client.request({method:"prompts/list",params:Z},yQ,{signal:$.signal})},Y.prompts.listChanged)this._client.setNotificationHandler(mQ,(Z)=>this.sendPromptListChanged(Z.params))}}return super.connect(X)}}function aQ(X,Y){return JSON.stringify(X)===JSON.stringify(Y)}export{mY as isToolVisibilityModelOnly,pY as isToolVisibilityAppOnly,hY as getToolUiResourceUri,cY as buildAllowAttribute,$Q as TOOL_RESULT_METHOD,_ as TOOL_INPUT_PARTIAL_METHOD,ZQ as TOOL_INPUT_METHOD,JQ as TOOL_CANCELLED_METHOD,rQ as SUPPORTED_PROTOCOL_VERSIONS,YQ as SIZE_CHANGED_METHOD,XQ as SANDBOX_RESOURCE_READY_METHOD,QQ as SANDBOX_PROXY_READY_METHOD,b as RESOURCE_URI_META_KEY,GQ as RESOURCE_TEARDOWN_METHOD,SQ as RESOURCE_MIME_TYPE,jQ as REQUEST_DISPLAY_MODE_METHOD,N as PostMessageTransport,t as OPEN_LINK_METHOD,y as McpUiUpdateModelContextRequestSchema,l as McpUiToolVisibilitySchema,g as McpUiToolResultNotificationSchema,AQ as McpUiToolMetaSchema,w as McpUiToolInputPartialNotificationSchema,T as McpUiToolInputNotificationSchema,U as McpUiToolCancelledNotificationSchema,m as McpUiThemeSchema,O as McpUiSupportedContentBlockModalitiesSchema,P as McpUiSizeChangedNotificationSchema,LQ as McpUiSandboxResourceReadyNotificationSchema,F as McpUiSandboxProxyReadyNotificationSchema,R as McpUiResourceTeardownResultSchema,H as McpUiResourceTeardownRequestSchema,E as McpUiResourcePermissionsSchema,IQ as McpUiResourceMetaSchema,j as McpUiResourceCspSchema,v as McpUiRequestDisplayModeResultSchema,W as McpUiRequestDisplayModeRequestSchema,I as McpUiOpenLinkResultSchema,V as McpUiOpenLinkRequestSchema,L as McpUiMessageResultSchema,C as McpUiMessageRequestSchema,M as McpUiInitializedNotificationSchema,d as McpUiInitializeResultSchema,f as McpUiInitializeRequestSchema,c as McpUiHostStylesSchema,p as McpUiHostCssSchema,q as McpUiHostContextSchema,k as McpUiHostContextChangedNotificationSchema,n as McpUiHostCapabilitiesSchema,A as McpUiDownloadFileResultSchema,S as McpUiDownloadFileRequestSchema,D as McpUiDisplayModeSchema,i as McpUiAppCapabilitiesSchema,e as MESSAGE_METHOD,G as LATEST_PROTOCOL_VERSION,DQ as INITIALIZE_METHOD,NQ as INITIALIZED_METHOD,KQ as HOST_CONTEXT_CHANGED_METHOD,s as DOWNLOAD_FILE_METHOD,oQ as AppBridge};
|
|
38
|
+
- "app": Tool callable by the app from this server only`)}),YX=Q.object({mimeTypes:Q.array(Q.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),C=Q.object({method:Q.literal("ui/download-file"),params:Q.object({contents:Q.array(Q.union([BQ,OQ])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),S=Q.object({method:Q.literal("ui/message"),params:Q.object({role:Q.literal("user").describe('Message role, currently only "user" is supported.'),content:Q.array(h).describe("Message content blocks (text, image, etc.).")})}),PQ=Q.object({method:Q.literal("ui/notifications/sandbox-resource-ready"),params:Q.object({html:Q.string().describe("HTML content to load into the inner iframe."),sandbox:Q.string().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:j.optional().describe("CSP configuration from resource metadata."),permissions:E.optional().describe("Sandbox permissions from resource metadata.")})}),q=Q.object({method:Q.literal("ui/notifications/tool-result"),params:zQ.describe("Standard MCP tool execution result.")}),y=Q.object({toolInfo:Q.object({id:_Q.optional().describe("JSON-RPC id of the tools/call request."),tool:VQ.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:p.optional().describe("Current color theme preference."),styles:n.optional().describe("Style configuration for theming the app."),displayMode:D.optional().describe("How the UI is currently displayed."),availableDisplayModes:Q.array(D).optional().describe("Display modes the host supports."),containerDimensions:Q.union([Q.object({height:Q.number().describe("Fixed container height in pixels.")}),Q.object({maxHeight:Q.union([Q.number(),Q.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(Q.union([Q.object({width:Q.number().describe("Fixed container width in pixels.")}),Q.object({maxWidth:Q.union([Q.number(),Q.undefined()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
39
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:Q.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:Q.string().optional().describe("User's timezone in IANA format."),userAgent:Q.string().optional().describe("Host application identifier."),platform:Q.union([Q.literal("web"),Q.literal("desktop"),Q.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:Q.object({touch:Q.boolean().optional().describe("Whether the device supports touch input."),hover:Q.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:Q.object({top:Q.number().describe("Top safe area inset in pixels."),right:Q.number().describe("Right safe area inset in pixels."),bottom:Q.number().describe("Bottom safe area inset in pixels."),left:Q.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),k=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:y.describe("Partial context update containing only changed fields.")}),f=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(h).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:Q.record(Q.string(),Q.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),d=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:m.describe("App identification (name and version)."),appCapabilities:l.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),b=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:m.describe("Host application identification and version."),hostCapabilities:i.describe("Features and capabilities provided by the host."),hostContext:y.describe("Rich context about the host environment.")}).passthrough();import{Protocol as wQ}from"@modelcontextprotocol/sdk/shared/protocol.js";import{CallToolRequestSchema as RQ,CallToolResultSchema as UQ,EmptyResultSchema as HQ,ListResourcesResultSchema as MQ,ListToolsRequestSchema as vQ,PingRequestSchema as gQ,ReadResourceResultSchema as CQ}from"@modelcontextprotocol/sdk/types.js";import{JSONRPCMessageSchema as TQ}from"@modelcontextprotocol/sdk/types.js";class N{eventTarget;eventSource;messageListener;constructor(X=window.parent,Y){this.eventTarget=X;this.eventSource=Y;this.messageListener=(Z)=>{if(Y&&Z.source!==this.eventSource){console.debug("Ignoring message from unknown source",Z);return}let $=TQ.safeParse(Z.data);if($.success)console.debug("Parsed message",$.data),this.onmessage?.($.data);else if(Z.data?.jsonrpc!=="2.0")console.debug("Ignoring non-JSON-RPC message",$.error.message,Z);else console.error("Failed to parse message",$.error.message,Z),this.onerror?.(Error("Invalid JSON-RPC message received: "+$.error.message))}}async start(){window.addEventListener("message",this.messageListener)}async send(X,Y){if(X.method!==_)console.debug("Sending message",X);this.eventTarget.postMessage(X,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}var x="ui/resourceUri",SQ="text/html;profile=mcp-app";class qQ extends wQ{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(X,Y={},Z={autoResize:!0}){super(Z);this._appInfo=X;this._capabilities=Y;this.options=Z;this.setRequestHandler(gQ,($)=>{return console.log("Received ping:",$.params),{}}),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(X){this.setNotificationHandler(T,(Y)=>X(Y.params))}set ontoolinputpartial(X){this.setNotificationHandler(w,(Y)=>X(Y.params))}set ontoolresult(X){this.setNotificationHandler(q,(Y)=>X(Y.params))}set ontoolcancelled(X){this.setNotificationHandler(R,(Y)=>X(Y.params))}set onhostcontextchanged(X){this.setNotificationHandler(k,(Y)=>{this._hostContext={...this._hostContext,...Y.params},X(Y.params)})}set onteardown(X){this.setRequestHandler(U,(Y,Z)=>X(Y.params,Z))}set oncalltool(X){this.setRequestHandler(RQ,(Y,Z)=>X(Y.params,Z))}set onlisttools(X){this.setRequestHandler(vQ,(Y,Z)=>X(Y.params,Z))}assertCapabilityForMethod(X){}assertRequestHandlerCapability(X){switch(X){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${X})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${X} registered`)}}assertNotificationCapability(X){}assertTaskCapability(X){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(X){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(X,Y){if(typeof X==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${X}"). Did you mean: callServerTool({ name: "${X}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:X},UQ,Y)}async readServerResource(X,Y){return await this.request({method:"resources/read",params:X},CQ,Y)}async listServerResources(X,Y){return await this.request({method:"resources/list",params:X},MQ,Y)}sendMessage(X,Y){return this.request({method:"ui/message",params:X},F,Y)}sendLog(X){return this.notification({method:"notifications/message",params:X})}updateModelContext(X,Y){return this.request({method:"ui/update-model-context",params:X},HQ,Y)}openLink(X,Y){return this.request({method:"ui/open-link",params:X},I,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this.request({method:"ui/download-file",params:X},A,Y)}requestTeardown(X={}){return this.notification({method:"ui/notifications/request-teardown",params:X})}requestDisplayMode(X,Y){return this.request({method:"ui/request-display-mode",params:X},g,Y)}sendSizeChanged(X){return this.notification({method:"ui/notifications/size-changed",params:X})}setupSizeChangedNotifications(){let X=!1,Y=0,Z=0,$=()=>{if(X)return;X=!0,requestAnimationFrame(()=>{X=!1;let J=document.documentElement,o=J.style.width,a=J.style.height;J.style.width="fit-content",J.style.height="max-content";let u=J.getBoundingClientRect();J.style.width=o,J.style.height=a;let t=window.innerWidth-J.clientWidth,z=Math.ceil(u.width+t),B=Math.ceil(u.height);if(z!==Y||B!==Z)Y=z,Z=B,this.sendSizeChanged({width:z,height:B})})};$();let K=new ResizeObserver($);return K.observe(document.documentElement),K.observe(document.body),()=>K.disconnect()}async connect(X=new N(window.parent,window.parent),Y){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(X);try{let Z=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:G}},b,Y);if(Z===void 0)throw Error(`Server sent invalid initialize result: ${Z}`);if(this._hostCapabilities=Z.hostCapabilities,this._hostInfo=Z.hostInfo,this._hostContext=Z.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(Z){throw this.close(),Z}}}function nY(X){let Z=X._meta?.ui?.resourceUri;if(Z===void 0)Z=X._meta?.[x];if(typeof Z==="string"&&Z.startsWith("ui://"))return Z;else if(Z!==void 0)throw Error(`Invalid UI resource URI: ${JSON.stringify(Z)}`);return}function iY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="model")return!0;return!1}function lY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="app")return!0;return!1}function rY(X){if(!X)return"";let Y=[];if(X.camera)Y.push("camera");if(X.microphone)Y.push("microphone");if(X.geolocation)Y.push("geolocation");if(X.clipboardWrite)Y.push("clipboard-write");return Y.join("; ")}var aQ=[G];class tQ extends oQ{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;constructor(X,Y,Z,$){super($);this._client=X;this._hostInfo=Y;this._capabilities=Z;this._hostContext=$?.hostContext||{},this.setRequestHandler(d,(K)=>this._oninitialize(K)),this.setRequestHandler(pQ,(K,J)=>{return this.onping?.(K.params,J),{}}),this.setRequestHandler(W,(K)=>{return{mode:this._hostContext.displayMode??"inline"}})}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;set onsizechange(X){this.setNotificationHandler(P,(Y)=>X(Y.params))}set onsandboxready(X){this.setNotificationHandler(L,(Y)=>X(Y.params))}set oninitialized(X){this.setNotificationHandler(v,(Y)=>X(Y.params))}set onmessage(X){this.setRequestHandler(S,async(Y,Z)=>{return X(Y.params,Z)})}set onopenlink(X){this.setRequestHandler(V,async(Y,Z)=>{return X(Y.params,Z)})}set ondownloadfile(X){this.setRequestHandler(C,async(Y,Z)=>{return X(Y.params,Z)})}set onrequestteardown(X){this.setNotificationHandler(M,(Y)=>X(Y.params))}set onrequestdisplaymode(X){this.setRequestHandler(W,async(Y,Z)=>{return X(Y.params,Z)})}set onloggingmessage(X){this.setNotificationHandler(mQ,async(Y)=>{X(Y.params)})}set onupdatemodelcontext(X){this.setRequestHandler(f,async(Y,Z)=>{return X(Y.params,Z)})}set oncalltool(X){this.setRequestHandler(yQ,async(Y,Z)=>{return X(Y.params,Z)})}sendToolListChanged(X={}){return this.notification({method:"notifications/tools/list_changed",params:X})}set onlistresources(X){this.setRequestHandler(bQ,async(Y,Z)=>{return X(Y.params,Z)})}set onlistresourcetemplates(X){this.setRequestHandler(uQ,async(Y,Z)=>{return X(Y.params,Z)})}set onreadresource(X){this.setRequestHandler(nQ,async(Y,Z)=>{return X(Y.params,Z)})}sendResourceListChanged(X={}){return this.notification({method:"notifications/resources/list_changed",params:X})}set onlistprompts(X){this.setRequestHandler(fQ,async(Y,Z)=>{return X(Y.params,Z)})}sendPromptListChanged(X={}){return this.notification({method:"notifications/prompts/list_changed",params:X})}assertCapabilityForMethod(X){}assertRequestHandlerCapability(X){}assertNotificationCapability(X){}assertTaskCapability(X){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(X){throw Error("Task handlers are not supported in MCP Apps")}getCapabilities(){return this._capabilities}async _oninitialize(X){let Y=X.params.protocolVersion;return this._appCapabilities=X.params.appCapabilities,this._appInfo=X.params.appInfo,{protocolVersion:aQ.includes(Y)?Y:G,hostCapabilities:this.getCapabilities(),hostInfo:this._hostInfo,hostContext:this._hostContext}}setHostContext(X){let Y={},Z=!1;for(let $ of Object.keys(X)){let K=this._hostContext[$],J=X[$];if(sQ(K,J))continue;Y[$]=J,Z=!0}if(Z)this._hostContext=X,this.sendHostContextChange(Y)}sendHostContextChange(X){return this.notification({method:"ui/notifications/host-context-changed",params:X})}sendToolInput(X){return this.notification({method:"ui/notifications/tool-input",params:X})}sendToolInputPartial(X){return this.notification({method:"ui/notifications/tool-input-partial",params:X})}sendToolResult(X){return this.notification({method:"ui/notifications/tool-result",params:X})}sendToolCancelled(X){return this.notification({method:"ui/notifications/tool-cancelled",params:X})}sendSandboxResourceReady(X){return this.notification({method:"ui/notifications/sandbox-resource-ready",params:X})}teardownResource(X,Y){return this.request({method:"ui/resource-teardown",params:X},H,Y)}sendResourceTeardown=this.teardownResource;async connect(X){if(this.transport)throw Error("AppBridge is already connected. Call close() before connecting again.");if(this._client){let Y=this._client.getServerCapabilities();if(!Y)throw Error("Client server capabilities not available");if(Y.tools){if(this.oncalltool=async(Z,$)=>{return this._client.request({method:"tools/call",params:Z},kQ,{signal:$.signal})},Y.tools.listChanged)this._client.setNotificationHandler(rQ,(Z)=>this.sendToolListChanged(Z.params))}if(Y.resources){if(this.onlistresources=async(Z,$)=>{return this._client.request({method:"resources/list",params:Z},xQ,{signal:$.signal})},this.onlistresourcetemplates=async(Z,$)=>{return this._client.request({method:"resources/templates/list",params:Z},hQ,{signal:$.signal})},this.onreadresource=async(Z,$)=>{return this._client.request({method:"resources/read",params:Z},iQ,{signal:$.signal})},Y.resources.listChanged)this._client.setNotificationHandler(lQ,(Z)=>this.sendResourceListChanged(Z.params))}if(Y.prompts){if(this.onlistprompts=async(Z,$)=>{return this._client.request({method:"prompts/list",params:Z},dQ,{signal:$.signal})},Y.prompts.listChanged)this._client.setNotificationHandler(cQ,(Z)=>this.sendPromptListChanged(Z.params))}}return super.connect(X)}}function sQ(X,Y){return JSON.stringify(X)===JSON.stringify(Y)}export{iY as isToolVisibilityModelOnly,lY as isToolVisibilityAppOnly,nY as getToolUiResourceUri,rY as buildAllowAttribute,JQ as TOOL_RESULT_METHOD,_ as TOOL_INPUT_PARTIAL_METHOD,$Q as TOOL_INPUT_METHOD,KQ as TOOL_CANCELLED_METHOD,aQ as SUPPORTED_PROTOCOL_VERSIONS,ZQ as SIZE_CHANGED_METHOD,YQ as SANDBOX_RESOURCE_READY_METHOD,XQ as SANDBOX_PROXY_READY_METHOD,x as RESOURCE_URI_META_KEY,NQ as RESOURCE_TEARDOWN_METHOD,SQ as RESOURCE_MIME_TYPE,DQ as REQUEST_TEARDOWN_METHOD,WQ as REQUEST_DISPLAY_MODE_METHOD,N as PostMessageTransport,s as OPEN_LINK_METHOD,f as McpUiUpdateModelContextRequestSchema,r as McpUiToolVisibilitySchema,q as McpUiToolResultNotificationSchema,LQ as McpUiToolMetaSchema,w as McpUiToolInputPartialNotificationSchema,T as McpUiToolInputNotificationSchema,R as McpUiToolCancelledNotificationSchema,p as McpUiThemeSchema,O as McpUiSupportedContentBlockModalitiesSchema,P as McpUiSizeChangedNotificationSchema,PQ as McpUiSandboxResourceReadyNotificationSchema,L as McpUiSandboxProxyReadyNotificationSchema,H as McpUiResourceTeardownResultSchema,U as McpUiResourceTeardownRequestSchema,E as McpUiResourcePermissionsSchema,FQ as McpUiResourceMetaSchema,j as McpUiResourceCspSchema,M as McpUiRequestTeardownNotificationSchema,g as McpUiRequestDisplayModeResultSchema,W as McpUiRequestDisplayModeRequestSchema,I as McpUiOpenLinkResultSchema,V as McpUiOpenLinkRequestSchema,F as McpUiMessageResultSchema,S as McpUiMessageRequestSchema,v as McpUiInitializedNotificationSchema,b as McpUiInitializeResultSchema,d as McpUiInitializeRequestSchema,n as McpUiHostStylesSchema,c as McpUiHostCssSchema,y as McpUiHostContextSchema,k as McpUiHostContextChangedNotificationSchema,i as McpUiHostCapabilitiesSchema,A as McpUiDownloadFileResultSchema,C as McpUiDownloadFileRequestSchema,D as McpUiDisplayModeSchema,l as McpUiAppCapabilitiesSchema,QQ as MESSAGE_METHOD,G as LATEST_PROTOCOL_VERSION,jQ as INITIALIZE_METHOD,EQ as INITIALIZED_METHOD,GQ as HOST_CONTEXT_CHANGED_METHOD,e as DOWNLOAD_FILE_METHOD,tQ as AppBridge};
|