@modelcontextprotocol/ext-apps 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/app-bridge.d.ts +28 -1
- package/dist/src/app-bridge.js +6 -6
- package/dist/src/app-with-deps.js +6 -6
- package/dist/src/app.d.ts +40 -2
- package/dist/src/app.js +6 -6
- package/dist/src/generated/schema.d.ts +13 -1
- package/dist/src/generated/schema.json +17 -0
- package/dist/src/generated/schema.test.d.ts +2 -1
- package/dist/src/react/index.js +6 -6
- package/dist/src/react/react-with-deps.js +10 -10
- package/dist/src/server/index.js +5 -5
- package/dist/src/spec.types.d.ts +13 -0
- package/dist/src/types.d.ts +5 -5
- package/package.json +1 -1
package/dist/src/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Protocol as
|
|
1
|
+
import{Protocol as jQ}from"@modelcontextprotocol/sdk/shared/protocol.js";import{CallToolRequestSchema as BQ,CallToolResultSchema as KQ,EmptyResultSchema as NQ,ListResourcesResultSchema as YQ,ListToolsRequestSchema as FQ,PingRequestSchema as zQ,ReadResourceResultSchema as qQ}from"@modelcontextprotocol/sdk/types.js";import{JSONRPCMessageSchema as m}from"@modelcontextprotocol/sdk/types.js";var F="2026-01-26";var z="ui/notifications/tool-input-partial";class j{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=m.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 M,CallToolResultSchema as c,EmbeddedResourceSchema as p,ImplementationSchema as b,RequestIdSchema as l,ResourceLinkSchema as r,ToolSchema as n}from"@modelcontextprotocol/sdk/types.js";var g=Q.union([Q.literal("light"),Q.literal("dark")]).describe("Color theme preference for the host environment."),G=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."),o=Q.record(i.describe(`Style variables for theming MCP apps.
|
|
2
2
|
|
|
3
3
|
Individual style keys are optional - hosts may provide any subset of these values.
|
|
4
4
|
Values are strings containing CSS values (colors, sizes, font stacks, etc.).
|
|
@@ -19,7 +19,7 @@ Note: This type uses \`Record<K, string | undefined>\` rather than \`Partial<Rec
|
|
|
19
19
|
for compatibility with Zod schema generation. Both are functionally equivalent for validation.`),a=Q.object({method:Q.literal("ui/open-link"),params:Q.object({url:Q.string().describe("URL to open in the host's browser")})}),O=Q.object({isError:Q.boolean().optional().describe("True if the host failed to open the URL (e.g., due to security policy).")}).passthrough(),I=Q.object({isError:Q.boolean().optional().describe("True if the download failed (e.g., user cancelled or host denied).")}).passthrough(),w=Q.object({isError:Q.boolean().optional().describe("True if the host rejected or failed to deliver the message.")}).passthrough(),s=Q.object({method:Q.literal("ui/notifications/sandbox-proxy-ready"),params:Q.object({})}),B=Q.object({connectDomains:Q.array(Q.string()).optional().describe(`Origins for network requests (fetch/XHR/WebSocket).
|
|
20
20
|
|
|
21
21
|
- Maps to CSP \`connect-src\` directive
|
|
22
|
-
- Empty or omitted → no network connections (secure default)`),resourceDomains:Q.array(Q.string()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:Q.array(Q.string()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:Q.array(Q.string()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),K=Q.object({camera:Q.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:Q.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:Q.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:Q.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),t=Q.object({method:Q.literal("ui/notifications/size-changed"),params:Q.object({width:Q.number().optional().describe("New width in pixels."),height:Q.number().optional().describe("New height in pixels.")})}),A=Q.object({method:Q.literal("ui/notifications/tool-input"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),P=Q.object({method:Q.literal("ui/notifications/tool-input-partial"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),H=Q.object({method:Q.literal("ui/notifications/tool-cancelled"),params:Q.object({reason:Q.string().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),
|
|
22
|
+
- Empty or omitted → no network connections (secure default)`),resourceDomains:Q.array(Q.string()).optional().describe("Origins for static resources (images, scripts, stylesheets, fonts, media).\n\n- Maps to CSP `img-src`, `script-src`, `style-src`, `font-src`, `media-src` directives\n- Wildcard subdomains supported: `https://*.example.com`\n- Empty or omitted → no network resources (secure default)"),frameDomains:Q.array(Q.string()).optional().describe("Origins for nested iframes.\n\n- Maps to CSP `frame-src` directive\n- Empty or omitted → no nested iframes allowed (`frame-src 'none'`)"),baseUriDomains:Q.array(Q.string()).optional().describe("Allowed base URIs for the document.\n\n- Maps to CSP `base-uri` directive\n- Empty or omitted → only same origin allowed (`base-uri 'self'`)")}),K=Q.object({camera:Q.object({}).optional().describe("Request camera access.\n\nMaps to Permission Policy `camera` feature."),microphone:Q.object({}).optional().describe("Request microphone access.\n\nMaps to Permission Policy `microphone` feature."),geolocation:Q.object({}).optional().describe("Request geolocation access.\n\nMaps to Permission Policy `geolocation` feature."),clipboardWrite:Q.object({}).optional().describe("Request clipboard write access.\n\nMaps to Permission Policy `clipboard-write` feature.")}),t=Q.object({method:Q.literal("ui/notifications/size-changed"),params:Q.object({width:Q.number().optional().describe("New width in pixels."),height:Q.number().optional().describe("New height in pixels.")})}),A=Q.object({method:Q.literal("ui/notifications/tool-input"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Complete tool call arguments as key-value pairs.")).optional().describe("Complete tool call arguments as key-value pairs.")})}),P=Q.object({method:Q.literal("ui/notifications/tool-input-partial"),params:Q.object({arguments:Q.record(Q.string(),Q.unknown().describe("Partial tool call arguments (incomplete, may change).")).optional().describe("Partial tool call arguments (incomplete, may change).")})}),H=Q.object({method:Q.literal("ui/notifications/tool-cancelled"),params:Q.object({reason:Q.string().optional().describe('Optional reason for the cancellation (e.g., "user action", "timeout").')})}),S=Q.object({fonts:Q.string().optional()}),y=Q.object({variables:o.optional().describe("CSS variables for theming the app."),css:S.optional().describe("CSS blocks that apps can inject.")}),_=Q.object({method:Q.literal("ui/resource-teardown"),params:Q.object({})}),e=Q.record(Q.string(),Q.unknown()),q=Q.object({text:Q.object({}).optional().describe("Host supports text content blocks."),image:Q.object({}).optional().describe("Host supports image content blocks."),audio:Q.object({}).optional().describe("Host supports audio content blocks."),resource:Q.object({}).optional().describe("Host supports resource content blocks."),resourceLink:Q.object({}).optional().describe("Host supports resource link content blocks."),structuredContent:Q.object({}).optional().describe("Host supports structured content.")}),QQ=Q.object({method:Q.literal("ui/notifications/request-teardown"),params:Q.object({}).optional()}),C=Q.object({experimental:Q.object({}).optional().describe("Experimental features (structure TBD)."),openLinks:Q.object({}).optional().describe("Host supports opening external URLs."),downloadFile:Q.object({}).optional().describe("Host supports file downloads via ui/download-file."),serverTools:Q.object({listChanged:Q.boolean().optional().describe("Host supports tools/list_changed notifications.")}).optional().describe("Host can proxy tool calls to the MCP server."),serverResources:Q.object({listChanged:Q.boolean().optional().describe("Host supports resources/list_changed notifications.")}).optional().describe("Host can proxy resource reads to the MCP server."),logging:Q.object({}).optional().describe("Host accepts log messages."),sandbox:Q.object({permissions:K.optional().describe("Permissions granted by the host (camera, microphone, geolocation)."),csp:B.optional().describe("CSP domains approved by the host.")}).optional().describe("Sandbox configuration applied by the host."),updateModelContext:q.optional().describe("Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns."),message:q.optional().describe("Host supports receiving content messages (ui/message) from the view.")}),f=Q.object({experimental:Q.object({}).optional().describe("Experimental features (structure TBD)."),tools:Q.object({listChanged:Q.boolean().optional().describe("App supports tools/list_changed notifications.")}).optional().describe("App exposes MCP-style tools that the host can call."),availableDisplayModes:Q.array(G).optional().describe("Display modes the app supports.")}),ZQ=Q.object({method:Q.literal("ui/notifications/initialized"),params:Q.object({}).optional()}),$Q=Q.object({csp:B.optional().describe("Content Security Policy configuration for UI resources."),permissions:K.optional().describe("Sandbox permissions requested by the UI resource."),domain:Q.string().optional().describe(`Dedicated origin for view sandbox.
|
|
23
23
|
|
|
24
24
|
Useful when views need stable, dedicated origins for OAuth callbacks, CORS policies, or API key allowlists.
|
|
25
25
|
|
|
@@ -33,7 +33,7 @@ Boolean requesting whether a visible border and background is provided by the ho
|
|
|
33
33
|
|
|
34
34
|
- \`true\`: request visible border + background
|
|
35
35
|
- \`false\`: request no visible border + background
|
|
36
|
-
- omitted: host decides border`)})
|
|
36
|
+
- omitted: host decides border`)}),JQ=Q.object({method:Q.literal("ui/request-display-mode"),params:Q.object({mode:G.describe("The display mode being requested.")})}),T=Q.object({mode:G.describe("The display mode that was actually set. May differ from requested if not supported.")}).passthrough(),u=Q.union([Q.literal("model"),Q.literal("app")]).describe("Tool visibility scope - who can access the tool."),XQ=Q.object({resourceUri:Q.string().optional(),visibility:Q.array(u).optional().describe(`Who can access this tool. Default: ["model", "app"]
|
|
37
37
|
- "model": Tool visible to and callable by the agent
|
|
38
|
-
- "app": Tool callable by the app from this server only`)}),
|
|
39
|
-
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:Q.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:Q.string().optional().describe("User's timezone in IANA format."),userAgent:Q.string().optional().describe("Host application identifier."),platform:Q.union([Q.literal("web"),Q.literal("desktop"),Q.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:Q.object({touch:Q.boolean().optional().describe("Whether the device supports touch input."),hover:Q.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:Q.object({top:Q.number().describe("Top safe area inset in pixels."),right:Q.number().describe("Right safe area inset in pixels."),bottom:Q.number().describe("Bottom safe area inset in pixels."),left:Q.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),
|
|
38
|
+
- "app": Tool callable by the app from this server only`)}),RQ=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.')}),VQ=Q.object({method:Q.literal("ui/download-file"),params:Q.object({contents:Q.array(Q.union([p,r])).describe("Resource contents to download — embedded (inline data) or linked (host fetches). Uses standard MCP resource types.")})}),DQ=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.).")})}),GQ=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:K.optional().describe("Sandbox permissions from resource metadata.")})}),E=Q.object({method:Q.literal("ui/notifications/tool-result"),params:c.describe("Standard MCP tool execution result.")}),k=Q.object({toolInfo:Q.object({id:l.optional().describe("JSON-RPC id of the tools/call request."),tool:n.describe("Tool definition including name, inputSchema, etc.")}).optional().describe("Metadata of the tool call that instantiated this App."),theme:g.optional().describe("Current color theme preference."),styles:y.optional().describe("Style configuration for theming the app."),displayMode:G.optional().describe("How the UI is currently displayed."),availableDisplayModes:Q.array(G).optional().describe("Display modes the host supports."),containerDimensions:Q.union([Q.object({height:Q.number().describe("Fixed container height in pixels.")}),Q.object({maxHeight:Q.union([Q.number(),Q.undefined()]).optional().describe("Maximum container height in pixels.")})]).and(Q.union([Q.object({width:Q.number().describe("Fixed container width in pixels.")}),Q.object({maxWidth:Q.union([Q.number(),Q.undefined()]).optional().describe("Maximum container width in pixels.")})])).optional().describe(`Container dimensions. Represents the dimensions of the iframe or other
|
|
39
|
+
container holding the app. Specify either width or maxWidth, and either height or maxHeight.`),locale:Q.string().optional().describe("User's language and region preference in BCP 47 format."),timeZone:Q.string().optional().describe("User's timezone in IANA format."),userAgent:Q.string().optional().describe("Host application identifier."),platform:Q.union([Q.literal("web"),Q.literal("desktop"),Q.literal("mobile")]).optional().describe("Platform type for responsive design decisions."),deviceCapabilities:Q.object({touch:Q.boolean().optional().describe("Whether the device supports touch input."),hover:Q.boolean().optional().describe("Whether the device supports hover interactions.")}).optional().describe("Device input capabilities."),safeAreaInsets:Q.object({top:Q.number().describe("Top safe area inset in pixels."),right:Q.number().describe("Right safe area inset in pixels."),bottom:Q.number().describe("Bottom safe area inset in pixels."),left:Q.number().describe("Left safe area inset in pixels.")}).optional().describe("Mobile safe area boundaries in pixels.")}).passthrough(),R=Q.object({method:Q.literal("ui/notifications/host-context-changed"),params:k.describe("Partial context update containing only changed fields.")}),LQ=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.")})}),WQ=Q.object({method:Q.literal("ui/initialize"),params:Q.object({appInfo:b.describe("App identification (name and version)."),appCapabilities:f.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:b.describe("Host application identification and version."),hostCapabilities:C.describe("Features and capabilities provided by the host."),hostContext:k.describe("Rich context about the host environment.")}).passthrough();var v="ui/resourceUri",d="text/html;profile=mcp-app";class OQ extends jQ{_appInfo;_capabilities;options;_hostCapabilities;_hostInfo;_hostContext;constructor(Z,$={},J={autoResize:!0}){super(J);this._appInfo=Z;this._capabilities=$;this.options=J;this.setRequestHandler(zQ,(X)=>{return console.log("Received ping:",X.params),{}}),this.onhostcontextchanged=()=>{}}getHostCapabilities(){return this._hostCapabilities}getHostVersion(){return this._hostInfo}getHostContext(){return this._hostContext}set ontoolinput(Z){this.setNotificationHandler(A,($)=>Z($.params))}set ontoolinputpartial(Z){this.setNotificationHandler(P,($)=>Z($.params))}set ontoolresult(Z){this.setNotificationHandler(E,($)=>Z($.params))}set ontoolcancelled(Z){this.setNotificationHandler(H,($)=>Z($.params))}set onhostcontextchanged(Z){this.setNotificationHandler(R,($)=>{this._hostContext={...this._hostContext,...$.params},Z($.params)})}set onteardown(Z){this.setRequestHandler(_,($,J)=>Z($.params,J))}set oncalltool(Z){this.setRequestHandler(BQ,($,J)=>Z($.params,J))}set onlisttools(Z){this.setRequestHandler(FQ,($,J)=>Z($.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},KQ,$)}async readServerResource(Z,$){return await this.request({method:"resources/read",params:Z},qQ,$)}async listServerResources(Z,$){return await this.request({method:"resources/list",params:Z},YQ,$)}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},NQ,$)}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 V=document.documentElement,L=V.style.width,W=V.style.height;V.style.width="fit-content",V.style.height="max-content";let x=V.getBoundingClientRect();V.style.width=L,V.style.height=W;let h=window.innerWidth-V.clientWidth,N=Math.ceil(x.width+h),Y=Math.ceil(x.height);if(N!==$||Y!==J)$=N,J=Y,this.sendSizeChanged({width:N,height:Y})})};X();let D=new ResizeObserver(X);return D.observe(document.documentElement),D.observe(document.body),()=>D.disconnect()}async connect(Z=new j(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}},U,$);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 D=J._meta,V=D.ui,L=D[v],W=D;if(V?.resourceUri&&!L)W={...D,[v]:V.resourceUri};else if(L&&!V?.resourceUri)W={...D,ui:{...V,resourceUri:L}};return Z.registerTool($,{...J,_meta:W},X)}function mZ(Z,$,J,X,D){return Z.registerResource($,J,{mimeType:d,...X},D)}var IQ="io.modelcontextprotocol/ui";function cZ(Z){if(!Z)return;return Z.extensions?.[IQ]}export{hZ as registerAppTool,mZ as registerAppResource,cZ as getUiCapability,v as RESOURCE_URI_META_KEY,d as RESOURCE_MIME_TYPE,IQ as EXTENSION_ID};
|
package/dist/src/spec.types.d.ts
CHANGED
|
@@ -342,6 +342,18 @@ export interface McpUiSupportedContentBlockModalities {
|
|
|
342
342
|
/** @description Host supports structured content. */
|
|
343
343
|
structuredContent?: {};
|
|
344
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* @description Notification for app-initiated teardown request (View -> Host).
|
|
347
|
+
* Views send this to request that the host tear them down. The host decides
|
|
348
|
+
* whether to proceed - if approved, the host will send
|
|
349
|
+
* `ui/resource-teardown` to allow the view to perform cleanup before being
|
|
350
|
+
* unmounted.
|
|
351
|
+
* @see {@link app.App.requestTeardown} for the app method that sends this
|
|
352
|
+
*/
|
|
353
|
+
export interface McpUiRequestTeardownNotification {
|
|
354
|
+
method: "ui/notifications/request-teardown";
|
|
355
|
+
params?: {};
|
|
356
|
+
}
|
|
345
357
|
/**
|
|
346
358
|
* @description Capabilities supported by the host application.
|
|
347
359
|
* @see {@link McpUiInitializeResult `McpUiInitializeResult`} for the initialization result that includes these capabilities
|
|
@@ -647,6 +659,7 @@ export declare const TOOL_INPUT_PARTIAL_METHOD: McpUiToolInputPartialNotificatio
|
|
|
647
659
|
export declare const TOOL_RESULT_METHOD: McpUiToolResultNotification["method"];
|
|
648
660
|
export declare const TOOL_CANCELLED_METHOD: McpUiToolCancelledNotification["method"];
|
|
649
661
|
export declare const HOST_CONTEXT_CHANGED_METHOD: McpUiHostContextChangedNotification["method"];
|
|
662
|
+
export declare const REQUEST_TEARDOWN_METHOD: McpUiRequestTeardownNotification["method"];
|
|
650
663
|
export declare const RESOURCE_TEARDOWN_METHOD: McpUiResourceTeardownRequest["method"];
|
|
651
664
|
export declare const INITIALIZE_METHOD: McpUiInitializeRequest["method"];
|
|
652
665
|
export declare const INITIALIZED_METHOD: McpUiInitializedNotification["method"];
|
package/dist/src/types.d.ts
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
* @see `generated/schema.ts` for auto-generated Zod schemas
|
|
9
9
|
* @see `generated/schema.test.ts` for compile-time verification
|
|
10
10
|
*/
|
|
11
|
-
export { LATEST_PROTOCOL_VERSION, OPEN_LINK_METHOD, DOWNLOAD_FILE_METHOD, MESSAGE_METHOD, SANDBOX_PROXY_READY_METHOD, SANDBOX_RESOURCE_READY_METHOD, SIZE_CHANGED_METHOD, TOOL_INPUT_METHOD, TOOL_INPUT_PARTIAL_METHOD, TOOL_RESULT_METHOD, TOOL_CANCELLED_METHOD, HOST_CONTEXT_CHANGED_METHOD, RESOURCE_TEARDOWN_METHOD, INITIALIZE_METHOD, INITIALIZED_METHOD, REQUEST_DISPLAY_MODE_METHOD, type McpUiTheme, type McpUiDisplayMode, type McpUiStyleVariableKey, type McpUiStyles, type McpUiHostCss, type McpUiHostStyles, type McpUiOpenLinkRequest, type McpUiOpenLinkResult, type McpUiDownloadFileRequest, type McpUiDownloadFileResult, type McpUiMessageRequest, type McpUiMessageResult, type McpUiUpdateModelContextRequest, type McpUiSupportedContentBlockModalities, type McpUiSandboxProxyReadyNotification, type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, type McpUiToolCancelledNotification, type McpUiHostContext, type McpUiHostContextChangedNotification, type McpUiResourceTeardownRequest, type McpUiResourceTeardownResult, type McpUiHostCapabilities, type McpUiAppCapabilities, type McpUiInitializeRequest, type McpUiInitializeResult, type McpUiInitializedNotification, type McpUiResourceCsp, type McpUiResourcePermissions, type McpUiResourceMeta, type McpUiRequestDisplayModeRequest, type McpUiRequestDisplayModeResult, type McpUiToolVisibility, type McpUiToolMeta, type McpUiClientCapabilities, } from "./spec.types.js";
|
|
12
|
-
import type { McpUiInitializeRequest, McpUiOpenLinkRequest, McpUiDownloadFileRequest, McpUiMessageRequest, McpUiUpdateModelContextRequest, McpUiResourceTeardownRequest, McpUiRequestDisplayModeRequest, McpUiHostContextChangedNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiToolCancelledNotification, McpUiSandboxResourceReadyNotification, McpUiInitializedNotification, McpUiSizeChangedNotification, McpUiSandboxProxyReadyNotification, McpUiInitializeResult, McpUiOpenLinkResult, McpUiDownloadFileResult, McpUiMessageResult, McpUiResourceTeardownResult, McpUiRequestDisplayModeResult } from "./spec.types.js";
|
|
13
|
-
export { McpUiThemeSchema, McpUiDisplayModeSchema, McpUiHostCssSchema, McpUiHostStylesSchema, McpUiOpenLinkRequestSchema, McpUiOpenLinkResultSchema, McpUiDownloadFileRequestSchema, McpUiDownloadFileResultSchema, McpUiMessageRequestSchema, McpUiMessageResultSchema, McpUiUpdateModelContextRequestSchema, McpUiSupportedContentBlockModalitiesSchema, McpUiSandboxProxyReadyNotificationSchema, McpUiSandboxResourceReadyNotificationSchema, McpUiSizeChangedNotificationSchema, McpUiToolInputNotificationSchema, McpUiToolInputPartialNotificationSchema, McpUiToolResultNotificationSchema, McpUiToolCancelledNotificationSchema, McpUiHostContextSchema, McpUiHostContextChangedNotificationSchema, McpUiResourceTeardownRequestSchema, McpUiResourceTeardownResultSchema, McpUiHostCapabilitiesSchema, McpUiAppCapabilitiesSchema, McpUiInitializeRequestSchema, McpUiInitializeResultSchema, McpUiInitializedNotificationSchema, McpUiResourceCspSchema, McpUiResourcePermissionsSchema, McpUiResourceMetaSchema, McpUiRequestDisplayModeRequestSchema, McpUiRequestDisplayModeResultSchema, McpUiToolVisibilitySchema, McpUiToolMetaSchema, } from "./generated/schema.js";
|
|
11
|
+
export { LATEST_PROTOCOL_VERSION, OPEN_LINK_METHOD, DOWNLOAD_FILE_METHOD, MESSAGE_METHOD, SANDBOX_PROXY_READY_METHOD, SANDBOX_RESOURCE_READY_METHOD, SIZE_CHANGED_METHOD, TOOL_INPUT_METHOD, TOOL_INPUT_PARTIAL_METHOD, TOOL_RESULT_METHOD, TOOL_CANCELLED_METHOD, HOST_CONTEXT_CHANGED_METHOD, REQUEST_TEARDOWN_METHOD, RESOURCE_TEARDOWN_METHOD, INITIALIZE_METHOD, INITIALIZED_METHOD, REQUEST_DISPLAY_MODE_METHOD, type McpUiTheme, type McpUiDisplayMode, type McpUiStyleVariableKey, type McpUiStyles, type McpUiHostCss, type McpUiHostStyles, type McpUiOpenLinkRequest, type McpUiOpenLinkResult, type McpUiDownloadFileRequest, type McpUiDownloadFileResult, type McpUiMessageRequest, type McpUiMessageResult, type McpUiUpdateModelContextRequest, type McpUiSupportedContentBlockModalities, type McpUiSandboxProxyReadyNotification, type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, type McpUiToolCancelledNotification, type McpUiHostContext, type McpUiHostContextChangedNotification, type McpUiResourceTeardownRequest, type McpUiResourceTeardownResult, type McpUiRequestTeardownNotification, type McpUiHostCapabilities, type McpUiAppCapabilities, type McpUiInitializeRequest, type McpUiInitializeResult, type McpUiInitializedNotification, type McpUiResourceCsp, type McpUiResourcePermissions, type McpUiResourceMeta, type McpUiRequestDisplayModeRequest, type McpUiRequestDisplayModeResult, type McpUiToolVisibility, type McpUiToolMeta, type McpUiClientCapabilities, } from "./spec.types.js";
|
|
12
|
+
import type { McpUiInitializeRequest, McpUiOpenLinkRequest, McpUiDownloadFileRequest, McpUiMessageRequest, McpUiUpdateModelContextRequest, McpUiResourceTeardownRequest, McpUiRequestDisplayModeRequest, McpUiHostContextChangedNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiToolCancelledNotification, McpUiSandboxResourceReadyNotification, McpUiInitializedNotification, McpUiSizeChangedNotification, McpUiSandboxProxyReadyNotification, McpUiRequestTeardownNotification, McpUiInitializeResult, McpUiOpenLinkResult, McpUiDownloadFileResult, McpUiMessageResult, McpUiResourceTeardownResult, McpUiRequestDisplayModeResult } from "./spec.types.js";
|
|
13
|
+
export { McpUiThemeSchema, McpUiDisplayModeSchema, McpUiHostCssSchema, McpUiHostStylesSchema, McpUiOpenLinkRequestSchema, McpUiOpenLinkResultSchema, McpUiDownloadFileRequestSchema, McpUiDownloadFileResultSchema, McpUiMessageRequestSchema, McpUiMessageResultSchema, McpUiUpdateModelContextRequestSchema, McpUiSupportedContentBlockModalitiesSchema, McpUiSandboxProxyReadyNotificationSchema, McpUiSandboxResourceReadyNotificationSchema, McpUiSizeChangedNotificationSchema, McpUiToolInputNotificationSchema, McpUiToolInputPartialNotificationSchema, McpUiToolResultNotificationSchema, McpUiToolCancelledNotificationSchema, McpUiHostContextSchema, McpUiHostContextChangedNotificationSchema, McpUiResourceTeardownRequestSchema, McpUiResourceTeardownResultSchema, McpUiRequestTeardownNotificationSchema, McpUiHostCapabilitiesSchema, McpUiAppCapabilitiesSchema, McpUiInitializeRequestSchema, McpUiInitializeResultSchema, McpUiInitializedNotificationSchema, McpUiResourceCspSchema, McpUiResourcePermissionsSchema, McpUiResourceMetaSchema, McpUiRequestDisplayModeRequestSchema, McpUiRequestDisplayModeResultSchema, McpUiToolVisibilitySchema, McpUiToolMetaSchema, } from "./generated/schema.js";
|
|
14
14
|
import { CallToolRequest, CallToolResult, EmptyResult, ListPromptsRequest, ListPromptsResult, ListResourcesRequest, ListResourcesResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, ListToolsRequest, ListToolsResult, LoggingMessageNotification, PingRequest, PromptListChangedNotification, ReadResourceRequest, ReadResourceResult, ResourceListChangedNotification, ToolListChangedNotification } from "@modelcontextprotocol/sdk/types.js";
|
|
15
15
|
/**
|
|
16
16
|
* All request types in the MCP Apps protocol.
|
|
@@ -32,10 +32,10 @@ export type AppRequest = McpUiInitializeRequest | McpUiOpenLinkRequest | McpUiDo
|
|
|
32
32
|
* - Sandbox resource ready
|
|
33
33
|
*
|
|
34
34
|
* App to host:
|
|
35
|
-
* - Initialized, size-changed, sandbox-proxy-ready
|
|
35
|
+
* - Initialized, size-changed, sandbox-proxy-ready, request-teardown
|
|
36
36
|
* - Logging messages
|
|
37
37
|
*/
|
|
38
|
-
export type AppNotification = McpUiHostContextChangedNotification | McpUiToolInputNotification | McpUiToolInputPartialNotification | McpUiToolResultNotification | McpUiToolCancelledNotification | McpUiSandboxResourceReadyNotification | ToolListChangedNotification | ResourceListChangedNotification | PromptListChangedNotification | McpUiInitializedNotification | McpUiSizeChangedNotification | McpUiSandboxProxyReadyNotification | LoggingMessageNotification;
|
|
38
|
+
export type AppNotification = McpUiHostContextChangedNotification | McpUiToolInputNotification | McpUiToolInputPartialNotification | McpUiToolResultNotification | McpUiToolCancelledNotification | McpUiSandboxResourceReadyNotification | ToolListChangedNotification | ResourceListChangedNotification | PromptListChangedNotification | McpUiInitializedNotification | McpUiSizeChangedNotification | McpUiSandboxProxyReadyNotification | McpUiRequestTeardownNotification | LoggingMessageNotification;
|
|
39
39
|
/**
|
|
40
40
|
* All result types in the MCP Apps protocol.
|
|
41
41
|
*/
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "https://github.com/modelcontextprotocol/ext-apps"
|
|
6
6
|
},
|
|
7
7
|
"homepage": "https://github.com/modelcontextprotocol/ext-apps",
|
|
8
|
-
"version": "1.
|
|
8
|
+
"version": "1.3.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"description": "MCP Apps SDK — Enable MCP servers to display interactive user interfaces in conversational clients.",
|
|
11
11
|
"type": "module",
|