@modelcontextprotocol/ext-apps 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +196 -1
- package/README.md +32 -10
- package/dist/src/app-bridge.d.ts +131 -72
- package/dist/src/app-bridge.js +10 -10
- package/dist/src/app-with-deps.js +9 -9
- package/dist/src/app.d.ts +75 -24
- package/dist/src/app.js +18 -18
- package/dist/src/generated/schema.d.ts +230 -29
- package/dist/src/generated/schema.test.d.ts +5 -2
- package/dist/src/message-transport.d.ts +20 -22
- package/dist/src/react/index.js +17 -17
- package/dist/src/react/react-with-deps.js +17 -17
- package/dist/src/react/useApp.d.ts +22 -17
- package/dist/src/react/useAutoResize.d.ts +5 -3
- package/dist/src/react/useDocumentTheme.d.ts +3 -1
- package/dist/src/react/useHostStyles.d.ts +19 -18
- package/dist/src/server/index.d.ts +106 -13
- package/dist/src/server/index.js +19 -19
- package/dist/src/spec.types.d.ts +85 -21
- package/dist/src/styles.d.ts +5 -5
- package/dist/src/types.d.ts +11 -10
- package/package.json +6 -4
package/dist/src/app.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RequestOptions, Protocol, ProtocolOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
2
2
|
import { CallToolRequest, CallToolResult, Implementation, ListToolsRequest, LoggingMessageNotification } from "@modelcontextprotocol/sdk/types.js";
|
|
3
3
|
import { AppNotification, AppRequest, AppResult } from "./types";
|
|
4
|
-
import { McpUiAppCapabilities, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiResourceTeardownRequest, McpUiResourceTeardownResult, McpUiSizeChangedNotification, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiRequestDisplayModeRequest } from "./types";
|
|
4
|
+
import { McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiResourceTeardownRequest, McpUiResourceTeardownResult, McpUiSizeChangedNotification, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiRequestDisplayModeRequest } from "./types";
|
|
5
5
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
6
6
|
export { PostMessageTransport } from "./message-transport";
|
|
7
7
|
export * from "./types";
|
|
@@ -11,7 +11,7 @@ export { applyHostStyleVariables, applyHostFonts, getDocumentTheme, applyDocumen
|
|
|
11
11
|
*
|
|
12
12
|
* MCP servers include this key in tool call result metadata to indicate which
|
|
13
13
|
* UI resource should be displayed for the tool. When hosts receive a tool result
|
|
14
|
-
* containing this metadata, they resolve and render the corresponding App.
|
|
14
|
+
* containing this metadata, they resolve and render the corresponding {@link App}.
|
|
15
15
|
*
|
|
16
16
|
* **Note**: This constant is provided for reference. MCP servers set this metadata
|
|
17
17
|
* in their tool handlers; App developers typically don't need to use it directly.
|
|
@@ -39,20 +39,24 @@ export { applyHostStyleVariables, applyHostFonts, getDocumentTheme, applyDocumen
|
|
|
39
39
|
export declare const RESOURCE_URI_META_KEY = "ui/resourceUri";
|
|
40
40
|
/**
|
|
41
41
|
* MIME type for MCP UI resources.
|
|
42
|
+
*
|
|
43
|
+
* Identifies HTML content as an MCP App UI resource.
|
|
44
|
+
*
|
|
45
|
+
* Used by {@link server-helpers!registerAppResource} as the default MIME type for app resources.
|
|
42
46
|
*/
|
|
43
47
|
export declare const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
|
|
44
48
|
/**
|
|
45
|
-
* Options for configuring App behavior.
|
|
49
|
+
* Options for configuring {@link App} behavior.
|
|
46
50
|
*
|
|
47
|
-
* Extends ProtocolOptions from the MCP SDK with App
|
|
51
|
+
* Extends `ProtocolOptions` from the MCP SDK with `App`-specific configuration.
|
|
48
52
|
*
|
|
49
|
-
* @see ProtocolOptions from @modelcontextprotocol/sdk for inherited options
|
|
53
|
+
* @see `ProtocolOptions` from @modelcontextprotocol/sdk for inherited options
|
|
50
54
|
*/
|
|
51
55
|
type AppOptions = ProtocolOptions & {
|
|
52
56
|
/**
|
|
53
|
-
* Automatically report size changes to the host using ResizeObserver
|
|
57
|
+
* Automatically report size changes to the host using `ResizeObserver`.
|
|
54
58
|
*
|
|
55
|
-
* When enabled, the App monitors `document.body` and `document.documentElement`
|
|
59
|
+
* When enabled, the {@link App} monitors `document.body` and `document.documentElement`
|
|
56
60
|
* for size changes and automatically sends `ui/notifications/size-changed`
|
|
57
61
|
* notifications to the host.
|
|
58
62
|
*
|
|
@@ -64,8 +68,8 @@ type RequestHandlerExtra = Parameters<Parameters<App["setRequestHandler"]>[1]>[1
|
|
|
64
68
|
/**
|
|
65
69
|
* Main class for MCP Apps to communicate with their host.
|
|
66
70
|
*
|
|
67
|
-
* The App class provides a framework-agnostic way to build interactive MCP Apps
|
|
68
|
-
* that run inside host applications. It extends the MCP SDK's Protocol class and
|
|
71
|
+
* The `App` class provides a framework-agnostic way to build interactive MCP Apps
|
|
72
|
+
* that run inside host applications. It extends the MCP SDK's `Protocol` class and
|
|
69
73
|
* handles the connection lifecycle, initialization handshake, and bidirectional
|
|
70
74
|
* communication with the host.
|
|
71
75
|
*
|
|
@@ -84,19 +88,20 @@ type RequestHandlerExtra = Parameters<Parameters<App["setRequestHandler"]>[1]>[1
|
|
|
84
88
|
*
|
|
85
89
|
* ## Inherited Methods
|
|
86
90
|
*
|
|
87
|
-
* As a subclass of Protocol
|
|
91
|
+
* As a subclass of `Protocol`, `App` inherits key methods for handling communication:
|
|
88
92
|
* - `setRequestHandler()` - Register handlers for requests from host
|
|
89
93
|
* - `setNotificationHandler()` - Register handlers for notifications from host
|
|
90
94
|
*
|
|
91
|
-
* @see Protocol from @modelcontextprotocol/sdk for all inherited methods
|
|
95
|
+
* @see `Protocol` from @modelcontextprotocol/sdk for all inherited methods
|
|
92
96
|
*
|
|
93
97
|
* ## Notification Setters
|
|
94
98
|
*
|
|
95
|
-
* For common notifications, the App class provides convenient setter properties
|
|
99
|
+
* For common notifications, the `App` class provides convenient setter properties
|
|
96
100
|
* that simplify handler registration:
|
|
97
101
|
* - `ontoolinput` - Complete tool arguments from host
|
|
98
102
|
* - `ontoolinputpartial` - Streaming partial tool arguments
|
|
99
103
|
* - `ontoolresult` - Tool execution results
|
|
104
|
+
* - `ontoolcancelled` - Tool execution was cancelled by user or host
|
|
100
105
|
* - `onhostcontextchanged` - Host context changes (theme, locale, etc.)
|
|
101
106
|
*
|
|
102
107
|
* These setters are convenience wrappers around `setNotificationHandler()`.
|
|
@@ -128,7 +133,7 @@ type RequestHandlerExtra = Parameters<Parameters<App["setRequestHandler"]>[1]>[1
|
|
|
128
133
|
* }
|
|
129
134
|
* );
|
|
130
135
|
*
|
|
131
|
-
* await app.connect(new PostMessageTransport(window.parent));
|
|
136
|
+
* await app.connect(new PostMessageTransport(window.parent, window.parent));
|
|
132
137
|
* ```
|
|
133
138
|
*
|
|
134
139
|
* @example Sending a message to the host's chat
|
|
@@ -151,7 +156,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
151
156
|
*
|
|
152
157
|
* @param _appInfo - App identification (name and version)
|
|
153
158
|
* @param _capabilities - Features and capabilities this app provides
|
|
154
|
-
* @param options - Configuration options including autoResize behavior
|
|
159
|
+
* @param options - Configuration options including `autoResize` behavior
|
|
155
160
|
*
|
|
156
161
|
* @example
|
|
157
162
|
* ```typescript
|
|
@@ -257,7 +262,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
257
262
|
*
|
|
258
263
|
* Register handlers before calling {@link connect} to avoid missing notifications.
|
|
259
264
|
*
|
|
260
|
-
* @param callback - Function called with the tool input params
|
|
265
|
+
* @param callback - Function called with the tool input params ({@link McpUiToolInputNotification.params})
|
|
261
266
|
*
|
|
262
267
|
* @example Using the setter (simpler)
|
|
263
268
|
* ```typescript
|
|
@@ -295,7 +300,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
295
300
|
*
|
|
296
301
|
* Register handlers before calling {@link connect} to avoid missing notifications.
|
|
297
302
|
*
|
|
298
|
-
* @param callback - Function called with each partial tool input update
|
|
303
|
+
* @param callback - Function called with each partial tool input update ({@link McpUiToolInputPartialNotification.params})
|
|
299
304
|
*
|
|
300
305
|
* @example Progressive rendering of tool arguments
|
|
301
306
|
* ```typescript
|
|
@@ -322,7 +327,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
322
327
|
*
|
|
323
328
|
* Register handlers before calling {@link connect} to avoid missing notifications.
|
|
324
329
|
*
|
|
325
|
-
* @param callback - Function called with the tool result
|
|
330
|
+
* @param callback - Function called with the tool result ({@link McpUiToolResultNotification.params})
|
|
326
331
|
*
|
|
327
332
|
* @example Display tool execution results
|
|
328
333
|
* ```typescript
|
|
@@ -354,7 +359,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
354
359
|
*
|
|
355
360
|
* Register handlers before calling {@link connect} to avoid missing notifications.
|
|
356
361
|
*
|
|
357
|
-
* @param callback - Function called when tool execution is cancelled
|
|
362
|
+
* @param callback - Function called when tool execution is cancelled. Receives optional cancellation reason — see {@link McpUiToolCancelledNotification.params}.
|
|
358
363
|
*
|
|
359
364
|
* @example Handle tool cancellation
|
|
360
365
|
* ```typescript
|
|
@@ -380,6 +385,10 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
380
385
|
* This setter is a convenience wrapper around `setNotificationHandler()` that
|
|
381
386
|
* automatically handles the notification schema and extracts the params for you.
|
|
382
387
|
*
|
|
388
|
+
* Notification params are automatically merged into the internal host context
|
|
389
|
+
* before the callback is invoked. This means {@link getHostContext} will
|
|
390
|
+
* return the updated values even before your callback runs.
|
|
391
|
+
*
|
|
383
392
|
* Register handlers before calling {@link connect} to avoid missing notifications.
|
|
384
393
|
*
|
|
385
394
|
* @param callback - Function called with the updated host context
|
|
@@ -416,7 +425,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
416
425
|
* Register handlers before calling {@link connect} to avoid missing requests.
|
|
417
426
|
*
|
|
418
427
|
* @param callback - Function called when teardown is requested.
|
|
419
|
-
*
|
|
428
|
+
* Must return `McpUiResourceTeardownResult` (can be an empty object `{}`) or a Promise resolving to it.
|
|
420
429
|
*
|
|
421
430
|
* @example Perform cleanup before teardown
|
|
422
431
|
* ```typescript
|
|
@@ -424,6 +433,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
424
433
|
* await saveState();
|
|
425
434
|
* closeConnections();
|
|
426
435
|
* console.log("App ready for teardown");
|
|
436
|
+
* return {};
|
|
427
437
|
* };
|
|
428
438
|
* ```
|
|
429
439
|
*
|
|
@@ -477,9 +487,9 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
477
487
|
*
|
|
478
488
|
* Register handlers before calling {@link connect} to avoid missing requests.
|
|
479
489
|
*
|
|
480
|
-
* @param callback - Async function that returns
|
|
481
|
-
*
|
|
482
|
-
*
|
|
490
|
+
* @param callback - Async function that returns tool names as strings (simplified
|
|
491
|
+
* from full `ListToolsResult` with `Tool` objects). Registration is always
|
|
492
|
+
* allowed; capability validation occurs when handlers are invoked.
|
|
483
493
|
*
|
|
484
494
|
* @example Return available tools
|
|
485
495
|
* ```typescript
|
|
@@ -608,6 +618,47 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
608
618
|
* @returns Promise that resolves when the log notification is sent
|
|
609
619
|
*/
|
|
610
620
|
sendLog(params: LoggingMessageNotification["params"]): Promise<void>;
|
|
621
|
+
/**
|
|
622
|
+
* Update the host's model context with app state.
|
|
623
|
+
*
|
|
624
|
+
* Unlike `sendLog`, which is for debugging/telemetry, context updates
|
|
625
|
+
* are intended to be available to the model in future reasoning,
|
|
626
|
+
* without requiring a follow-up action (like `sendMessage`).
|
|
627
|
+
*
|
|
628
|
+
* The host will typically defer sending the context to the model until the
|
|
629
|
+
* next user message (including `ui/message`), and will only send the last
|
|
630
|
+
* update received. Each call overwrites any previous context update.
|
|
631
|
+
*
|
|
632
|
+
* @param params - Context content and/or structured content
|
|
633
|
+
* @param options - Request options (timeout, etc.)
|
|
634
|
+
*
|
|
635
|
+
* @throws {Error} If the host rejects the context update (e.g., unsupported content type)
|
|
636
|
+
*
|
|
637
|
+
* @example Update model context with current app state
|
|
638
|
+
* ```typescript
|
|
639
|
+
* await app.updateModelContext({
|
|
640
|
+
* content: [{ type: "text", text: "User selected 3 items totaling $150.00" }]
|
|
641
|
+
* });
|
|
642
|
+
* ```
|
|
643
|
+
*
|
|
644
|
+
* @example Update with structured content
|
|
645
|
+
* ```typescript
|
|
646
|
+
* await app.updateModelContext({
|
|
647
|
+
* structuredContent: { selectedItems: 3, total: 150.00, currency: "USD" }
|
|
648
|
+
* });
|
|
649
|
+
* ```
|
|
650
|
+
*
|
|
651
|
+
* @returns Promise that resolves when the context update is acknowledged
|
|
652
|
+
*/
|
|
653
|
+
updateModelContext(params: McpUiUpdateModelContextRequest["params"], options?: RequestOptions): Promise<{
|
|
654
|
+
_meta?: {
|
|
655
|
+
[x: string]: unknown;
|
|
656
|
+
progressToken?: string | number | undefined;
|
|
657
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
658
|
+
taskId: string;
|
|
659
|
+
} | undefined;
|
|
660
|
+
} | undefined;
|
|
661
|
+
}>;
|
|
611
662
|
/**
|
|
612
663
|
* Request the host to open an external URL in the default browser.
|
|
613
664
|
*
|
|
@@ -727,7 +778,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
727
778
|
* If initialization fails, the connection is automatically closed and an error
|
|
728
779
|
* is thrown.
|
|
729
780
|
*
|
|
730
|
-
* @param transport - Transport layer (typically PostMessageTransport)
|
|
781
|
+
* @param transport - Transport layer (typically {@link PostMessageTransport})
|
|
731
782
|
* @param options - Request options for the initialize request
|
|
732
783
|
*
|
|
733
784
|
* @throws {Error} If initialization fails or connection is lost
|
|
@@ -740,7 +791,7 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
740
791
|
* );
|
|
741
792
|
*
|
|
742
793
|
* try {
|
|
743
|
-
* await app.connect(new PostMessageTransport(window.parent));
|
|
794
|
+
* await app.connect(new PostMessageTransport(window.parent, window.parent));
|
|
744
795
|
* console.log("Connected successfully!");
|
|
745
796
|
* } catch (error) {
|
|
746
797
|
* console.error("Failed to connect:", error);
|