@modelcontextprotocol/ext-apps 0.3.1 → 0.4.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/README.md CHANGED
@@ -6,6 +6,17 @@ This repo contains the SDK and [specification](https://github.com/modelcontextpr
6
6
 
7
7
  MCP Apps are a proposed standard inspired by [MCP-UI](https://mcpui.dev/) and [OpenAI's Apps SDK](https://developers.openai.com/apps-sdk/) to allow MCP Servers to display interactive UI elements in conversational MCP clients / chatbots.
8
8
 
9
+ ## How It Works
10
+
11
+ MCP Apps extend the Model Context Protocol to let servers deliver **interactive UIs** to MCP hosts. Here's how it works:
12
+
13
+ 1. **Tool call** — The LLM calls a tool on your server
14
+ 2. **UI Resource** — The tool's definition links to a predeclared `ui://` resource containing its HTML interface
15
+ 3. **Host renders** — The host fetches the resource and displays it in a sandboxed iframe
16
+ 4. **Bidirectional communication** — The host passes tool data to the UI via notifications, and the UI can call other tools through the host
17
+
18
+ This enables dashboards, forms, visualizations, and other rich experiences inside chat interfaces.
19
+
9
20
  ## Overview
10
21
 
11
22
  This SDK serves two audiences:
@@ -1,8 +1,8 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
3
- import { CallToolRequest, CallToolResult, Implementation, ListPromptsRequest, ListPromptsResult, ListResourcesRequest, ListResourcesResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, LoggingMessageNotification, PingRequest, PromptListChangedNotification, ReadResourceRequest, ReadResourceResult, ResourceListChangedNotification, ToolListChangedNotification } from "@modelcontextprotocol/sdk/types.js";
3
+ import { CallToolRequest, CallToolResult, EmptyResult, Implementation, ListPromptsRequest, ListPromptsResult, ListResourcesRequest, ListResourcesResult, ListResourceTemplatesRequest, ListResourceTemplatesResult, LoggingMessageNotification, PingRequest, PromptListChangedNotification, ReadResourceRequest, ReadResourceResult, ResourceListChangedNotification, ToolListChangedNotification } from "@modelcontextprotocol/sdk/types.js";
4
4
  import { Protocol, ProtocolOptions, RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
5
- import { type AppNotification, type AppRequest, type AppResult, type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolCancelledNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, McpUiAppCapabilities, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiInitializedNotification, McpUiMessageRequest, McpUiMessageResult, McpUiOpenLinkRequest, McpUiOpenLinkResult, McpUiResourceTeardownRequest, McpUiSandboxProxyReadyNotification, McpUiRequestDisplayModeRequest, McpUiRequestDisplayModeResult } from "./types";
5
+ import { type AppNotification, type AppRequest, type AppResult, type McpUiSandboxResourceReadyNotification, type McpUiSizeChangedNotification, type McpUiToolCancelledNotification, type McpUiToolInputNotification, type McpUiToolInputPartialNotification, type McpUiToolResultNotification, McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiInitializedNotification, McpUiMessageRequest, McpUiMessageResult, McpUiOpenLinkRequest, McpUiOpenLinkResult, McpUiResourceTeardownRequest, McpUiSandboxProxyReadyNotification, McpUiRequestDisplayModeRequest, McpUiRequestDisplayModeResult, McpUiResourcePermissions } from "./types";
6
6
  export * from "./types";
7
7
  export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE } from "./app";
8
8
  export { PostMessageTransport } from "./message-transport";
@@ -33,6 +33,23 @@ export { PostMessageTransport } from "./message-transport";
33
33
  export declare function getToolUiResourceUri(tool: {
34
34
  _meta?: Record<string, unknown>;
35
35
  }): string | undefined;
36
+ /**
37
+ * Build iframe `allow` attribute string from permissions.
38
+ *
39
+ * Maps McpUiResourcePermissions to the Permission Policy allow attribute
40
+ * format used by iframes (e.g., "microphone; clipboard-write").
41
+ *
42
+ * @param permissions - Permissions requested by the UI resource
43
+ * @returns Space-separated permission directives, or empty string if none
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const allow = buildAllowAttribute({ microphone: {}, clipboardWrite: {} });
48
+ * // Returns: "microphone; clipboard-write"
49
+ * iframe.setAttribute("allow", allow);
50
+ * ```
51
+ */
52
+ export declare function buildAllowAttribute(permissions: McpUiResourcePermissions | undefined): string;
36
53
  /**
37
54
  * Options for configuring AppBridge behavior.
38
55
  *
@@ -432,6 +449,35 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
432
449
  * ```
433
450
  */
434
451
  set onloggingmessage(callback: (params: LoggingMessageNotification["params"]) => void);
452
+ /**
453
+ * Register a handler for model context updates from the Guest UI.
454
+ *
455
+ * The Guest UI sends `ui/update-model-context` requests to update the Host's
456
+ * model context. Each request overwrites the previous context stored by the Guest UI.
457
+ * Unlike logging messages, context updates are intended to be available to
458
+ * the model in future turns. Unlike messages, context updates do not trigger follow-ups.
459
+ *
460
+ * The host will typically defer sending the context to the model until the
461
+ * next user message (including `ui/message`), and will only send the last
462
+ * update received.
463
+ *
464
+ * @example
465
+ * ```typescript
466
+ * bridge.onupdatemodelcontext = async ({ content, structuredContent }, extra) => {
467
+ * // Update the model context with the new snapshot
468
+ * modelContext = {
469
+ * type: "app_context",
470
+ * content,
471
+ * structuredContent,
472
+ * timestamp: Date.now()
473
+ * };
474
+ * return {};
475
+ * };
476
+ * ```
477
+ *
478
+ * @see {@link McpUiUpdateModelContextRequest} for the request type
479
+ */
480
+ set onupdatemodelcontext(callback: (params: McpUiUpdateModelContextRequest["params"], extra: RequestHandlerExtra) => Promise<EmptyResult>);
435
481
  /**
436
482
  * Register a handler for tool call requests from the Guest UI.
437
483
  *