@modelcontextprotocol/ext-apps 1.2.2 → 1.3.0
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.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RequestOptions, Protocol, ProtocolOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
2
2
|
import { CallToolRequest, CallToolResult, Implementation, ListResourcesRequest, ListResourcesResult, ListToolsRequest, LoggingMessageNotification, ReadResourceRequest, ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
3
|
import { AppNotification, AppRequest, AppResult } from "./types";
|
|
4
|
-
import { McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiDownloadFileRequest, McpUiResourceTeardownRequest, McpUiResourceTeardownResult, McpUiSizeChangedNotification, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiRequestDisplayModeRequest } from "./types";
|
|
4
|
+
import { McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiDownloadFileRequest, McpUiResourceTeardownRequest, McpUiResourceTeardownResult, McpUiRequestTeardownNotification, McpUiSizeChangedNotification, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiRequestDisplayModeRequest } from "./types";
|
|
5
5
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
6
6
|
export { PostMessageTransport } from "./message-transport";
|
|
7
7
|
export * from "./types";
|
|
@@ -110,7 +110,7 @@ type RequestHandlerExtra = Parameters<Parameters<App["setRequestHandler"]>[1]>[1
|
|
|
110
110
|
* 1. **Create**: Instantiate App with info and capabilities
|
|
111
111
|
* 2. **Connect**: Call `connect()` to establish transport and perform handshake
|
|
112
112
|
* 3. **Interactive**: Send requests, receive notifications, call tools
|
|
113
|
-
* 4. **
|
|
113
|
+
* 4. **Teardown**: Host sends teardown request before unmounting
|
|
114
114
|
*
|
|
115
115
|
* ## Inherited Methods
|
|
116
116
|
*
|
|
@@ -874,6 +874,44 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
874
874
|
[x: string]: unknown;
|
|
875
875
|
isError?: boolean | undefined;
|
|
876
876
|
}>;
|
|
877
|
+
/**
|
|
878
|
+
* Request the host to tear down this app.
|
|
879
|
+
*
|
|
880
|
+
* Apps call this method to request that the host tear them down. The host
|
|
881
|
+
* decides whether to proceed - if approved, the host will send
|
|
882
|
+
* `ui/resource-teardown` to allow the app to perform gracefull termination before being
|
|
883
|
+
* unmounted. This piggybacks on the existing teardown mechanism, ensuring
|
|
884
|
+
* the app only needs a single shutdown procedure (via {@link onteardown `onteardown`})
|
|
885
|
+
* regardless of whether the teardown was initiated by the app or the host.
|
|
886
|
+
*
|
|
887
|
+
* This is a fire-and-forget notification - no response is expected.
|
|
888
|
+
* If the host approves, the app will receive a `ui/resource-teardown`
|
|
889
|
+
* request via the {@link onteardown `onteardown`} handler to persist unsaved state.
|
|
890
|
+
*
|
|
891
|
+
* @param params - Empty params object (reserved for future use)
|
|
892
|
+
* @returns Promise that resolves when the notification is sent
|
|
893
|
+
*
|
|
894
|
+
* @example App-initiated teardown after user action
|
|
895
|
+
* ```typescript
|
|
896
|
+
* // User clicks "Done" button in the app
|
|
897
|
+
* async function handleDoneClick() {
|
|
898
|
+
* // Request the host to tear down the app
|
|
899
|
+
* await app.requestTeardown();
|
|
900
|
+
* // If host approves, onteardown handler will be called for termination
|
|
901
|
+
* }
|
|
902
|
+
*
|
|
903
|
+
* // Set up teardown handler (called for both app-initiated and host-initiated teardown)
|
|
904
|
+
* app.onteardown = async () => {
|
|
905
|
+
* await saveState();
|
|
906
|
+
* closeConnections();
|
|
907
|
+
* return {};
|
|
908
|
+
* };
|
|
909
|
+
* ```
|
|
910
|
+
*
|
|
911
|
+
* @see {@link McpUiRequestTeardownNotification `McpUiRequestTeardownNotification`} for notification structure
|
|
912
|
+
* @see {@link onteardown `onteardown`} for the graceful termination handler
|
|
913
|
+
*/
|
|
914
|
+
requestTeardown(params?: McpUiRequestTeardownNotification["params"]): Promise<void>;
|
|
877
915
|
/**
|
|
878
916
|
* Request a change to the display mode.
|
|
879
917
|
*
|
package/dist/src/app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Protocol as
|
|
1
|
+
import{Protocol as UQ}from"@modelcontextprotocol/sdk/shared/protocol.js";import{CallToolRequestSchema as HQ,CallToolResultSchema as MQ,EmptyResultSchema as vQ,ListResourcesResultSchema as bQ,ListToolsRequestSchema as kQ,PingRequestSchema as CQ,ReadResourceResultSchema as xQ}from"@modelcontextprotocol/sdk/types.js";import{JSONRPCMessageSchema as XQ}from"@modelcontextprotocol/sdk/types.js";var W="2026-01-26",d="ui/open-link",h="ui/download-file",m="ui/message",i="ui/notifications/sandbox-proxy-ready",l="ui/notifications/sandbox-resource-ready",r="ui/notifications/size-changed",p="ui/notifications/tool-input",z="ui/notifications/tool-input-partial",c="ui/notifications/tool-result",n="ui/notifications/tool-cancelled",a="ui/notifications/host-context-changed",o="ui/notifications/request-teardown",s="ui/resource-teardown",t="ui/initialize",e="ui/notifications/initialized",QQ="ui/request-display-mode";class K{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 $=XQ.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!==z)console.debug("Sending message",X);this.eventTarget.postMessage(X,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}import{z as Q}from"zod/v4";import{ContentBlockSchema as M,CallToolResultSchema as YQ,EmbeddedResourceSchema as ZQ,ImplementationSchema as v,RequestIdSchema as $Q,ResourceLinkSchema as DQ,ToolSchema as JQ}from"@modelcontextprotocol/sdk/types.js";var b=Q.union([Q.literal("light"),Q.literal("dark")]).describe("Color theme preference for the host environment."),J=Q.union([Q.literal("inline"),Q.literal("fullscreen"),Q.literal("pip")]).describe("Display mode for UI presentation."),KQ=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."),GQ=Q.record(KQ.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.`),
|
|
19
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),VQ=Q.object({method:Q.literal("ui/open-link"),params:Q.object({url:Q.string().describe("URL to open in the host's browser")})}),B=Q.object({isError:Q.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),_=Q.object({isError:Q.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),O=Q.object({isError:Q.boolean().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),NQ=Q.object({method:Q.literal("ui/notifications/sandbox-proxy-ready"),params:Q.object({})}),G=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'`)")}),V=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.")}),
|
|
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'`)")}),V=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.")}),jQ=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.")})}),I=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).")})}),A=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").')})}),k=Q.object({fonts:Q.string().optional()}),C=Q.object({variables:GQ.optional().describe("CSS variables for theming the app."),css:k.optional().describe("CSS blocks that apps can inject.")}),F=Q.object({method:Q.literal("ui/resource-teardown"),params:Q.object({})}),EQ=Q.record(Q.string(),Q.unknown()),L=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.")}),WQ=Q.object({method:Q.literal("ui/notifications/request-teardown"),params:Q.object({}).optional()}),x=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:V.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:G.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:L.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:L.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),g=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(J).optional().describe("Display modes the app supports.")}),zQ=Q.object({method:Q.literal("ui/notifications/initialized"),params:Q.object({}).optional()}),LQ=Q.object({csp:G.optional().describe("Content Security Policy configuration for UI resources."),permissions:V.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`)}),
|
|
36
|
+
- omitted: host decides border`)}),BQ=Q.object({method:Q.literal("ui/request-display-mode"),params:Q.object({mode:J.describe("The display mode being requested.")})}),P=Q.object({mode:J.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),S=Q.union([Q.literal("model"),Q.literal("app")]).describe("Tool visibility scope - who can access the tool."),_Q=Q.object({resourceUri:Q.string().optional(),visibility:Q.array(S).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(),
|
|
38
|
+
- "app": Tool callable by the app from this server only`)}),lQ=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.')}),OQ=Q.object({method:Q.literal("ui/download-file"),params:Q.object({contents:Q.array(Q.union([ZQ,DQ])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),IQ=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(M).describe("Message content blocks (text, image, etc.).")})}),wQ=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:G.optional().describe("CSP configuration from resource metadata."),permissions:V.optional().describe("Sandbox permissions from resource metadata.")})}),q=Q.object({method:Q.literal("ui/notifications/tool-result"),params:YQ.describe("Standard MCP tool execution result.")}),T=Q.object({toolInfo:Q.object({id:$Q.optional().describe("JSON-RPC id of the tools/call request."),tool:JQ.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:b.optional().describe("Current color theme preference."),styles:C.optional().describe("Style configuration for theming the app."),displayMode:J.optional().describe("How the UI is currently displayed."),availableDisplayModes:Q.array(J).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(),R=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:T.describe("Partial context update containing only changed fields.")}),AQ=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(M).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.")})}),FQ=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:v.describe("App identification (name and version)."),appCapabilities:g.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),U=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:v.describe("Host application identification and version."),hostCapabilities:x.describe("Features and capabilities provided by the host."),hostContext:T.describe("Rich context about the host environment.")}).passthrough();function PQ(){let X=document.documentElement.getAttribute("data-theme");if(X==="dark"||X==="light")return X;return document.documentElement.classList.contains("dark")?"dark":"light"}function qQ(X){let Y=document.documentElement;Y.setAttribute("data-theme",X),Y.style.colorScheme=X}function TQ(X,Y=document.documentElement){for(let[Z,$]of Object.entries(X))if($!==void 0)Y.style.setProperty(Z,$)}function RQ(X){if(document.getElementById("__mcp-host-fonts"))return;let Z=document.createElement("style");Z.id="__mcp-host-fonts",Z.textContent=X,document.head.appendChild(Z)}var MX="ui/resourceUri",vX="text/html;profile=mcp-app";class gQ extends UQ{_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(CQ,($)=>{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(I,(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(A,(Y)=>X(Y.params))}set onhostcontextchanged(X){this.setNotificationHandler(R,(Y)=>{this._hostContext={...this._hostContext,...Y.params},X(Y.params)})}set onteardown(X){this.setRequestHandler(F,(Y,Z)=>X(Y.params,Z))}set oncalltool(X){this.setRequestHandler(HQ,(Y,Z)=>X(Y.params,Z))}set onlisttools(X){this.setRequestHandler(kQ,(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},MQ,Y)}async readServerResource(X,Y){return await this.request({method:"resources/read",params:X},xQ,Y)}async listServerResources(X,Y){return await this.request({method:"resources/list",params:X},bQ,Y)}sendMessage(X,Y){return this.request({method:"ui/message",params:X},O,Y)}sendLog(X){return this.notification({method:"notifications/message",params:X})}updateModelContext(X,Y){return this.request({method:"ui/update-model-context",params:X},vQ,Y)}openLink(X,Y){return this.request({method:"ui/open-link",params:X},B,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this.request({method:"ui/download-file",params:X},_,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},P,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 D=document.documentElement,y=D.style.width,u=D.style.height;D.style.width="fit-content",D.style.height="max-content";let H=D.getBoundingClientRect();D.style.width=y,D.style.height=u;let f=window.innerWidth-D.clientWidth,j=Math.ceil(H.width+f),E=Math.ceil(H.height);if(j!==Y||E!==Z)Y=j,Z=E,this.sendSizeChanged({width:j,height:E})})};$();let N=new ResizeObserver($);return N.observe(document.documentElement),N.observe(document.body),()=>N.disconnect()}async connect(X=new K(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:W}},U,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}}}export{PQ as getDocumentTheme,TQ as applyHostStyleVariables,RQ as applyHostFonts,qQ as applyDocumentTheme,c as TOOL_RESULT_METHOD,z as TOOL_INPUT_PARTIAL_METHOD,p as TOOL_INPUT_METHOD,n as TOOL_CANCELLED_METHOD,r as SIZE_CHANGED_METHOD,l as SANDBOX_RESOURCE_READY_METHOD,i as SANDBOX_PROXY_READY_METHOD,MX as RESOURCE_URI_META_KEY,s as RESOURCE_TEARDOWN_METHOD,vX as RESOURCE_MIME_TYPE,o as REQUEST_TEARDOWN_METHOD,QQ as REQUEST_DISPLAY_MODE_METHOD,K as PostMessageTransport,d as OPEN_LINK_METHOD,AQ as McpUiUpdateModelContextRequestSchema,S as McpUiToolVisibilitySchema,q as McpUiToolResultNotificationSchema,_Q as McpUiToolMetaSchema,w as McpUiToolInputPartialNotificationSchema,I as McpUiToolInputNotificationSchema,A as McpUiToolCancelledNotificationSchema,b as McpUiThemeSchema,L as McpUiSupportedContentBlockModalitiesSchema,jQ as McpUiSizeChangedNotificationSchema,wQ as McpUiSandboxResourceReadyNotificationSchema,NQ as McpUiSandboxProxyReadyNotificationSchema,EQ as McpUiResourceTeardownResultSchema,F as McpUiResourceTeardownRequestSchema,V as McpUiResourcePermissionsSchema,LQ as McpUiResourceMetaSchema,G as McpUiResourceCspSchema,WQ as McpUiRequestTeardownNotificationSchema,P as McpUiRequestDisplayModeResultSchema,BQ as McpUiRequestDisplayModeRequestSchema,B as McpUiOpenLinkResultSchema,VQ as McpUiOpenLinkRequestSchema,O as McpUiMessageResultSchema,IQ as McpUiMessageRequestSchema,zQ as McpUiInitializedNotificationSchema,U as McpUiInitializeResultSchema,FQ as McpUiInitializeRequestSchema,C as McpUiHostStylesSchema,k as McpUiHostCssSchema,T as McpUiHostContextSchema,R as McpUiHostContextChangedNotificationSchema,x as McpUiHostCapabilitiesSchema,_ as McpUiDownloadFileResultSchema,OQ as McpUiDownloadFileRequestSchema,J as McpUiDisplayModeSchema,g as McpUiAppCapabilitiesSchema,m as MESSAGE_METHOD,W as LATEST_PROTOCOL_VERSION,t as INITIALIZE_METHOD,e as INITIALIZED_METHOD,a as HOST_CONTEXT_CHANGED_METHOD,h as DOWNLOAD_FILE_METHOD,gQ as App};
|
|
@@ -166,6 +166,18 @@ export declare const McpUiSupportedContentBlockModalitiesSchema: z.ZodObject<{
|
|
|
166
166
|
resourceLink: z.ZodOptional<z.ZodObject<{}, z.core.$strip>>;
|
|
167
167
|
structuredContent: z.ZodOptional<z.ZodObject<{}, z.core.$strip>>;
|
|
168
168
|
}, z.core.$strip>;
|
|
169
|
+
/**
|
|
170
|
+
* @description Notification for app-initiated teardown request (View -> Host).
|
|
171
|
+
* Views send this to request that the host tear them down. The host decides
|
|
172
|
+
* whether to proceed - if approved, the host will send
|
|
173
|
+
* `ui/resource-teardown` to allow the view to perform cleanup before being
|
|
174
|
+
* unmounted.
|
|
175
|
+
* @see {@link app.App.requestTeardown} for the app method that sends this
|
|
176
|
+
*/
|
|
177
|
+
export declare const McpUiRequestTeardownNotificationSchema: z.ZodObject<{
|
|
178
|
+
method: z.ZodLiteral<"ui/notifications/request-teardown">;
|
|
179
|
+
params: z.ZodOptional<z.ZodObject<{}, z.core.$strip>>;
|
|
180
|
+
}, z.core.$strip>;
|
|
169
181
|
/**
|
|
170
182
|
* @description Capabilities supported by the host application.
|
|
171
183
|
* @see {@link McpUiInitializeResult `McpUiInitializeResult`} for the initialization result that includes these capabilities
|
|
@@ -4074,6 +4074,23 @@
|
|
|
4074
4074
|
"required": ["mode"],
|
|
4075
4075
|
"additionalProperties": {}
|
|
4076
4076
|
},
|
|
4077
|
+
"McpUiRequestTeardownNotification": {
|
|
4078
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4079
|
+
"type": "object",
|
|
4080
|
+
"properties": {
|
|
4081
|
+
"method": {
|
|
4082
|
+
"type": "string",
|
|
4083
|
+
"const": "ui/notifications/request-teardown"
|
|
4084
|
+
},
|
|
4085
|
+
"params": {
|
|
4086
|
+
"type": "object",
|
|
4087
|
+
"properties": {},
|
|
4088
|
+
"additionalProperties": false
|
|
4089
|
+
}
|
|
4090
|
+
},
|
|
4091
|
+
"required": ["method"],
|
|
4092
|
+
"additionalProperties": false
|
|
4093
|
+
},
|
|
4077
4094
|
"McpUiResourceCsp": {
|
|
4078
4095
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
4079
4096
|
"type": "object",
|
|
@@ -20,6 +20,7 @@ export type McpUiHostStylesSchemaInferredType = z.infer<typeof generated.McpUiHo
|
|
|
20
20
|
export type McpUiResourceTeardownRequestSchemaInferredType = z.infer<typeof generated.McpUiResourceTeardownRequestSchema>;
|
|
21
21
|
export type McpUiResourceTeardownResultSchemaInferredType = z.infer<typeof generated.McpUiResourceTeardownResultSchema>;
|
|
22
22
|
export type McpUiSupportedContentBlockModalitiesSchemaInferredType = z.infer<typeof generated.McpUiSupportedContentBlockModalitiesSchema>;
|
|
23
|
+
export type McpUiRequestTeardownNotificationSchemaInferredType = z.infer<typeof generated.McpUiRequestTeardownNotificationSchema>;
|
|
23
24
|
export type McpUiHostCapabilitiesSchemaInferredType = z.infer<typeof generated.McpUiHostCapabilitiesSchema>;
|
|
24
25
|
export type McpUiAppCapabilitiesSchemaInferredType = z.infer<typeof generated.McpUiAppCapabilitiesSchema>;
|
|
25
26
|
export type McpUiInitializedNotificationSchemaInferredType = z.infer<typeof generated.McpUiInitializedNotificationSchema>;
|
package/dist/src/react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as
|
|
1
|
+
import{useEffect as uJ,useState as d}from"react";import{Protocol as bJ}from"@modelcontextprotocol/sdk/shared/protocol.js";import{CallToolRequestSchema as SJ,CallToolResultSchema as CJ,EmptyResultSchema as gJ,ListResourcesResultSchema as xJ,ListToolsRequestSchema as yJ,PingRequestSchema as fJ,ReadResourceResultSchema as dJ}from"@modelcontextprotocol/sdk/types.js";import{JSONRPCMessageSchema as LJ}from"@modelcontextprotocol/sdk/types.js";var z="2026-01-26",o="ui/open-link",a="ui/download-file",s="ui/message",t="ui/notifications/sandbox-proxy-ready",e="ui/notifications/sandbox-resource-ready",JJ="ui/notifications/size-changed",KJ="ui/notifications/tool-input",U="ui/notifications/tool-input-partial",QJ="ui/notifications/tool-result",XJ="ui/notifications/tool-cancelled",YJ="ui/notifications/host-context-changed",ZJ="ui/notifications/request-teardown",$J="ui/resource-teardown",GJ="ui/initialize",jJ="ui/notifications/initialized",WJ="ui/request-display-mode";class j{eventTarget;eventSource;messageListener;constructor(K=window.parent,Q){this.eventTarget=K;this.eventSource=Q;this.messageListener=(X)=>{if(Q&&X.source!==this.eventSource){console.debug("Ignoring message from unknown source",X);return}let Y=LJ.safeParse(X.data);if(Y.success)console.debug("Parsed message",Y.data),this.onmessage?.(Y.data);else if(X.data?.jsonrpc!=="2.0")console.debug("Ignoring non-JSON-RPC message",Y.error.message,X);else console.error("Failed to parse message",Y.error.message,X),this.onerror?.(Error("Invalid JSON-RPC message received: "+Y.error.message))}}async start(){window.addEventListener("message",this.messageListener)}async send(K,Q){if(K.method!==U)console.debug("Sending message",K);this.eventTarget.postMessage(K,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}import{z as J}from"zod/v4";import{ContentBlockSchema as u,CallToolResultSchema as NJ,EmbeddedResourceSchema as BJ,ImplementationSchema as h,RequestIdSchema as VJ,ResourceLinkSchema as PJ,ToolSchema as _J}from"@modelcontextprotocol/sdk/types.js";var m=J.union([J.literal("light"),J.literal("dark")]).describe("Color theme preference for the host environment."),W=J.union([J.literal("inline"),J.literal("fullscreen"),J.literal("pip")]).describe("Display mode for UI presentation."),OJ=J.union([J.literal("--color-background-primary"),J.literal("--color-background-secondary"),J.literal("--color-background-tertiary"),J.literal("--color-background-inverse"),J.literal("--color-background-ghost"),J.literal("--color-background-info"),J.literal("--color-background-danger"),J.literal("--color-background-success"),J.literal("--color-background-warning"),J.literal("--color-background-disabled"),J.literal("--color-text-primary"),J.literal("--color-text-secondary"),J.literal("--color-text-tertiary"),J.literal("--color-text-inverse"),J.literal("--color-text-ghost"),J.literal("--color-text-info"),J.literal("--color-text-danger"),J.literal("--color-text-success"),J.literal("--color-text-warning"),J.literal("--color-text-disabled"),J.literal("--color-border-primary"),J.literal("--color-border-secondary"),J.literal("--color-border-tertiary"),J.literal("--color-border-inverse"),J.literal("--color-border-ghost"),J.literal("--color-border-info"),J.literal("--color-border-danger"),J.literal("--color-border-success"),J.literal("--color-border-warning"),J.literal("--color-border-disabled"),J.literal("--color-ring-primary"),J.literal("--color-ring-secondary"),J.literal("--color-ring-inverse"),J.literal("--color-ring-info"),J.literal("--color-ring-danger"),J.literal("--color-ring-success"),J.literal("--color-ring-warning"),J.literal("--font-sans"),J.literal("--font-mono"),J.literal("--font-weight-normal"),J.literal("--font-weight-medium"),J.literal("--font-weight-semibold"),J.literal("--font-weight-bold"),J.literal("--font-text-xs-size"),J.literal("--font-text-sm-size"),J.literal("--font-text-md-size"),J.literal("--font-text-lg-size"),J.literal("--font-heading-xs-size"),J.literal("--font-heading-sm-size"),J.literal("--font-heading-md-size"),J.literal("--font-heading-lg-size"),J.literal("--font-heading-xl-size"),J.literal("--font-heading-2xl-size"),J.literal("--font-heading-3xl-size"),J.literal("--font-text-xs-line-height"),J.literal("--font-text-sm-line-height"),J.literal("--font-text-md-line-height"),J.literal("--font-text-lg-line-height"),J.literal("--font-heading-xs-line-height"),J.literal("--font-heading-sm-line-height"),J.literal("--font-heading-md-line-height"),J.literal("--font-heading-lg-line-height"),J.literal("--font-heading-xl-line-height"),J.literal("--font-heading-2xl-line-height"),J.literal("--font-heading-3xl-line-height"),J.literal("--border-radius-xs"),J.literal("--border-radius-sm"),J.literal("--border-radius-md"),J.literal("--border-radius-lg"),J.literal("--border-radius-xl"),J.literal("--border-radius-full"),J.literal("--border-width-regular"),J.literal("--shadow-hairline"),J.literal("--shadow-sm"),J.literal("--shadow-md"),J.literal("--shadow-lg")]).describe("CSS variable keys available to MCP apps for theming."),qJ=J.record(OJ.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.`),
|
|
19
|
+
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),DJ=J.object({method:J.literal("ui/open-link"),params:J.object({url:J.string().describe("URL to open in the host's browser")})}),M=J.object({isError:J.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),T=J.object({isError:J.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),H=J.object({isError:J.boolean().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),IJ=J.object({method:J.literal("ui/notifications/sandbox-proxy-ready"),params:J.object({})}),P=J.object({connectDomains:J.array(J.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:J.array(J.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:J.array(J.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:J.array(J.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'`)")}),_=J.object({camera:J.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:J.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:J.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:J.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),
|
|
22
|
+
- Empty or omitted → no network connections (secure default)`),resourceDomains:J.array(J.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:J.array(J.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:J.array(J.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'`)")}),_=J.object({camera:J.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:J.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:J.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:J.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),FJ=J.object({method:J.literal("ui/notifications/size-changed"),params:J.object({width:J.number().optional().describe("New width in pixels."),height:J.number().optional().describe("New height in pixels.")})}),v=J.object({method:J.literal("ui/notifications/tool-input"),params:J.object({arguments:J.record(J.string(),J.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),A=J.object({method:J.literal("ui/notifications/tool-input-partial"),params:J.object({arguments:J.record(J.string(),J.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),k=J.object({method:J.literal("ui/notifications/tool-cancelled"),params:J.object({reason:J.string().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),c=J.object({fonts:J.string().optional()}),r=J.object({variables:qJ.optional().describe("CSS variables for theming the app."),css:c.optional().describe("CSS blocks that apps can inject.")}),b=J.object({method:J.literal("ui/resource-teardown"),params:J.object({})}),EJ=J.record(J.string(),J.unknown()),w=J.object({text:J.object({}).optional().describe("Host supports text content blocks."),image:J.object({}).optional().describe("Host supports image content blocks."),audio:J.object({}).optional().describe("Host supports audio content blocks."),resource:J.object({}).optional().describe("Host supports resource content blocks."),resourceLink:J.object({}).optional().describe("Host supports resource link content blocks."),structuredContent:J.object({}).optional().describe("Host supports structured content.")}),RJ=J.object({method:J.literal("ui/notifications/request-teardown"),params:J.object({}).optional()}),l=J.object({experimental:J.object({}).optional().describe("Experimental features (structure TBD)."),openLinks:J.object({}).optional().describe("Host supports opening external URLs."),downloadFile:J.object({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:J.object({listChanged:J.boolean().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:J.object({listChanged:J.boolean().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:J.object({}).optional().describe("Host accepts log messages."),sandbox:J.object({permissions:_.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:P.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:w.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:w.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),i=J.object({experimental:J.object({}).optional().describe("Experimental features (structure TBD)."),tools:J.object({listChanged:J.boolean().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:J.array(W).optional().describe("Display modes the app supports.")}),zJ=J.object({method:J.literal("ui/notifications/initialized"),params:J.object({}).optional()}),UJ=J.object({csp:P.optional().describe("Content Security Policy configuration for UI resources."),permissions:_.optional().describe("Sandbox permissions requested by the UI resource."),domain:J.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`)}),
|
|
36
|
+
- omitted: host decides border`)}),wJ=J.object({method:J.literal("ui/request-display-mode"),params:J.object({mode:W.describe("The display mode being requested.")})}),S=J.object({mode:W.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),p=J.union([J.literal("model"),J.literal("app")]).describe("Tool visibility scope - who can access the tool."),MJ=J.object({resourceUri:J.string().optional(),visibility:J.array(p).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:J.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:J.string().optional().describe("User's timezone in IANA format."),userAgent:J.string().optional().describe("Host application identifier."),platform:J.union([J.literal("web"),J.literal("desktop"),J.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:J.object({touch:J.boolean().optional().describe("Whether the device supports touch input."),hover:J.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:J.object({top:J.number().describe("Top safe area inset in pixels."),right:J.number().describe("Right safe area inset in pixels."),bottom:J.number().describe("Bottom safe area inset in pixels."),left:J.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),x=J.object({method:J.literal("ui/notifications/host-context-changed"),params:g.describe("Partial context update containing only changed fields.")}),HJ=J.object({method:J.literal("ui/update-model-context"),params:J.object({content:J.array(u).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:J.record(J.string(),J.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),vJ=J.object({method:J.literal("ui/initialize"),params:J.object({appInfo:h.describe("App identification (name and version)."),appCapabilities:i.describe("Features and capabilities this app provides."),protocolVersion:J.string().describe("Protocol version this app supports.")})}),y=J.object({protocolVersion:J.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:h.describe("Host application identification and version."),hostCapabilities:l.describe("Features and capabilities provided by the host."),hostContext:g.describe("Rich context about the host environment.")}).passthrough();function O(){let K=document.documentElement.getAttribute("data-theme");if(K==="dark"||K==="light")return K;return document.documentElement.classList.contains("dark")?"dark":"light"}function q(K){let Q=document.documentElement;Q.setAttribute("data-theme",K),Q.style.colorScheme=K}function D(K,Q=document.documentElement){for(let[X,Y]of Object.entries(K))if(Y!==void 0)Q.style.setProperty(X,Y)}function I(K){if(document.getElementById("__mcp-host-fonts"))return;let X=document.createElement("style");X.id="__mcp-host-fonts",X.textContent=K,document.head.appendChild(X)}var xK="ui/resourceUri",yK="text/html;profile=mcp-app";class f extends AJ{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(K,Q={},X={autoResize:!0}){super(X);this._appInfo=K;this._capabilities=Q;this.options=X;this.setRequestHandler(xJ,(Y)=>{return console.log("Received ping:",Y.params),{}}),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(K){this.setNotificationHandler(v,(Q)=>K(Q.params))}set ontoolinputpartial(K){this.setNotificationHandler(A,(Q)=>K(Q.params))}set ontoolresult(K){this.setNotificationHandler(C,(Q)=>K(Q.params))}set ontoolcancelled(K){this.setNotificationHandler(k,(Q)=>K(Q.params))}set onhostcontextchanged(K){this.setNotificationHandler(x,(Q)=>{this._hostContext={...this._hostContext,...Q.params},K(Q.params)})}set onteardown(K){this.setRequestHandler(S,(Q,X)=>K(Q.params,X))}set oncalltool(K){this.setRequestHandler(kJ,(Q,X)=>K(Q.params,X))}set onlisttools(K){this.setRequestHandler(gJ,(Q,X)=>K(Q.params,X))}assertCapabilityForMethod(K){}assertRequestHandlerCapability(K){switch(K){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${K})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${K} registered`)}}assertNotificationCapability(K){}assertTaskCapability(K){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(K){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(K,Q){if(typeof K==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${K}"). Did you mean: callServerTool({ name: "${K}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:K},SJ,Q)}async readServerResource(K,Q){return await this.request({method:"resources/read",params:K},yJ,Q)}async listServerResources(K,Q){return await this.request({method:"resources/list",params:K},CJ,Q)}sendMessage(K,Q){return this.request({method:"ui/message",params:K},H,Q)}sendLog(K){return this.notification({method:"notifications/message",params:K})}updateModelContext(K,Q){return this.request({method:"ui/update-model-context",params:K},bJ,Q)}openLink(K,Q){return this.request({method:"ui/open-link",params:K},w,Q)}sendOpenLink=this.openLink;downloadFile(K,Q){return this.request({method:"ui/download-file",params:K},T,Q)}requestDisplayMode(K,Q){return this.request({method:"ui/request-display-mode",params:K},b,Q)}sendSizeChanged(K){return this.notification({method:"ui/notifications/size-changed",params:K})}setupSizeChangedNotifications(){let K=!1,Q=0,X=0,Y=()=>{if(K)return;K=!0,requestAnimationFrame(()=>{K=!1;let Z=document.documentElement,V=Z.style.width,E=Z.style.height;Z.style.width="fit-content",Z.style.height="max-content";let W=Z.getBoundingClientRect();Z.style.width=V,Z.style.height=E;let N=window.innerWidth-Z.clientWidth,B=Math.ceil(W.width+N),$=Math.ceil(W.height);if(B!==Q||$!==X)Q=B,X=$,this.sendSizeChanged({width:B,height:$})})};Y();let G=new ResizeObserver(Y);return G.observe(document.documentElement),G.observe(document.body),()=>G.disconnect()}async connect(K=new j(window.parent,window.parent),Q){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(K);try{let X=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:U}},y,Q);if(X===void 0)throw Error(`Server sent invalid initialize result: ${X}`);if(this._hostCapabilities=X.hostCapabilities,this._hostInfo=X.hostInfo,this._hostContext=X.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(X){throw this.close(),X}}}function lK({appInfo:K,capabilities:Q,onAppCreated:X}){let[Y,G]=d(null),[Z,V]=d(!1),[E,W]=d(null);return fJ(()=>{let N=!0;async function B(){try{let $=new j(window.parent,window.parent),R=new f(K,Q);if(X?.(R),await R.connect($),N)G(R),V(!0),W(null)}catch($){if(N)G(null),V(!1),W($ instanceof Error?$:Error("Failed to connect"))}}return B(),()=>{N=!1}},[]),{app:Y,isConnected:Z,error:E}}import{useEffect as dJ}from"react";function oK(K,Q){dJ(()=>{if(!K)return;return K.setupSizeChangedNotifications()},[K,Q])}import{useEffect as uJ,useState as hJ}from"react";function JQ(){let[K,Q]=hJ(O);return uJ(()=>{let X=new MutationObserver(()=>{Q(O())});return X.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"],characterData:!1,childList:!1,subtree:!1}),()=>X.disconnect()},[]),K}import{useEffect as F,useRef as n}from"react";function mJ(K,Q){let X=n(!1);F(()=>{if(X.current)return;if(Q?.theme)q(Q.theme);if(Q?.styles?.variables)D(Q.styles.variables);if(Q?.theme||Q?.styles?.variables)X.current=!0},[Q]),F(()=>{if(!K)return;K.onhostcontextchanged=(Y)=>{if(Y.theme)q(Y.theme);if(Y.styles?.variables)D(Y.styles.variables)}},[K])}function cJ(K,Q){let X=n(!1);F(()=>{if(X.current)return;if(Q?.styles?.css?.fonts)I(Q.styles.css.fonts),X.current=!0},[Q]),F(()=>{if(!K)return;K.onhostcontextchanged=(Y)=>{if(Y.styles?.css?.fonts)I(Y.styles.css.fonts)}},[K])}function YQ(K,Q){mJ(K,Q),cJ(K,Q)}export{YQ as useHostStyles,mJ as useHostStyleVariables,cJ as useHostFonts,JQ as useDocumentTheme,oK as useAutoResize,lK as useApp,O as getDocumentTheme,D as applyHostStyleVariables,I as applyHostFonts,q as applyDocumentTheme,QJ as TOOL_RESULT_METHOD,z as TOOL_INPUT_PARTIAL_METHOD,KJ as TOOL_INPUT_METHOD,XJ as TOOL_CANCELLED_METHOD,JJ as SIZE_CHANGED_METHOD,e as SANDBOX_RESOURCE_READY_METHOD,t as SANDBOX_PROXY_READY_METHOD,xK as RESOURCE_URI_META_KEY,ZJ as RESOURCE_TEARDOWN_METHOD,yK as RESOURCE_MIME_TYPE,jJ as REQUEST_DISPLAY_MODE_METHOD,j as PostMessageTransport,a as OPEN_LINK_METHOD,HJ as McpUiUpdateModelContextRequestSchema,p as McpUiToolVisibilitySchema,C as McpUiToolResultNotificationSchema,zJ as McpUiToolMetaSchema,A as McpUiToolInputPartialNotificationSchema,v as McpUiToolInputNotificationSchema,k as McpUiToolCancelledNotificationSchema,m as McpUiThemeSchema,M as McpUiSupportedContentBlockModalitiesSchema,IJ as McpUiSizeChangedNotificationSchema,TJ as McpUiSandboxResourceReadyNotificationSchema,DJ as McpUiSandboxProxyReadyNotificationSchema,FJ as McpUiResourceTeardownResultSchema,S as McpUiResourceTeardownRequestSchema,_ as McpUiResourcePermissionsSchema,RJ as McpUiResourceMetaSchema,P as McpUiResourceCspSchema,b as McpUiRequestDisplayModeResultSchema,UJ as McpUiRequestDisplayModeRequestSchema,w as McpUiOpenLinkResultSchema,qJ as McpUiOpenLinkRequestSchema,H as McpUiMessageResultSchema,wJ as McpUiMessageRequestSchema,EJ as McpUiInitializedNotificationSchema,y as McpUiInitializeResultSchema,vJ as McpUiInitializeRequestSchema,r as McpUiHostStylesSchema,c as McpUiHostCssSchema,g as McpUiHostContextSchema,x as McpUiHostContextChangedNotificationSchema,l as McpUiHostCapabilitiesSchema,T as McpUiDownloadFileResultSchema,MJ as McpUiDownloadFileRequestSchema,L as McpUiDisplayModeSchema,i as McpUiAppCapabilitiesSchema,s as MESSAGE_METHOD,U as LATEST_PROTOCOL_VERSION,$J as INITIALIZE_METHOD,GJ as INITIALIZED_METHOD,YJ as HOST_CONTEXT_CHANGED_METHOD,o as DOWNLOAD_FILE_METHOD,f as App};
|
|
38
|
+
- "app": Tool callable by the app from this server only`)}),JK=J.object({mimeTypes:J.array(J.string()).optional().describe('Array of supported MIME types for UI resources.\nMust include `"text/html;profile=mcp-app"` for MCP Apps support.')}),TJ=J.object({method:J.literal("ui/download-file"),params:J.object({contents:J.array(J.union([BJ,PJ])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),HJ=J.object({method:J.literal("ui/message"),params:J.object({role:J.literal("user").describe('Message role, currently only "user" is supported.'),content:J.array(u).describe("Message content blocks (text, image, etc.).")})}),vJ=J.object({method:J.literal("ui/notifications/sandbox-resource-ready"),params:J.object({html:J.string().describe("HTML content to load into the inner iframe."),sandbox:J.string().optional().describe("Optional override for the inner iframe's sandbox attribute."),csp:P.optional().describe("CSP configuration from resource metadata."),permissions:_.optional().describe("Sandbox permissions from resource metadata.")})}),C=J.object({method:J.literal("ui/notifications/tool-result"),params:NJ.describe("Standard MCP tool execution result.")}),g=J.object({toolInfo:J.object({id:VJ.optional().describe("JSON-RPC id of the tools/call request."),tool:_J.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:m.optional().describe("Current color theme preference."),styles:r.optional().describe("Style configuration for theming the app."),displayMode:W.optional().describe("How the UI is currently displayed."),availableDisplayModes:J.array(W).optional().describe("Display modes the host supports."),containerDimensions:J.union([J.object({height:J.number().describe("Fixed container height in pixels.")}),J.object({maxHeight:J.union([J.number(),J.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(J.union([J.object({width:J.number().describe("Fixed container width in pixels.")}),J.object({maxWidth:J.union([J.number(),J.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:J.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:J.string().optional().describe("User's timezone in IANA format."),userAgent:J.string().optional().describe("Host application identifier."),platform:J.union([J.literal("web"),J.literal("desktop"),J.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:J.object({touch:J.boolean().optional().describe("Whether the device supports touch input."),hover:J.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:J.object({top:J.number().describe("Top safe area inset in pixels."),right:J.number().describe("Right safe area inset in pixels."),bottom:J.number().describe("Bottom safe area inset in pixels."),left:J.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),x=J.object({method:J.literal("ui/notifications/host-context-changed"),params:g.describe("Partial context update containing only changed fields.")}),AJ=J.object({method:J.literal("ui/update-model-context"),params:J.object({content:J.array(u).optional().describe("Context content blocks (text, image, etc.)."),structuredContent:J.record(J.string(),J.unknown().describe("Structured content for machine-readable context data.")).optional().describe("Structured content for machine-readable context data.")})}),kJ=J.object({method:J.literal("ui/initialize"),params:J.object({appInfo:h.describe("App identification (name and version)."),appCapabilities:i.describe("Features and capabilities this app provides."),protocolVersion:J.string().describe("Protocol version this app supports.")})}),y=J.object({protocolVersion:J.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:h.describe("Host application identification and version."),hostCapabilities:l.describe("Features and capabilities provided by the host."),hostContext:g.describe("Rich context about the host environment.")}).passthrough();function O(){let K=document.documentElement.getAttribute("data-theme");if(K==="dark"||K==="light")return K;return document.documentElement.classList.contains("dark")?"dark":"light"}function q(K){let Q=document.documentElement;Q.setAttribute("data-theme",K),Q.style.colorScheme=K}function D(K,Q=document.documentElement){for(let[X,Y]of Object.entries(K))if(Y!==void 0)Q.style.setProperty(X,Y)}function I(K){if(document.getElementById("__mcp-host-fonts"))return;let X=document.createElement("style");X.id="__mcp-host-fonts",X.textContent=K,document.head.appendChild(X)}var dK="ui/resourceUri",uK="text/html;profile=mcp-app";class f extends bJ{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(K,Q={},X={autoResize:!0}){super(X);this._appInfo=K;this._capabilities=Q;this.options=X;this.setRequestHandler(fJ,(Y)=>{return console.log("Received ping:",Y.params),{}}),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(K){this.setNotificationHandler(v,(Q)=>K(Q.params))}set ontoolinputpartial(K){this.setNotificationHandler(A,(Q)=>K(Q.params))}set ontoolresult(K){this.setNotificationHandler(C,(Q)=>K(Q.params))}set ontoolcancelled(K){this.setNotificationHandler(k,(Q)=>K(Q.params))}set onhostcontextchanged(K){this.setNotificationHandler(x,(Q)=>{this._hostContext={...this._hostContext,...Q.params},K(Q.params)})}set onteardown(K){this.setRequestHandler(b,(Q,X)=>K(Q.params,X))}set oncalltool(K){this.setRequestHandler(SJ,(Q,X)=>K(Q.params,X))}set onlisttools(K){this.setRequestHandler(yJ,(Q,X)=>K(Q.params,X))}assertCapabilityForMethod(K){}assertRequestHandlerCapability(K){switch(K){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${K})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${K} registered`)}}assertNotificationCapability(K){}assertTaskCapability(K){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(K){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(K,Q){if(typeof K==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${K}"). Did you mean: callServerTool({ name: "${K}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:K},CJ,Q)}async readServerResource(K,Q){return await this.request({method:"resources/read",params:K},dJ,Q)}async listServerResources(K,Q){return await this.request({method:"resources/list",params:K},xJ,Q)}sendMessage(K,Q){return this.request({method:"ui/message",params:K},H,Q)}sendLog(K){return this.notification({method:"notifications/message",params:K})}updateModelContext(K,Q){return this.request({method:"ui/update-model-context",params:K},gJ,Q)}openLink(K,Q){return this.request({method:"ui/open-link",params:K},M,Q)}sendOpenLink=this.openLink;downloadFile(K,Q){return this.request({method:"ui/download-file",params:K},T,Q)}requestTeardown(K={}){return this.notification({method:"ui/notifications/request-teardown",params:K})}requestDisplayMode(K,Q){return this.request({method:"ui/request-display-mode",params:K},S,Q)}sendSizeChanged(K){return this.notification({method:"ui/notifications/size-changed",params:K})}setupSizeChangedNotifications(){let K=!1,Q=0,X=0,Y=()=>{if(K)return;K=!0,requestAnimationFrame(()=>{K=!1;let Z=document.documentElement,V=Z.style.width,E=Z.style.height;Z.style.width="fit-content",Z.style.height="max-content";let L=Z.getBoundingClientRect();Z.style.width=V,Z.style.height=E;let N=window.innerWidth-Z.clientWidth,B=Math.ceil(L.width+N),$=Math.ceil(L.height);if(B!==Q||$!==X)Q=B,X=$,this.sendSizeChanged({width:B,height:$})})};Y();let G=new ResizeObserver(Y);return G.observe(document.documentElement),G.observe(document.body),()=>G.disconnect()}async connect(K=new j(window.parent,window.parent),Q){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(K);try{let X=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:z}},y,Q);if(X===void 0)throw Error(`Server sent invalid initialize result: ${X}`);if(this._hostCapabilities=X.hostCapabilities,this._hostInfo=X.hostInfo,this._hostContext=X.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(X){throw this.close(),X}}}function nK({appInfo:K,capabilities:Q,onAppCreated:X}){let[Y,G]=d(null),[Z,V]=d(!1),[E,L]=d(null);return uJ(()=>{let N=!0;async function B(){try{let $=new j(window.parent,window.parent),R=new f(K,Q);if(X?.(R),await R.connect($),N)G(R),V(!0),L(null)}catch($){if(N)G(null),V(!1),L($ instanceof Error?$:Error("Failed to connect"))}}return B(),()=>{N=!1}},[]),{app:Y,isConnected:Z,error:E}}import{useEffect as hJ}from"react";function eK(K,Q){hJ(()=>{if(!K)return;return K.setupSizeChangedNotifications()},[K,Q])}import{useEffect as mJ,useState as cJ}from"react";function XQ(){let[K,Q]=cJ(O);return mJ(()=>{let X=new MutationObserver(()=>{Q(O())});return X.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme","class"],characterData:!1,childList:!1,subtree:!1}),()=>X.disconnect()},[]),K}import{useEffect as F,useRef as n}from"react";function rJ(K,Q){let X=n(!1);F(()=>{if(X.current)return;if(Q?.theme)q(Q.theme);if(Q?.styles?.variables)D(Q.styles.variables);if(Q?.theme||Q?.styles?.variables)X.current=!0},[Q]),F(()=>{if(!K)return;K.onhostcontextchanged=(Y)=>{if(Y.theme)q(Y.theme);if(Y.styles?.variables)D(Y.styles.variables)}},[K])}function lJ(K,Q){let X=n(!1);F(()=>{if(X.current)return;if(Q?.styles?.css?.fonts)I(Q.styles.css.fonts),X.current=!0},[Q]),F(()=>{if(!K)return;K.onhostcontextchanged=(Y)=>{if(Y.styles?.css?.fonts)I(Y.styles.css.fonts)}},[K])}function GQ(K,Q){rJ(K,Q),lJ(K,Q)}export{GQ as useHostStyles,rJ as useHostStyleVariables,lJ as useHostFonts,XQ as useDocumentTheme,eK as useAutoResize,nK as useApp,O as getDocumentTheme,D as applyHostStyleVariables,I as applyHostFonts,q as applyDocumentTheme,QJ as TOOL_RESULT_METHOD,U as TOOL_INPUT_PARTIAL_METHOD,KJ as TOOL_INPUT_METHOD,XJ as TOOL_CANCELLED_METHOD,JJ as SIZE_CHANGED_METHOD,e as SANDBOX_RESOURCE_READY_METHOD,t as SANDBOX_PROXY_READY_METHOD,dK as RESOURCE_URI_META_KEY,$J as RESOURCE_TEARDOWN_METHOD,uK as RESOURCE_MIME_TYPE,ZJ as REQUEST_TEARDOWN_METHOD,WJ as REQUEST_DISPLAY_MODE_METHOD,j as PostMessageTransport,o as OPEN_LINK_METHOD,AJ as McpUiUpdateModelContextRequestSchema,p as McpUiToolVisibilitySchema,C as McpUiToolResultNotificationSchema,MJ as McpUiToolMetaSchema,A as McpUiToolInputPartialNotificationSchema,v as McpUiToolInputNotificationSchema,k as McpUiToolCancelledNotificationSchema,m as McpUiThemeSchema,w as McpUiSupportedContentBlockModalitiesSchema,FJ as McpUiSizeChangedNotificationSchema,vJ as McpUiSandboxResourceReadyNotificationSchema,IJ as McpUiSandboxProxyReadyNotificationSchema,EJ as McpUiResourceTeardownResultSchema,b as McpUiResourceTeardownRequestSchema,_ as McpUiResourcePermissionsSchema,UJ as McpUiResourceMetaSchema,P as McpUiResourceCspSchema,RJ as McpUiRequestTeardownNotificationSchema,S as McpUiRequestDisplayModeResultSchema,wJ as McpUiRequestDisplayModeRequestSchema,M as McpUiOpenLinkResultSchema,DJ as McpUiOpenLinkRequestSchema,H as McpUiMessageResultSchema,HJ as McpUiMessageRequestSchema,zJ as McpUiInitializedNotificationSchema,y as McpUiInitializeResultSchema,kJ as McpUiInitializeRequestSchema,r as McpUiHostStylesSchema,c as McpUiHostCssSchema,g as McpUiHostContextSchema,x as McpUiHostContextChangedNotificationSchema,l as McpUiHostCapabilitiesSchema,T as McpUiDownloadFileResultSchema,TJ as McpUiDownloadFileRequestSchema,W as McpUiDisplayModeSchema,i as McpUiAppCapabilitiesSchema,s as MESSAGE_METHOD,z as LATEST_PROTOCOL_VERSION,GJ as INITIALIZE_METHOD,jJ as INITIALIZED_METHOD,YJ as HOST_CONTEXT_CHANGED_METHOD,a as DOWNLOAD_FILE_METHOD,f as App};
|