Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@modelcontextprotocol/ext-apps

Package Overview
Dependencies
Maintainers
6
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@modelcontextprotocol/ext-apps - npm Package Compare versions

Comparing version
1.5.0
to
1.6.0
+1
-1
dist/src/app-bridge.js

@@ -39,2 +39,2 @@ import{CallToolRequestSchema as fQ,CallToolResultSchema as t,ListPromptsRequestSchema as yQ,ListPromptsResultSchema as vQ,ListResourcesRequestSchema as xQ,ListResourcesResultSchema as kQ,ListResourceTemplatesRequestSchema as dQ,ListResourceTemplatesResultSchema as bQ,ListToolsResultSchema as uQ,LoggingMessageNotificationSchema as hQ,PingRequestSchema as mQ,PromptListChangedNotificationSchema as iQ,ReadResourceRequestSchema as pQ,ReadResourceResultSchema as nQ,ResourceListChangedNotificationSchema as cQ,ToolListChangedNotificationSchema as rQ}from"@modelcontextprotocol/sdk/types.js";import{Protocol as s}from"@modelcontextprotocol/sdk/shared/protocol.js";class j extends s{_registeredMethods=new Set;_eventSlots=new Map;onEventDispatch(X,Y){}_ensureEventSlot(X){let Y=this._eventSlots.get(X);if(!Y){let Z=this.eventSchemas[X];if(!Z)throw Error(`Unknown event: ${String(X)}`);Y={listeners:[]},this._eventSlots.set(X,Y);let $=Z.shape.method.value;this._registeredMethods.add($);let J=Y;super.setNotificationHandler(Z,(K)=>{let N=K.params;this.onEventDispatch(X,N),J.onHandler?.(N);for(let W of[...J.listeners])W(N)})}return Y}setEventHandler(X,Y){let Z=this._ensureEventSlot(X);if(Z.onHandler&&Y)console.warn(`[MCP Apps] on${String(X)} handler replaced. Use addEventListener("${String(X)}", …) to add multiple listeners without replacing.`);Z.onHandler=Y}getEventHandler(X){return this._eventSlots.get(X)?.onHandler}addEventListener(X,Y){this._ensureEventSlot(X).listeners.push(Y)}removeEventListener(X,Y){let Z=this._eventSlots.get(X);if(!Z)return;let $=Z.listeners.indexOf(Y);if($!==-1)Z.listeners.splice($,1)}setRequestHandler=(X,Y)=>{this._assertMethodNotRegistered(X,"setRequestHandler"),super.setRequestHandler(X,Y)};setNotificationHandler=(X,Y)=>{this._assertMethodNotRegistered(X,"setNotificationHandler"),super.setNotificationHandler(X,Y)};warnIfRequestHandlerReplaced(X,Y,Z){if(Y&&Z)console.warn(`[MCP Apps] ${X} handler replaced. Previous handler will no longer be called.`)}replaceRequestHandler=(X,Y)=>{let Z=X.shape.method.value;this._registeredMethods.add(Z),super.setRequestHandler(X,Y)};_assertMethodNotRegistered(X,Y){let Z=X.shape.method.value;if(this._registeredMethods.has(Z))throw Error(`Handler for "${Z}" already registered (via ${Y}). Use addEventListener() to attach multiple listeners, or the on* setter for replace semantics.`);this._registeredMethods.add(Z)}}var G="2026-01-26",a="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",V="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",WQ="ui/initialize",jQ="ui/notifications/initialized",zQ="ui/request-display-mode";import{z as Q}from"zod/v4";import{ContentBlockSchema as m,CallToolResultSchema as BQ,EmbeddedResourceSchema as EQ,ImplementationSchema as i,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.

- "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.')}),f=Q.object({method:Q.literal("ui/download-file"),params:Q.object({contents:Q.array(Q.union([EQ,OQ])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),y=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.).")})}),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:B.optional().describe("CSP configuration from resource metadata."),permissions:E.optional().describe("Sandbox permissions from resource metadata.")})}),v=Q.object({method:Q.literal("ui/notifications/tool-result"),params:BQ.describe("Standard MCP tool execution result.")}),x=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:c.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
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:x.describe("Partial context update containing only changed fields.")}),d=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.")})}),b=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:i.describe("App identification (name and version)."),appCapabilities:l.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:i.describe("Host application identification and version."),hostCapabilities:r.describe("Features and capabilities provided by the host."),hostContext:x.describe("Rich context about the host environment.")}).passthrough();import{CallToolRequestSchema as wQ,CallToolResultSchema as RQ,EmptyResultSchema as UQ,ListResourcesResultSchema as HQ,ListToolsRequestSchema as MQ,PingRequestSchema as gQ,ReadResourceResultSchema as CQ}from"@modelcontextprotocol/sdk/types.js";import{JSONRPCMessageSchema as TQ}from"@modelcontextprotocol/sdk/types.js";class z{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!==V)console.debug("Sending message",X);this.eventTarget.postMessage(X,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}var h="ui/resourceUri",SQ="text/html;profile=mcp-app";class qQ extends j{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:R,toolinputpartial:U,toolresult:v,toolcancelled:H,hostcontextchanged:k};onEventDispatch(X,Y){if(X==="hostcontextchanged")this._hostContext={...this._hostContext,...Y}}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.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(X){this.setEventHandler("toolinput",X)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(X){this.setEventHandler("toolinputpartial",X)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(X){this.setEventHandler("toolresult",X)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(X){this.setEventHandler("toolcancelled",X)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(X){this.setEventHandler("hostcontextchanged",X)}_onteardown;get onteardown(){return this._onteardown}set onteardown(X){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,X),this._onteardown=X,this.replaceRequestHandler(M,(Y,Z)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(Y.params,Z)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(X){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,X),this._oncalltool=X,this.replaceRequestHandler(wQ,(Y,Z)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Y.params,Z)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(X){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,X),this._onlisttools=X,this.replaceRequestHandler(MQ,(Y,Z)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(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},RQ,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},HQ,Y)}sendMessage(X,Y){return this.request({method:"ui/message",params:X},P,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},F,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this.request({method:"ui/download-file",params:X},L,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},q,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 K=document.documentElement,N=K.style.height;K.style.height="max-content";let W=Math.ceil(K.getBoundingClientRect().height);K.style.height=N;let O=Math.ceil(window.innerWidth);if(O!==Y||W!==Z)Y=O,Z=W,this.sendSizeChanged({width:O,height:W})})};$();let J=new ResizeObserver($);return J.observe(document.documentElement),J.observe(document.body),()=>J.disconnect()}async connect(X=new z(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}},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}}}function nY(X){let Z=X._meta?.ui?.resourceUri;if(Z===void 0)Z=X._meta?.[h];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 cY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="model")return!0;return!1}function rY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="app")return!0;return!1}function lY(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 lQ=[G];class oQ extends j{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;eventSchemas={sizechange:w,sandboxready:T,initialized:S,requestteardown:C,loggingmessage:hQ};constructor(X,Y,Z,$){super($);this._client=X;this._hostInfo=Y;this._capabilities=Z;this._hostContext=$?.hostContext||{},this.setRequestHandler(b,(J)=>this._oninitialize(J)),this.setRequestHandler(mQ,(J,K)=>{return this.onping?.(J.params,K),{}}),this.replaceRequestHandler(_,(J)=>{return{mode:this._hostContext.displayMode??"inline"}})}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;get onsizechange(){return this.getEventHandler("sizechange")}set onsizechange(X){this.setEventHandler("sizechange",X)}get onsandboxready(){return this.getEventHandler("sandboxready")}set onsandboxready(X){this.setEventHandler("sandboxready",X)}get oninitialized(){return this.getEventHandler("initialized")}set oninitialized(X){this.setEventHandler("initialized",X)}_onmessage;get onmessage(){return this._onmessage}set onmessage(X){this.warnIfRequestHandlerReplaced("onmessage",this._onmessage,X),this._onmessage=X,this.replaceRequestHandler(y,async(Y,Z)=>{if(!this._onmessage)throw Error("No onmessage handler set");return this._onmessage(Y.params,Z)})}_onopenlink;get onopenlink(){return this._onopenlink}set onopenlink(X){this.warnIfRequestHandlerReplaced("onopenlink",this._onopenlink,X),this._onopenlink=X,this.replaceRequestHandler(A,async(Y,Z)=>{if(!this._onopenlink)throw Error("No onopenlink handler set");return this._onopenlink(Y.params,Z)})}_ondownloadfile;get ondownloadfile(){return this._ondownloadfile}set ondownloadfile(X){this.warnIfRequestHandlerReplaced("ondownloadfile",this._ondownloadfile,X),this._ondownloadfile=X,this.replaceRequestHandler(f,async(Y,Z)=>{if(!this._ondownloadfile)throw Error("No ondownloadfile handler set");return this._ondownloadfile(Y.params,Z)})}get onrequestteardown(){return this.getEventHandler("requestteardown")}set onrequestteardown(X){this.setEventHandler("requestteardown",X)}_onrequestdisplaymode;get onrequestdisplaymode(){return this._onrequestdisplaymode}set onrequestdisplaymode(X){this.warnIfRequestHandlerReplaced("onrequestdisplaymode",this._onrequestdisplaymode,X),this._onrequestdisplaymode=X,this.replaceRequestHandler(_,async(Y,Z)=>{if(!this._onrequestdisplaymode)throw Error("No onrequestdisplaymode handler set");return this._onrequestdisplaymode(Y.params,Z)})}get onloggingmessage(){return this.getEventHandler("loggingmessage")}set onloggingmessage(X){this.setEventHandler("loggingmessage",X)}_onupdatemodelcontext;get onupdatemodelcontext(){return this._onupdatemodelcontext}set onupdatemodelcontext(X){this.warnIfRequestHandlerReplaced("onupdatemodelcontext",this._onupdatemodelcontext,X),this._onupdatemodelcontext=X,this.replaceRequestHandler(d,async(Y,Z)=>{if(!this._onupdatemodelcontext)throw Error("No onupdatemodelcontext handler set");return this._onupdatemodelcontext(Y.params,Z)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(X){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,X),this._oncalltool=X,this.replaceRequestHandler(fQ,async(Y,Z)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Y.params,Z)})}sendToolListChanged(X={}){return this.notification({method:"notifications/tools/list_changed",params:X})}_onlistresources;get onlistresources(){return this._onlistresources}set onlistresources(X){this.warnIfRequestHandlerReplaced("onlistresources",this._onlistresources,X),this._onlistresources=X,this.replaceRequestHandler(xQ,async(Y,Z)=>{if(!this._onlistresources)throw Error("No onlistresources handler set");return this._onlistresources(Y.params,Z)})}_onlistresourcetemplates;get onlistresourcetemplates(){return this._onlistresourcetemplates}set onlistresourcetemplates(X){this.warnIfRequestHandlerReplaced("onlistresourcetemplates",this._onlistresourcetemplates,X),this._onlistresourcetemplates=X,this.replaceRequestHandler(dQ,async(Y,Z)=>{if(!this._onlistresourcetemplates)throw Error("No onlistresourcetemplates handler set");return this._onlistresourcetemplates(Y.params,Z)})}_onreadresource;get onreadresource(){return this._onreadresource}set onreadresource(X){this.warnIfRequestHandlerReplaced("onreadresource",this._onreadresource,X),this._onreadresource=X,this.replaceRequestHandler(pQ,async(Y,Z)=>{if(!this._onreadresource)throw Error("No onreadresource handler set");return this._onreadresource(Y.params,Z)})}sendResourceListChanged(X={}){return this.notification({method:"notifications/resources/list_changed",params:X})}_onlistprompts;get onlistprompts(){return this._onlistprompts}set onlistprompts(X){this.warnIfRequestHandlerReplaced("onlistprompts",this._onlistprompts,X),this._onlistprompts=X,this.replaceRequestHandler(yQ,async(Y,Z)=>{if(!this._onlistprompts)throw Error("No onlistprompts handler set");return this._onlistprompts(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:lQ.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 J=this._hostContext[$],K=X[$];if(tQ(J,K))continue;Y[$]=K,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},g,Y)}sendResourceTeardown=this.teardownResource;callTool(X,Y){return this.request({method:"tools/call",params:X},t,Y)}listTools(X,Y){return this.request({method:"tools/list",params:X},uQ,Y)}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},t,{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},kQ,{signal:$.signal})},this.onlistresourcetemplates=async(Z,$)=>{return this._client.request({method:"resources/templates/list",params:Z},bQ,{signal:$.signal})},this.onreadresource=async(Z,$)=>{return this._client.request({method:"resources/read",params:Z},nQ,{signal:$.signal})},Y.resources.listChanged)this._client.setNotificationHandler(cQ,(Z)=>this.sendResourceListChanged(Z.params))}if(Y.prompts){if(this.onlistprompts=async(Z,$)=>{return this._client.request({method:"prompts/list",params:Z},vQ,{signal:$.signal})},Y.prompts.listChanged)this._client.setNotificationHandler(iQ,(Z)=>this.sendPromptListChanged(Z.params))}}return super.connect(X)}}function tQ(X,Y){return JSON.stringify(X)===JSON.stringify(Y)}export{cY as isToolVisibilityModelOnly,rY as isToolVisibilityAppOnly,nY as getToolUiResourceUri,lY as buildAllowAttribute,JQ as TOOL_RESULT_METHOD,V as TOOL_INPUT_PARTIAL_METHOD,$Q as TOOL_INPUT_METHOD,KQ as TOOL_CANCELLED_METHOD,lQ as SUPPORTED_PROTOCOL_VERSIONS,ZQ as SIZE_CHANGED_METHOD,YQ as SANDBOX_RESOURCE_READY_METHOD,XQ as SANDBOX_PROXY_READY_METHOD,h as RESOURCE_URI_META_KEY,NQ as RESOURCE_TEARDOWN_METHOD,SQ as RESOURCE_MIME_TYPE,DQ as REQUEST_TEARDOWN_METHOD,zQ as REQUEST_DISPLAY_MODE_METHOD,z as PostMessageTransport,a as OPEN_LINK_METHOD,d as McpUiUpdateModelContextRequestSchema,o as McpUiToolVisibilitySchema,v as McpUiToolResultNotificationSchema,LQ as McpUiToolMetaSchema,U as McpUiToolInputPartialNotificationSchema,R as McpUiToolInputNotificationSchema,H as McpUiToolCancelledNotificationSchema,p as McpUiThemeSchema,I as McpUiSupportedContentBlockModalitiesSchema,w as McpUiSizeChangedNotificationSchema,PQ as McpUiSandboxResourceReadyNotificationSchema,T as McpUiSandboxProxyReadyNotificationSchema,g as McpUiResourceTeardownResultSchema,M as McpUiResourceTeardownRequestSchema,E as McpUiResourcePermissionsSchema,FQ as McpUiResourceMetaSchema,B as McpUiResourceCspSchema,C as McpUiRequestTeardownNotificationSchema,q as McpUiRequestDisplayModeResultSchema,_ as McpUiRequestDisplayModeRequestSchema,F as McpUiOpenLinkResultSchema,A as McpUiOpenLinkRequestSchema,P as McpUiMessageResultSchema,y as McpUiMessageRequestSchema,S as McpUiInitializedNotificationSchema,u as McpUiInitializeResultSchema,b as McpUiInitializeRequestSchema,c as McpUiHostStylesSchema,n as McpUiHostCssSchema,x as McpUiHostContextSchema,k as McpUiHostContextChangedNotificationSchema,r as McpUiHostCapabilitiesSchema,L as McpUiDownloadFileResultSchema,f as McpUiDownloadFileRequestSchema,D as McpUiDisplayModeSchema,l as McpUiAppCapabilitiesSchema,QQ as MESSAGE_METHOD,G as LATEST_PROTOCOL_VERSION,WQ as INITIALIZE_METHOD,jQ as INITIALIZED_METHOD,GQ as HOST_CONTEXT_CHANGED_METHOD,e as DOWNLOAD_FILE_METHOD,oQ as AppBridge};
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:x.describe("Partial context update containing only changed fields.")}),d=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.")})}),b=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:i.describe("App identification (name and version)."),appCapabilities:l.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:i.describe("Host application identification and version."),hostCapabilities:r.describe("Features and capabilities provided by the host."),hostContext:x.describe("Rich context about the host environment.")}).passthrough();import{CallToolRequestSchema as wQ,CallToolResultSchema as RQ,EmptyResultSchema as UQ,ListResourcesResultSchema as HQ,ListToolsRequestSchema as MQ,PingRequestSchema as gQ,ReadResourceResultSchema as CQ}from"@modelcontextprotocol/sdk/types.js";import{JSONRPCMessageSchema as TQ}from"@modelcontextprotocol/sdk/types.js";class z{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!==V)console.debug("Sending message",X);this.eventTarget.postMessage(X,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}var h="ui/resourceUri",SQ="text/html;profile=mcp-app";class qQ extends j{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:R,toolinputpartial:U,toolresult:v,toolcancelled:H,hostcontextchanged:k};onEventDispatch(X,Y){if(X==="hostcontextchanged")this._hostContext={...this._hostContext,...Y}}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.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(X){this.setEventHandler("toolinput",X)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(X){this.setEventHandler("toolinputpartial",X)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(X){this.setEventHandler("toolresult",X)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(X){this.setEventHandler("toolcancelled",X)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(X){this.setEventHandler("hostcontextchanged",X)}_onteardown;get onteardown(){return this._onteardown}set onteardown(X){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,X),this._onteardown=X,this.replaceRequestHandler(M,(Y,Z)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(Y.params,Z)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(X){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,X),this._oncalltool=X,this.replaceRequestHandler(wQ,(Y,Z)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Y.params,Z)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(X){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,X),this._onlisttools=X,this.replaceRequestHandler(MQ,(Y,Z)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(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},RQ,{onprogress:()=>{},resetTimeoutOnProgress:!0,...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},HQ,Y)}sendMessage(X,Y){return this.request({method:"ui/message",params:X},P,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},F,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this.request({method:"ui/download-file",params:X},L,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},q,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 K=document.documentElement,N=K.style.height;K.style.height="max-content";let W=Math.ceil(K.getBoundingClientRect().height);K.style.height=N;let O=Math.ceil(window.innerWidth);if(O!==Y||W!==Z)Y=O,Z=W,this.sendSizeChanged({width:O,height:W})})};$();let J=new ResizeObserver($);return J.observe(document.documentElement),J.observe(document.body),()=>J.disconnect()}async connect(X=new z(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}},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}}}function nY(X){let Z=X._meta?.ui?.resourceUri;if(Z===void 0)Z=X._meta?.[h];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 cY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="model")return!0;return!1}function rY(X){let Z=X._meta?.ui?.visibility;if(!Z)return!1;if(Z.length===1&&Z[0]==="app")return!0;return!1}function lY(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 lQ=[G];class oQ extends j{_client;_hostInfo;_capabilities;_appCapabilities;_hostContext={};_appInfo;eventSchemas={sizechange:w,sandboxready:T,initialized:S,requestteardown:C,loggingmessage:hQ};constructor(X,Y,Z,$){super($);this._client=X;this._hostInfo=Y;this._capabilities=Z;this._hostContext=$?.hostContext||{},this.setRequestHandler(b,(J)=>this._oninitialize(J)),this.setRequestHandler(mQ,(J,K)=>{return this.onping?.(J.params,K),{}}),this.replaceRequestHandler(_,(J)=>{return{mode:this._hostContext.displayMode??"inline"}})}getAppCapabilities(){return this._appCapabilities}getAppVersion(){return this._appInfo}onping;get onsizechange(){return this.getEventHandler("sizechange")}set onsizechange(X){this.setEventHandler("sizechange",X)}get onsandboxready(){return this.getEventHandler("sandboxready")}set onsandboxready(X){this.setEventHandler("sandboxready",X)}get oninitialized(){return this.getEventHandler("initialized")}set oninitialized(X){this.setEventHandler("initialized",X)}_onmessage;get onmessage(){return this._onmessage}set onmessage(X){this.warnIfRequestHandlerReplaced("onmessage",this._onmessage,X),this._onmessage=X,this.replaceRequestHandler(y,async(Y,Z)=>{if(!this._onmessage)throw Error("No onmessage handler set");return this._onmessage(Y.params,Z)})}_onopenlink;get onopenlink(){return this._onopenlink}set onopenlink(X){this.warnIfRequestHandlerReplaced("onopenlink",this._onopenlink,X),this._onopenlink=X,this.replaceRequestHandler(A,async(Y,Z)=>{if(!this._onopenlink)throw Error("No onopenlink handler set");return this._onopenlink(Y.params,Z)})}_ondownloadfile;get ondownloadfile(){return this._ondownloadfile}set ondownloadfile(X){this.warnIfRequestHandlerReplaced("ondownloadfile",this._ondownloadfile,X),this._ondownloadfile=X,this.replaceRequestHandler(f,async(Y,Z)=>{if(!this._ondownloadfile)throw Error("No ondownloadfile handler set");return this._ondownloadfile(Y.params,Z)})}get onrequestteardown(){return this.getEventHandler("requestteardown")}set onrequestteardown(X){this.setEventHandler("requestteardown",X)}_onrequestdisplaymode;get onrequestdisplaymode(){return this._onrequestdisplaymode}set onrequestdisplaymode(X){this.warnIfRequestHandlerReplaced("onrequestdisplaymode",this._onrequestdisplaymode,X),this._onrequestdisplaymode=X,this.replaceRequestHandler(_,async(Y,Z)=>{if(!this._onrequestdisplaymode)throw Error("No onrequestdisplaymode handler set");return this._onrequestdisplaymode(Y.params,Z)})}get onloggingmessage(){return this.getEventHandler("loggingmessage")}set onloggingmessage(X){this.setEventHandler("loggingmessage",X)}_onupdatemodelcontext;get onupdatemodelcontext(){return this._onupdatemodelcontext}set onupdatemodelcontext(X){this.warnIfRequestHandlerReplaced("onupdatemodelcontext",this._onupdatemodelcontext,X),this._onupdatemodelcontext=X,this.replaceRequestHandler(d,async(Y,Z)=>{if(!this._onupdatemodelcontext)throw Error("No onupdatemodelcontext handler set");return this._onupdatemodelcontext(Y.params,Z)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(X){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,X),this._oncalltool=X,this.replaceRequestHandler(fQ,async(Y,Z)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Y.params,Z)})}sendToolListChanged(X={}){return this.notification({method:"notifications/tools/list_changed",params:X})}_onlistresources;get onlistresources(){return this._onlistresources}set onlistresources(X){this.warnIfRequestHandlerReplaced("onlistresources",this._onlistresources,X),this._onlistresources=X,this.replaceRequestHandler(xQ,async(Y,Z)=>{if(!this._onlistresources)throw Error("No onlistresources handler set");return this._onlistresources(Y.params,Z)})}_onlistresourcetemplates;get onlistresourcetemplates(){return this._onlistresourcetemplates}set onlistresourcetemplates(X){this.warnIfRequestHandlerReplaced("onlistresourcetemplates",this._onlistresourcetemplates,X),this._onlistresourcetemplates=X,this.replaceRequestHandler(dQ,async(Y,Z)=>{if(!this._onlistresourcetemplates)throw Error("No onlistresourcetemplates handler set");return this._onlistresourcetemplates(Y.params,Z)})}_onreadresource;get onreadresource(){return this._onreadresource}set onreadresource(X){this.warnIfRequestHandlerReplaced("onreadresource",this._onreadresource,X),this._onreadresource=X,this.replaceRequestHandler(pQ,async(Y,Z)=>{if(!this._onreadresource)throw Error("No onreadresource handler set");return this._onreadresource(Y.params,Z)})}sendResourceListChanged(X={}){return this.notification({method:"notifications/resources/list_changed",params:X})}_onlistprompts;get onlistprompts(){return this._onlistprompts}set onlistprompts(X){this.warnIfRequestHandlerReplaced("onlistprompts",this._onlistprompts,X),this._onlistprompts=X,this.replaceRequestHandler(yQ,async(Y,Z)=>{if(!this._onlistprompts)throw Error("No onlistprompts handler set");return this._onlistprompts(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:lQ.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 J=this._hostContext[$],K=X[$];if(tQ(J,K))continue;Y[$]=K,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},g,Y)}sendResourceTeardown=this.teardownResource;callTool(X,Y){return this.request({method:"tools/call",params:X},t,Y)}listTools(X,Y){return this.request({method:"tools/list",params:X},uQ,Y)}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},t,{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},kQ,{signal:$.signal})},this.onlistresourcetemplates=async(Z,$)=>{return this._client.request({method:"resources/templates/list",params:Z},bQ,{signal:$.signal})},this.onreadresource=async(Z,$)=>{return this._client.request({method:"resources/read",params:Z},nQ,{signal:$.signal})},Y.resources.listChanged)this._client.setNotificationHandler(cQ,(Z)=>this.sendResourceListChanged(Z.params))}if(Y.prompts){if(this.onlistprompts=async(Z,$)=>{return this._client.request({method:"prompts/list",params:Z},vQ,{signal:$.signal})},Y.prompts.listChanged)this._client.setNotificationHandler(iQ,(Z)=>this.sendPromptListChanged(Z.params))}}return super.connect(X)}}function tQ(X,Y){return JSON.stringify(X)===JSON.stringify(Y)}export{cY as isToolVisibilityModelOnly,rY as isToolVisibilityAppOnly,nY as getToolUiResourceUri,lY as buildAllowAttribute,JQ as TOOL_RESULT_METHOD,V as TOOL_INPUT_PARTIAL_METHOD,$Q as TOOL_INPUT_METHOD,KQ as TOOL_CANCELLED_METHOD,lQ as SUPPORTED_PROTOCOL_VERSIONS,ZQ as SIZE_CHANGED_METHOD,YQ as SANDBOX_RESOURCE_READY_METHOD,XQ as SANDBOX_PROXY_READY_METHOD,h as RESOURCE_URI_META_KEY,NQ as RESOURCE_TEARDOWN_METHOD,SQ as RESOURCE_MIME_TYPE,DQ as REQUEST_TEARDOWN_METHOD,zQ as REQUEST_DISPLAY_MODE_METHOD,z as PostMessageTransport,a as OPEN_LINK_METHOD,d as McpUiUpdateModelContextRequestSchema,o as McpUiToolVisibilitySchema,v as McpUiToolResultNotificationSchema,LQ as McpUiToolMetaSchema,U as McpUiToolInputPartialNotificationSchema,R as McpUiToolInputNotificationSchema,H as McpUiToolCancelledNotificationSchema,p as McpUiThemeSchema,I as McpUiSupportedContentBlockModalitiesSchema,w as McpUiSizeChangedNotificationSchema,PQ as McpUiSandboxResourceReadyNotificationSchema,T as McpUiSandboxProxyReadyNotificationSchema,g as McpUiResourceTeardownResultSchema,M as McpUiResourceTeardownRequestSchema,E as McpUiResourcePermissionsSchema,FQ as McpUiResourceMetaSchema,B as McpUiResourceCspSchema,C as McpUiRequestTeardownNotificationSchema,q as McpUiRequestDisplayModeResultSchema,_ as McpUiRequestDisplayModeRequestSchema,F as McpUiOpenLinkResultSchema,A as McpUiOpenLinkRequestSchema,P as McpUiMessageResultSchema,y as McpUiMessageRequestSchema,S as McpUiInitializedNotificationSchema,u as McpUiInitializeResultSchema,b as McpUiInitializeRequestSchema,c as McpUiHostStylesSchema,n as McpUiHostCssSchema,x as McpUiHostContextSchema,k as McpUiHostContextChangedNotificationSchema,r as McpUiHostCapabilitiesSchema,L as McpUiDownloadFileResultSchema,f as McpUiDownloadFileRequestSchema,D as McpUiDisplayModeSchema,l as McpUiAppCapabilitiesSchema,QQ as MESSAGE_METHOD,G as LATEST_PROTOCOL_VERSION,WQ as INITIALIZE_METHOD,jQ as INITIALIZED_METHOD,GQ as HOST_CONTEXT_CHANGED_METHOD,e as DOWNLOAD_FILE_METHOD,oQ as AppBridge};

@@ -39,2 +39,2 @@ import{CallToolRequestSchema as RQ,CallToolResultSchema as UQ,EmptyResultSchema as HQ,ListResourcesResultSchema as MQ,ListToolsRequestSchema as CQ,PingRequestSchema as bQ,ReadResourceResultSchema as kQ}from"@modelcontextprotocol/sdk/types.js";import{Protocol as f}from"@modelcontextprotocol/sdk/shared/protocol.js";class z extends f{_registeredMethods=new Set;_eventSlots=new Map;onEventDispatch(X,Y){}_ensureEventSlot(X){let Y=this._eventSlots.get(X);if(!Y){let Z=this.eventSchemas[X];if(!Z)throw Error(`Unknown event: ${String(X)}`);Y={listeners:[]},this._eventSlots.set(X,Y);let $=Z.shape.method.value;this._registeredMethods.add($);let D=Y;super.setNotificationHandler(Z,(J)=>{let G=J.params;this.onEventDispatch(X,G),D.onHandler?.(G);for(let V of[...D.listeners])V(G)})}return Y}setEventHandler(X,Y){let Z=this._ensureEventSlot(X);if(Z.onHandler&&Y)console.warn(`[MCP Apps] on${String(X)} handler replaced. Use addEventListener("${String(X)}", …) to add multiple listeners without replacing.`);Z.onHandler=Y}getEventHandler(X){return this._eventSlots.get(X)?.onHandler}addEventListener(X,Y){this._ensureEventSlot(X).listeners.push(Y)}removeEventListener(X,Y){let Z=this._eventSlots.get(X);if(!Z)return;let $=Z.listeners.indexOf(Y);if($!==-1)Z.listeners.splice($,1)}setRequestHandler=(X,Y)=>{this._assertMethodNotRegistered(X,"setRequestHandler"),super.setRequestHandler(X,Y)};setNotificationHandler=(X,Y)=>{this._assertMethodNotRegistered(X,"setNotificationHandler"),super.setNotificationHandler(X,Y)};warnIfRequestHandlerReplaced(X,Y,Z){if(Y&&Z)console.warn(`[MCP Apps] ${X} handler replaced. Previous handler will no longer be called.`)}replaceRequestHandler=(X,Y)=>{let Z=X.shape.method.value;this._registeredMethods.add(Z),super.setRequestHandler(X,Y)};_assertMethodNotRegistered(X,Y){let Z=X.shape.method.value;if(this._registeredMethods.has(Z))throw Error(`Handler for "${Z}" already registered (via ${Y}). Use addEventListener() to attach multiple listeners, or the on* setter for replace semantics.`);this._registeredMethods.add(Z)}}import{JSONRPCMessageSchema as QQ}from"@modelcontextprotocol/sdk/types.js";var B="2026-01-26",u="ui/open-link",d="ui/download-file",h="ui/message",i="ui/notifications/sandbox-proxy-ready",m="ui/notifications/sandbox-resource-ready",p="ui/notifications/size-changed",r="ui/notifications/tool-input",E="ui/notifications/tool-input-partial",c="ui/notifications/tool-result",l="ui/notifications/tool-cancelled",n="ui/notifications/host-context-changed",a="ui/notifications/request-teardown",o="ui/resource-teardown",s="ui/initialize",t="ui/notifications/initialized",e="ui/request-display-mode";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 $=QQ.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!==E)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 C,CallToolResultSchema as XQ,EmbeddedResourceSchema as YQ,ImplementationSchema as b,RequestIdSchema as ZQ,ResourceLinkSchema as $Q,ToolSchema as DQ}from"@modelcontextprotocol/sdk/types.js";var k=Q.union([Q.literal("light"),Q.literal("dark")]).describe("Color theme preference for the host environment."),K=Q.union([Q.literal("inline"),Q.literal("fullscreen"),Q.literal("pip")]).describe("Display mode for UI presentation."),JQ=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."),KQ=Q.record(JQ.describe(`Style variables for theming MCP apps.

- "app": Tool callable by the app from this server only`)}),pQ=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.')}),_Q=Q.object({method:Q.literal("ui/download-file"),params:Q.object({contents:Q.array(Q.union([YQ,$Q])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),OQ=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(C).describe("Message content blocks (text, image, etc.).")})}),IQ=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:W.optional().describe("CSP configuration from resource metadata."),permissions:j.optional().describe("Sandbox permissions from resource metadata.")})}),R=Q.object({method:Q.literal("ui/notifications/tool-result"),params:XQ.describe("Standard MCP tool execution result.")}),U=Q.object({toolInfo:Q.object({id:ZQ.optional().describe("JSON-RPC id of the tools/call request."),tool:DQ.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:k.optional().describe("Current color theme preference."),styles:x.optional().describe("Style configuration for theming the app."),displayMode:K.optional().describe("How the UI is currently displayed."),availableDisplayModes:Q.array(K).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
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(),H=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:U.describe("Partial context update containing only changed fields.")}),wQ=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(C).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.")})}),AQ=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:b.describe("App identification (name and version)."),appCapabilities:y.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),M=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:b.describe("Host application identification and version."),hostCapabilities:S.describe("Features and capabilities provided by the host."),hostContext:U.describe("Rich context about the host environment.")}).passthrough();function FQ(){let X=document.documentElement.getAttribute("data-theme");if(X==="dark"||X==="light")return X;return document.documentElement.classList.contains("dark")?"dark":"light"}function PQ(X){let Y=document.documentElement;Y.setAttribute("data-theme",X),Y.style.colorScheme=X}function qQ(X,Y=document.documentElement){for(let[Z,$]of Object.entries(X))if($!==void 0)Y.style.setProperty(Z,$)}function TQ(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",CX="text/html;profile=mcp-app";class gQ extends z{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:A,toolinputpartial:F,toolresult:R,toolcancelled:P,hostcontextchanged:H};onEventDispatch(X,Y){if(X==="hostcontextchanged")this._hostContext={...this._hostContext,...Y}}constructor(X,Y={},Z={autoResize:!0}){super(Z);this._appInfo=X;this._capabilities=Y;this.options=Z;this.setRequestHandler(bQ,($)=>{return console.log("Received ping:",$.params),{}}),this.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(X){this.setEventHandler("toolinput",X)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(X){this.setEventHandler("toolinputpartial",X)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(X){this.setEventHandler("toolresult",X)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(X){this.setEventHandler("toolcancelled",X)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(X){this.setEventHandler("hostcontextchanged",X)}_onteardown;get onteardown(){return this._onteardown}set onteardown(X){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,X),this._onteardown=X,this.replaceRequestHandler(q,(Y,Z)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(Y.params,Z)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(X){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,X),this._oncalltool=X,this.replaceRequestHandler(RQ,(Y,Z)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Y.params,Z)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(X){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,X),this._onlisttools=X,this.replaceRequestHandler(CQ,(Y,Z)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(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},kQ,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},w,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},O,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this.request({method:"ui/download-file",params:X},I,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},T,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,G=J.style.height;J.style.height="max-content";let V=Math.ceil(J.getBoundingClientRect().height);J.style.height=G;let L=Math.ceil(window.innerWidth);if(L!==Y||V!==Z)Y=L,Z=V,this.sendSizeChanged({width:L,height:V})})};$();let D=new ResizeObserver($);return D.observe(document.documentElement),D.observe(document.body),()=>D.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:B}},M,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{FQ as getDocumentTheme,qQ as applyHostStyleVariables,TQ as applyHostFonts,PQ as applyDocumentTheme,c as TOOL_RESULT_METHOD,E as TOOL_INPUT_PARTIAL_METHOD,r as TOOL_INPUT_METHOD,l as TOOL_CANCELLED_METHOD,p as SIZE_CHANGED_METHOD,m as SANDBOX_RESOURCE_READY_METHOD,i as SANDBOX_PROXY_READY_METHOD,MX as RESOURCE_URI_META_KEY,o as RESOURCE_TEARDOWN_METHOD,CX as RESOURCE_MIME_TYPE,a as REQUEST_TEARDOWN_METHOD,e as REQUEST_DISPLAY_MODE_METHOD,z as ProtocolWithEvents,N as PostMessageTransport,u as OPEN_LINK_METHOD,wQ as McpUiUpdateModelContextRequestSchema,v as McpUiToolVisibilitySchema,R as McpUiToolResultNotificationSchema,EQ as McpUiToolMetaSchema,F as McpUiToolInputPartialNotificationSchema,A as McpUiToolInputNotificationSchema,P as McpUiToolCancelledNotificationSchema,k as McpUiThemeSchema,_ as McpUiSupportedContentBlockModalitiesSchema,NQ as McpUiSizeChangedNotificationSchema,IQ as McpUiSandboxResourceReadyNotificationSchema,VQ as McpUiSandboxProxyReadyNotificationSchema,WQ as McpUiResourceTeardownResultSchema,q as McpUiResourceTeardownRequestSchema,j as McpUiResourcePermissionsSchema,zQ as McpUiResourceMetaSchema,W as McpUiResourceCspSchema,jQ as McpUiRequestTeardownNotificationSchema,T as McpUiRequestDisplayModeResultSchema,BQ as McpUiRequestDisplayModeRequestSchema,O as McpUiOpenLinkResultSchema,GQ as McpUiOpenLinkRequestSchema,w as McpUiMessageResultSchema,OQ as McpUiMessageRequestSchema,LQ as McpUiInitializedNotificationSchema,M as McpUiInitializeResultSchema,AQ as McpUiInitializeRequestSchema,x as McpUiHostStylesSchema,g as McpUiHostCssSchema,U as McpUiHostContextSchema,H as McpUiHostContextChangedNotificationSchema,S as McpUiHostCapabilitiesSchema,I as McpUiDownloadFileResultSchema,_Q as McpUiDownloadFileRequestSchema,K as McpUiDisplayModeSchema,y as McpUiAppCapabilitiesSchema,h as MESSAGE_METHOD,B as LATEST_PROTOCOL_VERSION,s as INITIALIZE_METHOD,t as INITIALIZED_METHOD,n as HOST_CONTEXT_CHANGED_METHOD,d as DOWNLOAD_FILE_METHOD,gQ as App};
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(),H=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:U.describe("Partial context update containing only changed fields.")}),wQ=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(C).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.")})}),AQ=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:b.describe("App identification (name and version)."),appCapabilities:y.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),M=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:b.describe("Host application identification and version."),hostCapabilities:S.describe("Features and capabilities provided by the host."),hostContext:U.describe("Rich context about the host environment.")}).passthrough();function FQ(){let X=document.documentElement.getAttribute("data-theme");if(X==="dark"||X==="light")return X;return document.documentElement.classList.contains("dark")?"dark":"light"}function PQ(X){let Y=document.documentElement;Y.setAttribute("data-theme",X),Y.style.colorScheme=X}function qQ(X,Y=document.documentElement){for(let[Z,$]of Object.entries(X))if($!==void 0)Y.style.setProperty(Z,$)}function TQ(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",CX="text/html;profile=mcp-app";class gQ extends z{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:A,toolinputpartial:F,toolresult:R,toolcancelled:P,hostcontextchanged:H};onEventDispatch(X,Y){if(X==="hostcontextchanged")this._hostContext={...this._hostContext,...Y}}constructor(X,Y={},Z={autoResize:!0}){super(Z);this._appInfo=X;this._capabilities=Y;this.options=Z;this.setRequestHandler(bQ,($)=>{return console.log("Received ping:",$.params),{}}),this.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(X){this.setEventHandler("toolinput",X)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(X){this.setEventHandler("toolinputpartial",X)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(X){this.setEventHandler("toolresult",X)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(X){this.setEventHandler("toolcancelled",X)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(X){this.setEventHandler("hostcontextchanged",X)}_onteardown;get onteardown(){return this._onteardown}set onteardown(X){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,X),this._onteardown=X,this.replaceRequestHandler(q,(Y,Z)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(Y.params,Z)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(X){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,X),this._oncalltool=X,this.replaceRequestHandler(RQ,(Y,Z)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Y.params,Z)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(X){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,X),this._onlisttools=X,this.replaceRequestHandler(CQ,(Y,Z)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(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,{onprogress:()=>{},resetTimeoutOnProgress:!0,...Y})}async readServerResource(X,Y){return await this.request({method:"resources/read",params:X},kQ,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},w,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},O,Y)}sendOpenLink=this.openLink;downloadFile(X,Y){return this.request({method:"ui/download-file",params:X},I,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},T,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,G=J.style.height;J.style.height="max-content";let V=Math.ceil(J.getBoundingClientRect().height);J.style.height=G;let L=Math.ceil(window.innerWidth);if(L!==Y||V!==Z)Y=L,Z=V,this.sendSizeChanged({width:L,height:V})})};$();let D=new ResizeObserver($);return D.observe(document.documentElement),D.observe(document.body),()=>D.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:B}},M,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{FQ as getDocumentTheme,qQ as applyHostStyleVariables,TQ as applyHostFonts,PQ as applyDocumentTheme,c as TOOL_RESULT_METHOD,E as TOOL_INPUT_PARTIAL_METHOD,r as TOOL_INPUT_METHOD,l as TOOL_CANCELLED_METHOD,p as SIZE_CHANGED_METHOD,m as SANDBOX_RESOURCE_READY_METHOD,i as SANDBOX_PROXY_READY_METHOD,MX as RESOURCE_URI_META_KEY,o as RESOURCE_TEARDOWN_METHOD,CX as RESOURCE_MIME_TYPE,a as REQUEST_TEARDOWN_METHOD,e as REQUEST_DISPLAY_MODE_METHOD,z as ProtocolWithEvents,N as PostMessageTransport,u as OPEN_LINK_METHOD,wQ as McpUiUpdateModelContextRequestSchema,v as McpUiToolVisibilitySchema,R as McpUiToolResultNotificationSchema,EQ as McpUiToolMetaSchema,F as McpUiToolInputPartialNotificationSchema,A as McpUiToolInputNotificationSchema,P as McpUiToolCancelledNotificationSchema,k as McpUiThemeSchema,_ as McpUiSupportedContentBlockModalitiesSchema,NQ as McpUiSizeChangedNotificationSchema,IQ as McpUiSandboxResourceReadyNotificationSchema,VQ as McpUiSandboxProxyReadyNotificationSchema,WQ as McpUiResourceTeardownResultSchema,q as McpUiResourceTeardownRequestSchema,j as McpUiResourcePermissionsSchema,zQ as McpUiResourceMetaSchema,W as McpUiResourceCspSchema,jQ as McpUiRequestTeardownNotificationSchema,T as McpUiRequestDisplayModeResultSchema,BQ as McpUiRequestDisplayModeRequestSchema,O as McpUiOpenLinkResultSchema,GQ as McpUiOpenLinkRequestSchema,w as McpUiMessageResultSchema,OQ as McpUiMessageRequestSchema,LQ as McpUiInitializedNotificationSchema,M as McpUiInitializeResultSchema,AQ as McpUiInitializeRequestSchema,x as McpUiHostStylesSchema,g as McpUiHostCssSchema,U as McpUiHostContextSchema,H as McpUiHostContextChangedNotificationSchema,S as McpUiHostCapabilitiesSchema,I as McpUiDownloadFileResultSchema,_Q as McpUiDownloadFileRequestSchema,K as McpUiDisplayModeSchema,y as McpUiAppCapabilitiesSchema,h as MESSAGE_METHOD,B as LATEST_PROTOCOL_VERSION,s as INITIALIZE_METHOD,t as INITIALIZED_METHOD,n as HOST_CONTEXT_CHANGED_METHOD,d as DOWNLOAD_FILE_METHOD,gQ as App};

@@ -39,2 +39,2 @@ import{useEffect as hJ,useState as d}from"react";import{CallToolRequestSchema as gJ,CallToolResultSchema as vJ,EmptyResultSchema as xJ,ListResourcesResultSchema as yJ,ListToolsRequestSchema as fJ,PingRequestSchema as dJ,ReadResourceResultSchema as uJ}from"@modelcontextprotocol/sdk/types.js";import{Protocol as a}from"@modelcontextprotocol/sdk/shared/protocol.js";class R extends a{_registeredMethods=new Set;_eventSlots=new Map;onEventDispatch(K,Q){}_ensureEventSlot(K){let Q=this._eventSlots.get(K);if(!Q){let X=this.eventSchemas[K];if(!X)throw Error(`Unknown event: ${String(K)}`);Q={listeners:[]},this._eventSlots.set(K,Q);let Y=X.shape.method.value;this._registeredMethods.add(Y);let Z=Q;super.setNotificationHandler(X,($)=>{let G=$.params;this.onEventDispatch(K,G),Z.onHandler?.(G);for(let j of[...Z.listeners])j(G)})}return Q}setEventHandler(K,Q){let X=this._ensureEventSlot(K);if(X.onHandler&&Q)console.warn(`[MCP Apps] on${String(K)} handler replaced. Use addEventListener("${String(K)}", …) to add multiple listeners without replacing.`);X.onHandler=Q}getEventHandler(K){return this._eventSlots.get(K)?.onHandler}addEventListener(K,Q){this._ensureEventSlot(K).listeners.push(Q)}removeEventListener(K,Q){let X=this._eventSlots.get(K);if(!X)return;let Y=X.listeners.indexOf(Q);if(Y!==-1)X.listeners.splice(Y,1)}setRequestHandler=(K,Q)=>{this._assertMethodNotRegistered(K,"setRequestHandler"),super.setRequestHandler(K,Q)};setNotificationHandler=(K,Q)=>{this._assertMethodNotRegistered(K,"setNotificationHandler"),super.setNotificationHandler(K,Q)};warnIfRequestHandlerReplaced(K,Q,X){if(Q&&X)console.warn(`[MCP Apps] ${K} handler replaced. Previous handler will no longer be called.`)}replaceRequestHandler=(K,Q)=>{let X=K.shape.method.value;this._registeredMethods.add(X),super.setRequestHandler(K,Q)};_assertMethodNotRegistered(K,Q){let X=K.shape.method.value;if(this._registeredMethods.has(X))throw Error(`Handler for "${X}" already registered (via ${Q}). Use addEventListener() to attach multiple listeners, or the on* setter for replace semantics.`);this._registeredMethods.add(X)}}import{JSONRPCMessageSchema as BJ}from"@modelcontextprotocol/sdk/types.js";var z="2026-01-26",s="ui/open-link",t="ui/download-file",e="ui/message",JJ="ui/notifications/sandbox-proxy-ready",KJ="ui/notifications/sandbox-resource-ready",QJ="ui/notifications/size-changed",XJ="ui/notifications/tool-input",U="ui/notifications/tool-input-partial",YJ="ui/notifications/tool-result",ZJ="ui/notifications/tool-cancelled",$J="ui/notifications/host-context-changed",GJ="ui/notifications/request-teardown",jJ="ui/resource-teardown",WJ="ui/initialize",LJ="ui/notifications/initialized",NJ="ui/request-display-mode";class L{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=BJ.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 VJ,EmbeddedResourceSchema as _J,ImplementationSchema as h,RequestIdSchema as OJ,ResourceLinkSchema as PJ,ToolSchema as qJ}from"@modelcontextprotocol/sdk/types.js";var m=J.union([J.literal("light"),J.literal("dark")]).describe("Color theme preference for the host environment."),N=J.union([J.literal("inline"),J.literal("fullscreen"),J.literal("pip")]).describe("Display mode for UI presentation."),DJ=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."),IJ=J.record(DJ.describe(`Style variables for theming MCP apps.

- "app": Tool callable by the app from this server only`)}),XK=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.')}),AJ=J.object({method:J.literal("ui/download-file"),params:J.object({contents:J.array(J.union([_J,PJ])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),kJ=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.).")})}),bJ=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:V.optional().describe("CSP configuration from resource metadata."),permissions:_.optional().describe("Sandbox permissions from resource metadata.")})}),g=J.object({method:J.literal("ui/notifications/tool-result"),params:VJ.describe("Standard MCP tool execution result.")}),v=J.object({toolInfo:J.object({id:OJ.optional().describe("JSON-RPC id of the tools/call request."),tool:qJ.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:N.optional().describe("How the UI is currently displayed."),availableDisplayModes:J.array(N).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
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:v.describe("Partial context update containing only changed fields.")}),SJ=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.")})}),CJ=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:v.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 P(K){let Q=document.documentElement;Q.setAttribute("data-theme",K),Q.style.colorScheme=K}function q(K,Q=document.documentElement){for(let[X,Y]of Object.entries(K))if(Y!==void 0)Q.style.setProperty(X,Y)}function D(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 mK="ui/resourceUri",cK="text/html;profile=mcp-app";class f extends R{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:A,toolinputpartial:k,toolresult:g,toolcancelled:b,hostcontextchanged:x};onEventDispatch(K,Q){if(K==="hostcontextchanged")this._hostContext={...this._hostContext,...Q}}constructor(K,Q={},X={autoResize:!0}){super(X);this._appInfo=K;this._capabilities=Q;this.options=X;this.setRequestHandler(dJ,(Y)=>{return console.log("Received ping:",Y.params),{}}),this.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(K){this.setEventHandler("toolinput",K)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(K){this.setEventHandler("toolinputpartial",K)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(K){this.setEventHandler("toolresult",K)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(K){this.setEventHandler("toolcancelled",K)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(K){this.setEventHandler("hostcontextchanged",K)}_onteardown;get onteardown(){return this._onteardown}set onteardown(K){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,K),this._onteardown=K,this.replaceRequestHandler(S,(Q,X)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(Q.params,X)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(K){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,K),this._oncalltool=K,this.replaceRequestHandler(gJ,(Q,X)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Q.params,X)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(K){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,K),this._onlisttools=K,this.replaceRequestHandler(fJ,(Q,X)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(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},vJ,Q)}async readServerResource(K,Q){return await this.request({method:"resources/read",params:K},uJ,Q)}async listServerResources(K,Q){return await this.request({method:"resources/list",params:K},yJ,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},xJ,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},C,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 $=document.documentElement,G=$.style.height;$.style.height="max-content";let j=Math.ceil($.getBoundingClientRect().height);$.style.height=G;let W=Math.ceil(window.innerWidth);if(W!==Q||j!==X)Q=W,X=j,this.sendSizeChanged({width:W,height:j})})};Y();let Z=new ResizeObserver(Y);return Z.observe(document.documentElement),Z.observe(document.body),()=>Z.disconnect()}async connect(K=new L(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 sK({appInfo:K,capabilities:Q,onAppCreated:X}){let[Y,Z]=d(null),[$,G]=d(!1),[j,W]=d(null);return hJ(()=>{let F=!0;async function o(){try{let B=new L(window.parent,window.parent),E=new f(K,Q);if(X?.(E),await E.connect(B),F)Z(E),G(!0),W(null)}catch(B){if(F)Z(null),G(!1),W(B instanceof Error?B:Error("Failed to connect"))}}return o(),()=>{F=!1}},[]),{app:Y,isConnected:$,error:j}}import{useEffect as mJ}from"react";function QQ(K,Q){mJ(()=>{if(!K)return;return K.setupSizeChangedNotifications()},[K,Q])}import{useEffect as cJ,useState as rJ}from"react";function $Q(){let[K,Q]=rJ(O);return cJ(()=>{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 I,useRef as n}from"react";function lJ(K,Q){let X=n(!1);I(()=>{if(X.current)return;if(Q?.theme)P(Q.theme);if(Q?.styles?.variables)q(Q.styles.variables);if(Q?.theme||Q?.styles?.variables)X.current=!0},[Q]),I(()=>{if(!K)return;let Y=(Z)=>{if(Z.theme)P(Z.theme);if(Z.styles?.variables)q(Z.styles.variables)};return K.addEventListener("hostcontextchanged",Y),()=>K.removeEventListener("hostcontextchanged",Y)},[K])}function iJ(K,Q){let X=n(!1);I(()=>{if(X.current)return;if(Q?.styles?.css?.fonts)D(Q.styles.css.fonts),X.current=!0},[Q]),I(()=>{if(!K)return;let Y=(Z)=>{if(Z.styles?.css?.fonts)D(Z.styles.css.fonts)};return K.addEventListener("hostcontextchanged",Y),()=>K.removeEventListener("hostcontextchanged",Y)},[K])}function LQ(K,Q){lJ(K,Q),iJ(K,Q)}export{LQ as useHostStyles,lJ as useHostStyleVariables,iJ as useHostFonts,$Q as useDocumentTheme,QQ as useAutoResize,sK as useApp,O as getDocumentTheme,q as applyHostStyleVariables,D as applyHostFonts,P as applyDocumentTheme,YJ as TOOL_RESULT_METHOD,U as TOOL_INPUT_PARTIAL_METHOD,XJ as TOOL_INPUT_METHOD,ZJ as TOOL_CANCELLED_METHOD,QJ as SIZE_CHANGED_METHOD,KJ as SANDBOX_RESOURCE_READY_METHOD,JJ as SANDBOX_PROXY_READY_METHOD,mK as RESOURCE_URI_META_KEY,jJ as RESOURCE_TEARDOWN_METHOD,cK as RESOURCE_MIME_TYPE,GJ as REQUEST_TEARDOWN_METHOD,NJ as REQUEST_DISPLAY_MODE_METHOD,R as ProtocolWithEvents,L as PostMessageTransport,s as OPEN_LINK_METHOD,SJ as McpUiUpdateModelContextRequestSchema,p as McpUiToolVisibilitySchema,g as McpUiToolResultNotificationSchema,HJ as McpUiToolMetaSchema,k as McpUiToolInputPartialNotificationSchema,A as McpUiToolInputNotificationSchema,b as McpUiToolCancelledNotificationSchema,m as McpUiThemeSchema,w as McpUiSupportedContentBlockModalitiesSchema,RJ as McpUiSizeChangedNotificationSchema,bJ as McpUiSandboxResourceReadyNotificationSchema,EJ as McpUiSandboxProxyReadyNotificationSchema,zJ as McpUiResourceTeardownResultSchema,S as McpUiResourceTeardownRequestSchema,_ as McpUiResourcePermissionsSchema,MJ as McpUiResourceMetaSchema,V as McpUiResourceCspSchema,UJ as McpUiRequestTeardownNotificationSchema,C as McpUiRequestDisplayModeResultSchema,TJ as McpUiRequestDisplayModeRequestSchema,M as McpUiOpenLinkResultSchema,FJ as McpUiOpenLinkRequestSchema,H as McpUiMessageResultSchema,kJ as McpUiMessageRequestSchema,wJ as McpUiInitializedNotificationSchema,y as McpUiInitializeResultSchema,CJ as McpUiInitializeRequestSchema,r as McpUiHostStylesSchema,c as McpUiHostCssSchema,v as McpUiHostContextSchema,x as McpUiHostContextChangedNotificationSchema,l as McpUiHostCapabilitiesSchema,T as McpUiDownloadFileResultSchema,AJ as McpUiDownloadFileRequestSchema,N as McpUiDisplayModeSchema,i as McpUiAppCapabilitiesSchema,e as MESSAGE_METHOD,z as LATEST_PROTOCOL_VERSION,WJ as INITIALIZE_METHOD,LJ as INITIALIZED_METHOD,$J as HOST_CONTEXT_CHANGED_METHOD,t as DOWNLOAD_FILE_METHOD,f as App};
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:v.describe("Partial context update containing only changed fields.")}),SJ=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.")})}),CJ=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:v.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 P(K){let Q=document.documentElement;Q.setAttribute("data-theme",K),Q.style.colorScheme=K}function q(K,Q=document.documentElement){for(let[X,Y]of Object.entries(K))if(Y!==void 0)Q.style.setProperty(X,Y)}function D(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 mK="ui/resourceUri",cK="text/html;profile=mcp-app";class f extends R{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:A,toolinputpartial:k,toolresult:g,toolcancelled:b,hostcontextchanged:x};onEventDispatch(K,Q){if(K==="hostcontextchanged")this._hostContext={...this._hostContext,...Q}}constructor(K,Q={},X={autoResize:!0}){super(X);this._appInfo=K;this._capabilities=Q;this.options=X;this.setRequestHandler(dJ,(Y)=>{return console.log("Received ping:",Y.params),{}}),this.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(K){this.setEventHandler("toolinput",K)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(K){this.setEventHandler("toolinputpartial",K)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(K){this.setEventHandler("toolresult",K)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(K){this.setEventHandler("toolcancelled",K)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(K){this.setEventHandler("hostcontextchanged",K)}_onteardown;get onteardown(){return this._onteardown}set onteardown(K){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,K),this._onteardown=K,this.replaceRequestHandler(S,(Q,X)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown(Q.params,X)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(K){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,K),this._oncalltool=K,this.replaceRequestHandler(gJ,(Q,X)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool(Q.params,X)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(K){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,K),this._onlisttools=K,this.replaceRequestHandler(fJ,(Q,X)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools(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},vJ,{onprogress:()=>{},resetTimeoutOnProgress:!0,...Q})}async readServerResource(K,Q){return await this.request({method:"resources/read",params:K},uJ,Q)}async listServerResources(K,Q){return await this.request({method:"resources/list",params:K},yJ,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},xJ,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},C,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 $=document.documentElement,G=$.style.height;$.style.height="max-content";let j=Math.ceil($.getBoundingClientRect().height);$.style.height=G;let W=Math.ceil(window.innerWidth);if(W!==Q||j!==X)Q=W,X=j,this.sendSizeChanged({width:W,height:j})})};Y();let Z=new ResizeObserver(Y);return Z.observe(document.documentElement),Z.observe(document.body),()=>Z.disconnect()}async connect(K=new L(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 sK({appInfo:K,capabilities:Q,onAppCreated:X}){let[Y,Z]=d(null),[$,G]=d(!1),[j,W]=d(null);return hJ(()=>{let F=!0;async function o(){try{let B=new L(window.parent,window.parent),E=new f(K,Q);if(X?.(E),await E.connect(B),F)Z(E),G(!0),W(null)}catch(B){if(F)Z(null),G(!1),W(B instanceof Error?B:Error("Failed to connect"))}}return o(),()=>{F=!1}},[]),{app:Y,isConnected:$,error:j}}import{useEffect as mJ}from"react";function QQ(K,Q){mJ(()=>{if(!K)return;return K.setupSizeChangedNotifications()},[K,Q])}import{useEffect as cJ,useState as rJ}from"react";function $Q(){let[K,Q]=rJ(O);return cJ(()=>{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 I,useRef as n}from"react";function lJ(K,Q){let X=n(!1);I(()=>{if(X.current)return;if(Q?.theme)P(Q.theme);if(Q?.styles?.variables)q(Q.styles.variables);if(Q?.theme||Q?.styles?.variables)X.current=!0},[Q]),I(()=>{if(!K)return;let Y=(Z)=>{if(Z.theme)P(Z.theme);if(Z.styles?.variables)q(Z.styles.variables)};return K.addEventListener("hostcontextchanged",Y),()=>K.removeEventListener("hostcontextchanged",Y)},[K])}function iJ(K,Q){let X=n(!1);I(()=>{if(X.current)return;if(Q?.styles?.css?.fonts)D(Q.styles.css.fonts),X.current=!0},[Q]),I(()=>{if(!K)return;let Y=(Z)=>{if(Z.styles?.css?.fonts)D(Z.styles.css.fonts)};return K.addEventListener("hostcontextchanged",Y),()=>K.removeEventListener("hostcontextchanged",Y)},[K])}function LQ(K,Q){lJ(K,Q),iJ(K,Q)}export{LQ as useHostStyles,lJ as useHostStyleVariables,iJ as useHostFonts,$Q as useDocumentTheme,QQ as useAutoResize,sK as useApp,O as getDocumentTheme,q as applyHostStyleVariables,D as applyHostFonts,P as applyDocumentTheme,YJ as TOOL_RESULT_METHOD,U as TOOL_INPUT_PARTIAL_METHOD,XJ as TOOL_INPUT_METHOD,ZJ as TOOL_CANCELLED_METHOD,QJ as SIZE_CHANGED_METHOD,KJ as SANDBOX_RESOURCE_READY_METHOD,JJ as SANDBOX_PROXY_READY_METHOD,mK as RESOURCE_URI_META_KEY,jJ as RESOURCE_TEARDOWN_METHOD,cK as RESOURCE_MIME_TYPE,GJ as REQUEST_TEARDOWN_METHOD,NJ as REQUEST_DISPLAY_MODE_METHOD,R as ProtocolWithEvents,L as PostMessageTransport,s as OPEN_LINK_METHOD,SJ as McpUiUpdateModelContextRequestSchema,p as McpUiToolVisibilitySchema,g as McpUiToolResultNotificationSchema,HJ as McpUiToolMetaSchema,k as McpUiToolInputPartialNotificationSchema,A as McpUiToolInputNotificationSchema,b as McpUiToolCancelledNotificationSchema,m as McpUiThemeSchema,w as McpUiSupportedContentBlockModalitiesSchema,RJ as McpUiSizeChangedNotificationSchema,bJ as McpUiSandboxResourceReadyNotificationSchema,EJ as McpUiSandboxProxyReadyNotificationSchema,zJ as McpUiResourceTeardownResultSchema,S as McpUiResourceTeardownRequestSchema,_ as McpUiResourcePermissionsSchema,MJ as McpUiResourceMetaSchema,V as McpUiResourceCspSchema,UJ as McpUiRequestTeardownNotificationSchema,C as McpUiRequestDisplayModeResultSchema,TJ as McpUiRequestDisplayModeRequestSchema,M as McpUiOpenLinkResultSchema,FJ as McpUiOpenLinkRequestSchema,H as McpUiMessageResultSchema,kJ as McpUiMessageRequestSchema,wJ as McpUiInitializedNotificationSchema,y as McpUiInitializeResultSchema,CJ as McpUiInitializeRequestSchema,r as McpUiHostStylesSchema,c as McpUiHostCssSchema,v as McpUiHostContextSchema,x as McpUiHostContextChangedNotificationSchema,l as McpUiHostCapabilitiesSchema,T as McpUiDownloadFileResultSchema,AJ as McpUiDownloadFileRequestSchema,N as McpUiDisplayModeSchema,i as McpUiAppCapabilitiesSchema,e as MESSAGE_METHOD,z as LATEST_PROTOCOL_VERSION,WJ as INITIALIZE_METHOD,LJ as INITIALIZED_METHOD,$J as HOST_CONTEXT_CHANGED_METHOD,t as DOWNLOAD_FILE_METHOD,f as App};

@@ -39,2 +39,2 @@ import{CallToolRequestSchema as WQ,CallToolResultSchema as BQ,EmptyResultSchema as KQ,ListResourcesResultSchema as NQ,ListToolsRequestSchema as YQ,PingRequestSchema as jQ,ReadResourceResultSchema as FQ}from"@modelcontextprotocol/sdk/types.js";import{Protocol as d}from"@modelcontextprotocol/sdk/shared/protocol.js";class j extends d{_registeredMethods=new Set;_eventSlots=new Map;onEventDispatch(Z,$){}_ensureEventSlot(Z){let $=this._eventSlots.get(Z);if(!$){let J=this.eventSchemas[Z];if(!J)throw Error(`Unknown event: ${String(Z)}`);$={listeners:[]},this._eventSlots.set(Z,$);let X=J.shape.method.value;this._registeredMethods.add(X);let V=$;super.setNotificationHandler(J,(D)=>{let G=D.params;this.onEventDispatch(Z,G),V.onHandler?.(G);for(let L of[...V.listeners])L(G)})}return $}setEventHandler(Z,$){let J=this._ensureEventSlot(Z);if(J.onHandler&&$)console.warn(`[MCP Apps] on${String(Z)} handler replaced. Use addEventListener("${String(Z)}", …) to add multiple listeners without replacing.`);J.onHandler=$}getEventHandler(Z){return this._eventSlots.get(Z)?.onHandler}addEventListener(Z,$){this._ensureEventSlot(Z).listeners.push($)}removeEventListener(Z,$){let J=this._eventSlots.get(Z);if(!J)return;let X=J.listeners.indexOf($);if(X!==-1)J.listeners.splice(X,1)}setRequestHandler=(Z,$)=>{this._assertMethodNotRegistered(Z,"setRequestHandler"),super.setRequestHandler(Z,$)};setNotificationHandler=(Z,$)=>{this._assertMethodNotRegistered(Z,"setNotificationHandler"),super.setNotificationHandler(Z,$)};warnIfRequestHandlerReplaced(Z,$,J){if($&&J)console.warn(`[MCP Apps] ${Z} handler replaced. Previous handler will no longer be called.`)}replaceRequestHandler=(Z,$)=>{let J=Z.shape.method.value;this._registeredMethods.add(J),super.setRequestHandler(Z,$)};_assertMethodNotRegistered(Z,$){let J=Z.shape.method.value;if(this._registeredMethods.has(J))throw Error(`Handler for "${J}" already registered (via ${$}). Use addEventListener() to attach multiple listeners, or the on* setter for replace semantics.`);this._registeredMethods.add(J)}}import{JSONRPCMessageSchema as h}from"@modelcontextprotocol/sdk/types.js";var F="2026-01-26";var z="ui/notifications/tool-input-partial";class B{eventTarget;eventSource;messageListener;constructor(Z=window.parent,$){this.eventTarget=Z;this.eventSource=$;this.messageListener=(J)=>{if($&&J.source!==this.eventSource){console.debug("Ignoring message from unknown source",J);return}let X=h.safeParse(J.data);if(X.success)console.debug("Parsed message",X.data),this.onmessage?.(X.data);else if(J.data?.jsonrpc!=="2.0")console.debug("Ignoring non-JSON-RPC message",X.error.message,J);else console.error("Failed to parse message",X.error.message,J),this.onerror?.(Error("Invalid JSON-RPC message received: "+X.error.message))}}async start(){window.addEventListener("message",this.messageListener)}async send(Z,$){if(Z.method!==z)console.debug("Sending message",Z);this.eventTarget.postMessage(Z,"*")}async close(){window.removeEventListener("message",this.messageListener),this.onclose?.()}onclose;onerror;onmessage;sessionId;setProtocolVersion}import{z as Q}from"zod/v4";import{ContentBlockSchema as x,CallToolResultSchema as m,EmbeddedResourceSchema as p,ImplementationSchema as g,RequestIdSchema as c,ResourceLinkSchema as l,ToolSchema as r}from"@modelcontextprotocol/sdk/types.js";var S=Q.union([Q.literal("light"),Q.literal("dark")]).describe("Color theme preference for the host environment."),W=Q.union([Q.literal("inline"),Q.literal("fullscreen"),Q.literal("pip")]).describe("Display mode for UI presentation."),i=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."),n=Q.record(i.describe(`Style variables for theming MCP apps.

- "app": Tool callable by the app from this server only`)}),UQ=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.')}),XQ=Q.object({method:Q.literal("ui/download-file"),params:Q.object({contents:Q.array(Q.union([p,l])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),VQ=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(x).describe("Message content blocks (text, image, etc.).")})}),DQ=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:K.optional().describe("CSP configuration from resource metadata."),permissions:N.optional().describe("Sandbox permissions from resource metadata.")})}),R=Q.object({method:Q.literal("ui/notifications/tool-result"),params:m.describe("Standard MCP tool execution result.")}),E=Q.object({toolInfo:Q.object({id:c.optional().describe("JSON-RPC id of the tools/call request."),tool:r.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:S.optional().describe("Current color theme preference."),styles:C.optional().describe("Style configuration for theming the app."),displayMode:W.optional().describe("How the UI is currently displayed."),availableDisplayModes:Q.array(W).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
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(),U=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:E.describe("Partial context update containing only changed fields.")}),GQ=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(x).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.")})}),LQ=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:g.describe("App identification (name and version)."),appCapabilities:v.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),k=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:g.describe("Host application identification and version."),hostCapabilities:y.describe("Features and capabilities provided by the host."),hostContext:E.describe("Rich context about the host environment.")}).passthrough();var M="ui/resourceUri",u="text/html;profile=mcp-app";class zQ extends j{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:A,toolinputpartial:P,toolresult:R,toolcancelled:H,hostcontextchanged:U};onEventDispatch(Z,$){if(Z==="hostcontextchanged")this._hostContext={...this._hostContext,...$}}constructor(Z,$={},J={autoResize:!0}){super(J);this._appInfo=Z;this._capabilities=$;this.options=J;this.setRequestHandler(jQ,(X)=>{return console.log("Received ping:",X.params),{}}),this.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(Z){this.setEventHandler("toolinput",Z)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(Z){this.setEventHandler("toolinputpartial",Z)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(Z){this.setEventHandler("toolresult",Z)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(Z){this.setEventHandler("toolcancelled",Z)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(Z){this.setEventHandler("hostcontextchanged",Z)}_onteardown;get onteardown(){return this._onteardown}set onteardown(Z){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,Z),this._onteardown=Z,this.replaceRequestHandler(_,($,J)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown($.params,J)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(Z){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,Z),this._oncalltool=Z,this.replaceRequestHandler(WQ,($,J)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool($.params,J)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(Z){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,Z),this._onlisttools=Z,this.replaceRequestHandler(YQ,($,J)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools($.params,J)})}assertCapabilityForMethod(Z){}assertRequestHandlerCapability(Z){switch(Z){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${Z})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${Z} registered`)}}assertNotificationCapability(Z){}assertTaskCapability(Z){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(Z){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(Z,$){if(typeof Z==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${Z}"). Did you mean: callServerTool({ name: "${Z}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:Z},BQ,$)}async readServerResource(Z,$){return await this.request({method:"resources/read",params:Z},FQ,$)}async listServerResources(Z,$){return await this.request({method:"resources/list",params:Z},NQ,$)}sendMessage(Z,$){return this.request({method:"ui/message",params:Z},w,$)}sendLog(Z){return this.notification({method:"notifications/message",params:Z})}updateModelContext(Z,$){return this.request({method:"ui/update-model-context",params:Z},KQ,$)}openLink(Z,$){return this.request({method:"ui/open-link",params:Z},O,$)}sendOpenLink=this.openLink;downloadFile(Z,$){return this.request({method:"ui/download-file",params:Z},I,$)}requestTeardown(Z={}){return this.notification({method:"ui/notifications/request-teardown",params:Z})}requestDisplayMode(Z,$){return this.request({method:"ui/request-display-mode",params:Z},T,$)}sendSizeChanged(Z){return this.notification({method:"ui/notifications/size-changed",params:Z})}setupSizeChangedNotifications(){let Z=!1,$=0,J=0,X=()=>{if(Z)return;Z=!0,requestAnimationFrame(()=>{Z=!1;let D=document.documentElement,G=D.style.height;D.style.height="max-content";let L=Math.ceil(D.getBoundingClientRect().height);D.style.height=G;let Y=Math.ceil(window.innerWidth);if(Y!==$||L!==J)$=Y,J=L,this.sendSizeChanged({width:Y,height:L})})};X();let V=new ResizeObserver(X);return V.observe(document.documentElement),V.observe(document.body),()=>V.disconnect()}async connect(Z=new B(window.parent,window.parent),$){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(Z);try{let J=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:F}},k,$);if(J===void 0)throw Error(`Server sent invalid initialize result: ${J}`);if(this._hostCapabilities=J.hostCapabilities,this._hostInfo=J.hostInfo,this._hostContext=J.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(J){throw this.close(),J}}}function hZ(Z,$,J,X){let V=J._meta,D=V.ui,G=V[M],L=V;if(D?.resourceUri&&!G)L={...V,[M]:D.resourceUri};else if(G&&!D?.resourceUri)L={...V,ui:{...D,resourceUri:G}};return Z.registerTool($,{...J,_meta:L},X)}function mZ(Z,$,J,X,V){return Z.registerResource($,J,{mimeType:u,...X},V)}var qQ="io.modelcontextprotocol/ui";function pZ(Z){if(!Z)return;return Z.extensions?.[qQ]}export{hZ as registerAppTool,mZ as registerAppResource,pZ as getUiCapability,M as RESOURCE_URI_META_KEY,u as RESOURCE_MIME_TYPE,qQ as EXTENSION_ID};
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(),U=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:E.describe("Partial context update containing only changed fields.")}),GQ=Q.object({method:Q.literal("ui/update-model-context"),params:Q.object({content:Q.array(x).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.")})}),LQ=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:g.describe("App identification (name and version)."),appCapabilities:v.describe("Features and capabilities this app provides."),protocolVersion:Q.string().describe("Protocol version this app supports.")})}),k=Q.object({protocolVersion:Q.string().describe('Negotiated protocol version string (e.g., "2025-11-21").'),hostInfo:g.describe("Host application identification and version."),hostCapabilities:y.describe("Features and capabilities provided by the host."),hostContext:E.describe("Rich context about the host environment.")}).passthrough();var M="ui/resourceUri",u="text/html;profile=mcp-app";class zQ extends j{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;eventSchemas={toolinput:A,toolinputpartial:P,toolresult:R,toolcancelled:H,hostcontextchanged:U};onEventDispatch(Z,$){if(Z==="hostcontextchanged")this._hostContext={...this._hostContext,...$}}constructor(Z,$={},J={autoResize:!0}){super(J);this._appInfo=Z;this._capabilities=$;this.options=J;this.setRequestHandler(jQ,(X)=>{return console.log("Received ping:",X.params),{}}),this.setEventHandler("hostcontextchanged",void 0)}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}get ontoolinput(){return this.getEventHandler("toolinput")}set ontoolinput(Z){this.setEventHandler("toolinput",Z)}get ontoolinputpartial(){return this.getEventHandler("toolinputpartial")}set ontoolinputpartial(Z){this.setEventHandler("toolinputpartial",Z)}get ontoolresult(){return this.getEventHandler("toolresult")}set ontoolresult(Z){this.setEventHandler("toolresult",Z)}get ontoolcancelled(){return this.getEventHandler("toolcancelled")}set ontoolcancelled(Z){this.setEventHandler("toolcancelled",Z)}get onhostcontextchanged(){return this.getEventHandler("hostcontextchanged")}set onhostcontextchanged(Z){this.setEventHandler("hostcontextchanged",Z)}_onteardown;get onteardown(){return this._onteardown}set onteardown(Z){this.warnIfRequestHandlerReplaced("onteardown",this._onteardown,Z),this._onteardown=Z,this.replaceRequestHandler(_,($,J)=>{if(!this._onteardown)throw Error("No onteardown handler set");return this._onteardown($.params,J)})}_oncalltool;get oncalltool(){return this._oncalltool}set oncalltool(Z){this.warnIfRequestHandlerReplaced("oncalltool",this._oncalltool,Z),this._oncalltool=Z,this.replaceRequestHandler(WQ,($,J)=>{if(!this._oncalltool)throw Error("No oncalltool handler set");return this._oncalltool($.params,J)})}_onlisttools;get onlisttools(){return this._onlisttools}set onlisttools(Z){this.warnIfRequestHandlerReplaced("onlisttools",this._onlisttools,Z),this._onlisttools=Z,this.replaceRequestHandler(YQ,($,J)=>{if(!this._onlisttools)throw Error("No onlisttools handler set");return this._onlisttools($.params,J)})}assertCapabilityForMethod(Z){}assertRequestHandlerCapability(Z){switch(Z){case"tools/call":case"tools/list":if(!this._capabilities.tools)throw Error(`Client does not support tool capability (required for ${Z})`);return;case"ping":case"ui/resource-teardown":return;default:throw Error(`No handler for method ${Z} registered`)}}assertNotificationCapability(Z){}assertTaskCapability(Z){throw Error("Tasks are not supported in MCP Apps")}assertTaskHandlerCapability(Z){throw Error("Task handlers are not supported in MCP Apps")}async callServerTool(Z,$){if(typeof Z==="string")throw Error(`callServerTool() expects an object as its first argument, but received a string ("${Z}"). Did you mean: callServerTool({ name: "${Z}", arguments: { ... } })?`);return await this.request({method:"tools/call",params:Z},BQ,{onprogress:()=>{},resetTimeoutOnProgress:!0,...$})}async readServerResource(Z,$){return await this.request({method:"resources/read",params:Z},FQ,$)}async listServerResources(Z,$){return await this.request({method:"resources/list",params:Z},NQ,$)}sendMessage(Z,$){return this.request({method:"ui/message",params:Z},w,$)}sendLog(Z){return this.notification({method:"notifications/message",params:Z})}updateModelContext(Z,$){return this.request({method:"ui/update-model-context",params:Z},KQ,$)}openLink(Z,$){return this.request({method:"ui/open-link",params:Z},O,$)}sendOpenLink=this.openLink;downloadFile(Z,$){return this.request({method:"ui/download-file",params:Z},I,$)}requestTeardown(Z={}){return this.notification({method:"ui/notifications/request-teardown",params:Z})}requestDisplayMode(Z,$){return this.request({method:"ui/request-display-mode",params:Z},T,$)}sendSizeChanged(Z){return this.notification({method:"ui/notifications/size-changed",params:Z})}setupSizeChangedNotifications(){let Z=!1,$=0,J=0,X=()=>{if(Z)return;Z=!0,requestAnimationFrame(()=>{Z=!1;let D=document.documentElement,G=D.style.height;D.style.height="max-content";let L=Math.ceil(D.getBoundingClientRect().height);D.style.height=G;let Y=Math.ceil(window.innerWidth);if(Y!==$||L!==J)$=Y,J=L,this.sendSizeChanged({width:Y,height:L})})};X();let V=new ResizeObserver(X);return V.observe(document.documentElement),V.observe(document.body),()=>V.disconnect()}async connect(Z=new B(window.parent,window.parent),$){if(this.transport)throw Error("App is already connected. Call close() before connecting again.");await super.connect(Z);try{let J=await this.request({method:"ui/initialize",params:{appCapabilities:this._capabilities,appInfo:this._appInfo,protocolVersion:F}},k,$);if(J===void 0)throw Error(`Server sent invalid initialize result: ${J}`);if(this._hostCapabilities=J.hostCapabilities,this._hostInfo=J.hostInfo,this._hostContext=J.hostContext,await this.notification({method:"ui/notifications/initialized"}),this.options?.autoResize)this.setupSizeChangedNotifications()}catch(J){throw this.close(),J}}}function hZ(Z,$,J,X){let V=J._meta,D=V.ui,G=V[M],L=V;if(D?.resourceUri&&!G)L={...V,[M]:D.resourceUri};else if(G&&!D?.resourceUri)L={...V,ui:{...D,resourceUri:G}};return Z.registerTool($,{...J,_meta:L},X)}function mZ(Z,$,J,X,V){return Z.registerResource($,J,{mimeType:u,...X},V)}var qQ="io.modelcontextprotocol/ui";function pZ(Z){if(!Z)return;return Z.extensions?.[qQ]}export{hZ as registerAppTool,mZ as registerAppResource,pZ as getUiCapability,M as RESOURCE_URI_META_KEY,u as RESOURCE_MIME_TYPE,qQ as EXTENSION_ID};

@@ -8,3 +8,3 @@ {

"homepage": "https://github.com/modelcontextprotocol/ext-apps",
"version": "1.5.0",
"version": "1.6.0",
"license": "MIT",

@@ -11,0 +11,0 @@ "description": "MCP Apps SDK — Enable MCP servers to display interactive user interfaces in conversational clients.",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display