@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-bridge.d.ts
CHANGED
|
@@ -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, Tool, 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";
|
|
@@ -15,7 +15,7 @@ export { PostMessageTransport } from "./message-transport";
|
|
|
15
15
|
*
|
|
16
16
|
* @param tool - A tool object with optional `_meta` property
|
|
17
17
|
* @returns The UI resource URI if valid, undefined if not present
|
|
18
|
-
* @throws Error if resourceUri is present but invalid (not
|
|
18
|
+
* @throws Error if resourceUri is present but invalid (does not start with "ui://")
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```typescript
|
|
@@ -30,13 +30,31 @@ export { PostMessageTransport } from "./message-transport";
|
|
|
30
30
|
* });
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
export declare function getToolUiResourceUri(tool:
|
|
34
|
-
_meta?: Record<string, unknown>;
|
|
35
|
-
}): string | undefined;
|
|
33
|
+
export declare function getToolUiResourceUri(tool: Partial<Tool>): string | undefined;
|
|
36
34
|
/**
|
|
37
|
-
*
|
|
35
|
+
* Build iframe `allow` attribute string from permissions.
|
|
38
36
|
*
|
|
39
|
-
*
|
|
37
|
+
* Maps McpUiResourcePermissions to the Permission Policy allow attribute
|
|
38
|
+
* format used by iframes (e.g., "microphone; clipboard-write").
|
|
39
|
+
*
|
|
40
|
+
* @param permissions - Permissions requested by the UI resource
|
|
41
|
+
* @returns Space-separated permission directives, or empty string if none
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const allow = buildAllowAttribute({ microphone: {}, clipboardWrite: {} });
|
|
46
|
+
* // Returns: "microphone; clipboard-write"
|
|
47
|
+
* iframe.setAttribute("allow", allow);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildAllowAttribute(permissions: McpUiResourcePermissions | undefined): string;
|
|
51
|
+
/**
|
|
52
|
+
* Options for configuring {@link AppBridge} behavior.
|
|
53
|
+
*
|
|
54
|
+
* @property hostContext - Optional initial host context to provide to the Guest UI
|
|
55
|
+
*
|
|
56
|
+
* @see `ProtocolOptions` from @modelcontextprotocol/sdk for available options
|
|
57
|
+
* @see {@link McpUiHostContext} for the hostContext structure
|
|
40
58
|
*/
|
|
41
59
|
export type HostOptions = ProtocolOptions & {
|
|
42
60
|
hostContext?: McpUiHostContext;
|
|
@@ -51,7 +69,7 @@ export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
|
|
|
51
69
|
/**
|
|
52
70
|
* Extra metadata passed to request handlers.
|
|
53
71
|
*
|
|
54
|
-
* This type represents the additional context provided by the Protocol class
|
|
72
|
+
* This type represents the additional context provided by the `Protocol` class
|
|
55
73
|
* when handling requests, including abort signals and session information.
|
|
56
74
|
* It is extracted from the MCP SDK's request handler signature.
|
|
57
75
|
*
|
|
@@ -59,12 +77,13 @@ export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
|
|
|
59
77
|
*/
|
|
60
78
|
type RequestHandlerExtra = Parameters<Parameters<AppBridge["setRequestHandler"]>[1]>[1];
|
|
61
79
|
/**
|
|
62
|
-
* Host-side bridge for communicating with a single Guest UI (App).
|
|
80
|
+
* Host-side bridge for communicating with a single Guest UI ({@link app!App}).
|
|
63
81
|
*
|
|
64
|
-
* AppBridge extends the MCP SDK's Protocol class and acts as a proxy between
|
|
65
|
-
* the host application and a Guest UI running in an iframe.
|
|
66
|
-
*
|
|
67
|
-
*
|
|
82
|
+
* `AppBridge` extends the MCP SDK's `Protocol` class and acts as a proxy between
|
|
83
|
+
* the host application and a Guest UI running in an iframe. When an MCP client
|
|
84
|
+
* is provided to the constructor, it automatically forwards MCP server capabilities
|
|
85
|
+
* (tools, resources, prompts) to the Guest UI. It also handles the initialization
|
|
86
|
+
* handshake.
|
|
68
87
|
*
|
|
69
88
|
* ## Architecture
|
|
70
89
|
*
|
|
@@ -76,11 +95,11 @@ type RequestHandlerExtra = Parameters<Parameters<AppBridge["setRequestHandler"]>
|
|
|
76
95
|
*
|
|
77
96
|
* ## Lifecycle
|
|
78
97
|
*
|
|
79
|
-
* 1. **Create**: Instantiate AppBridge with MCP client and capabilities
|
|
98
|
+
* 1. **Create**: Instantiate `AppBridge` with MCP client and capabilities
|
|
80
99
|
* 2. **Connect**: Call `connect()` with transport to establish communication
|
|
81
100
|
* 3. **Wait for init**: Guest UI sends initialize request, bridge responds
|
|
82
|
-
* 4. **Send data**: Call
|
|
83
|
-
* 5. **Teardown**: Call
|
|
101
|
+
* 4. **Send data**: Call {@link sendToolInput}, {@link sendToolResult}, etc.
|
|
102
|
+
* 5. **Teardown**: Call {@link teardownResource} before unmounting iframe
|
|
84
103
|
*
|
|
85
104
|
* @example Basic usage
|
|
86
105
|
* ```typescript
|
|
@@ -130,7 +149,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
130
149
|
* @param _client - MCP client connected to the server, or `null`. When provided,
|
|
131
150
|
* {@link connect} will automatically set up forwarding of MCP requests/notifications
|
|
132
151
|
* between the Guest UI and the server. When `null`, you must register handlers
|
|
133
|
-
* manually using the
|
|
152
|
+
* manually using the {@link oncalltool}, {@link onlistresources}, etc. setters.
|
|
134
153
|
* @param _hostInfo - Host application identification (name and version)
|
|
135
154
|
* @param _capabilities - Features and capabilities the host supports
|
|
136
155
|
* @param options - Configuration options (inherited from Protocol)
|
|
@@ -200,7 +219,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
200
219
|
* Optional handler for ping requests from the Guest UI.
|
|
201
220
|
*
|
|
202
221
|
* The Guest UI can send standard MCP `ping` requests to verify the connection
|
|
203
|
-
* is alive. The AppBridge automatically responds with an empty object, but this
|
|
222
|
+
* is alive. The {@link AppBridge} automatically responds with an empty object, but this
|
|
204
223
|
* handler allows the host to observe or log ping activity.
|
|
205
224
|
*
|
|
206
225
|
* Unlike the other handlers which use setters, this is a direct property
|
|
@@ -221,7 +240,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
221
240
|
* Register a handler for size change notifications from the Guest UI.
|
|
222
241
|
*
|
|
223
242
|
* The Guest UI sends `ui/notifications/size-changed` when its rendered content
|
|
224
|
-
* size changes, typically via ResizeObserver
|
|
243
|
+
* size changes, typically via `ResizeObserver`. Set this callback to dynamically
|
|
225
244
|
* adjust the iframe container dimensions based on the Guest UI's content.
|
|
226
245
|
*
|
|
227
246
|
* Note: This is for Guest UI → Host communication. To notify the Guest UI of
|
|
@@ -240,7 +259,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
240
259
|
* ```
|
|
241
260
|
*
|
|
242
261
|
* @see {@link McpUiSizeChangedNotification} for the notification type
|
|
243
|
-
* @see {@link app
|
|
262
|
+
* @see {@link app!App.sendSizeChanged} - the Guest UI method that sends these notifications
|
|
244
263
|
*/
|
|
245
264
|
set onsizechange(callback: (params: McpUiSizeChangedNotification["params"]) => void);
|
|
246
265
|
/**
|
|
@@ -305,10 +324,10 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
305
324
|
* leakage.
|
|
306
325
|
*
|
|
307
326
|
* @param callback - Handler that receives message params and returns a result
|
|
308
|
-
* - params.role - Message role (currently only "user" is supported)
|
|
309
|
-
* - params.content - Message content blocks (text, image, etc.)
|
|
310
|
-
* - extra - Request metadata (abort signal, session info)
|
|
311
|
-
* - Returns: Promise<McpUiMessageResult
|
|
327
|
+
* - `params.role` - Message role (currently only "user" is supported)
|
|
328
|
+
* - `params.content` - Message content blocks (text, image, etc.)
|
|
329
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
330
|
+
* - Returns: `Promise<McpUiMessageResult>` with optional `isError` flag
|
|
312
331
|
*
|
|
313
332
|
* @example
|
|
314
333
|
* ```typescript
|
|
@@ -341,9 +360,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
341
360
|
* - Reject the request entirely
|
|
342
361
|
*
|
|
343
362
|
* @param callback - Handler that receives URL params and returns a result
|
|
344
|
-
* - params.url - URL to open in the host's browser
|
|
345
|
-
* - extra - Request metadata (abort signal, session info)
|
|
346
|
-
* - Returns: Promise<McpUiOpenLinkResult
|
|
363
|
+
* - `params.url` - URL to open in the host's browser
|
|
364
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
365
|
+
* - Returns: `Promise<McpUiOpenLinkResult>` with optional `isError` flag
|
|
347
366
|
*
|
|
348
367
|
* @example
|
|
349
368
|
* ```typescript
|
|
@@ -382,17 +401,22 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
382
401
|
* If the requested mode is not available, the handler should return the current
|
|
383
402
|
* display mode instead.
|
|
384
403
|
*
|
|
404
|
+
* By default, `AppBridge` returns the current `displayMode` from host context (or "inline").
|
|
405
|
+
* Setting this property replaces that default behavior.
|
|
406
|
+
*
|
|
385
407
|
* @param callback - Handler that receives the requested mode and returns the actual mode set
|
|
386
|
-
* - params.mode - The display mode being requested ("inline" | "fullscreen" | "pip")
|
|
387
|
-
* - extra - Request metadata (abort signal, session info)
|
|
388
|
-
* - Returns: Promise<McpUiRequestDisplayModeResult
|
|
408
|
+
* - `params.mode` - The display mode being requested ("inline" | "fullscreen" | "pip")
|
|
409
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
410
|
+
* - Returns: `Promise<McpUiRequestDisplayModeResult>` with the actual mode set
|
|
389
411
|
*
|
|
390
412
|
* @example
|
|
391
413
|
* ```typescript
|
|
414
|
+
* let currentDisplayMode: McpUiDisplayMode = "inline";
|
|
415
|
+
*
|
|
392
416
|
* bridge.onrequestdisplaymode = async ({ mode }, extra) => {
|
|
393
417
|
* const availableModes = hostContext.availableDisplayModes ?? ["inline"];
|
|
394
418
|
* if (availableModes.includes(mode)) {
|
|
395
|
-
*
|
|
419
|
+
* currentDisplayMode = mode;
|
|
396
420
|
* return { mode };
|
|
397
421
|
* }
|
|
398
422
|
* // Return current mode if requested mode not available
|
|
@@ -416,9 +440,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
416
440
|
* message type.
|
|
417
441
|
*
|
|
418
442
|
* @param callback - Handler that receives logging params
|
|
419
|
-
* - params.level - Log level: "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"
|
|
420
|
-
* - params.logger - Optional logger name/identifier
|
|
421
|
-
* - params.data - Log message and optional structured data
|
|
443
|
+
* - `params.level` - Log level: "debug" | "info" | "notice" | "warning" | "error" | "critical" | "alert" | "emergency"
|
|
444
|
+
* - `params.logger` - Optional logger name/identifier
|
|
445
|
+
* - `params.data` - Log message and optional structured data
|
|
422
446
|
*
|
|
423
447
|
* @example
|
|
424
448
|
* ```typescript
|
|
@@ -432,6 +456,35 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
432
456
|
* ```
|
|
433
457
|
*/
|
|
434
458
|
set onloggingmessage(callback: (params: LoggingMessageNotification["params"]) => void);
|
|
459
|
+
/**
|
|
460
|
+
* Register a handler for model context updates from the Guest UI.
|
|
461
|
+
*
|
|
462
|
+
* The Guest UI sends `ui/update-model-context` requests to update the Host's
|
|
463
|
+
* model context. Each request overwrites the previous context stored by the Guest UI.
|
|
464
|
+
* Unlike logging messages, context updates are intended to be available to
|
|
465
|
+
* the model in future turns. Unlike messages, context updates do not trigger follow-ups.
|
|
466
|
+
*
|
|
467
|
+
* The host will typically defer sending the context to the model until the
|
|
468
|
+
* next user message (including `ui/message`), and will only send the last
|
|
469
|
+
* update received.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* bridge.onupdatemodelcontext = async ({ content, structuredContent }, extra) => {
|
|
474
|
+
* // Update the model context with the new snapshot
|
|
475
|
+
* modelContext = {
|
|
476
|
+
* type: "app_context",
|
|
477
|
+
* content,
|
|
478
|
+
* structuredContent,
|
|
479
|
+
* timestamp: Date.now()
|
|
480
|
+
* };
|
|
481
|
+
* return {};
|
|
482
|
+
* };
|
|
483
|
+
* ```
|
|
484
|
+
*
|
|
485
|
+
* @see {@link McpUiUpdateModelContextRequest} for the request type
|
|
486
|
+
*/
|
|
487
|
+
set onupdatemodelcontext(callback: (params: McpUiUpdateModelContextRequest["params"], extra: RequestHandlerExtra) => Promise<EmptyResult>);
|
|
435
488
|
/**
|
|
436
489
|
* Register a handler for tool call requests from the Guest UI.
|
|
437
490
|
*
|
|
@@ -440,9 +493,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
440
493
|
* by forwarding them to the MCP server.
|
|
441
494
|
*
|
|
442
495
|
* @param callback - Handler that receives tool call params and returns a
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
496
|
+
* `CallToolResult`
|
|
497
|
+
* - `params` - Tool call parameters (name and arguments)
|
|
498
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
446
499
|
*
|
|
447
500
|
* @example
|
|
448
501
|
* ```typescript
|
|
@@ -455,8 +508,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
455
508
|
* };
|
|
456
509
|
* ```
|
|
457
510
|
*
|
|
458
|
-
* @see
|
|
459
|
-
* @see
|
|
511
|
+
* @see `CallToolRequest` from @modelcontextprotocol/sdk for the request type
|
|
512
|
+
* @see `CallToolResult` from @modelcontextprotocol/sdk for the result type
|
|
460
513
|
*/
|
|
461
514
|
set oncalltool(callback: (params: CallToolRequest["params"], extra: RequestHandlerExtra) => Promise<CallToolResult>);
|
|
462
515
|
/**
|
|
@@ -476,7 +529,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
476
529
|
* });
|
|
477
530
|
* ```
|
|
478
531
|
*
|
|
479
|
-
* @see
|
|
532
|
+
* @see `ToolListChangedNotification` from @modelcontextprotocol/sdk for the notification type
|
|
480
533
|
*/
|
|
481
534
|
sendToolListChanged(params?: ToolListChangedNotification["params"]): Promise<void>;
|
|
482
535
|
/**
|
|
@@ -487,9 +540,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
487
540
|
* requests, typically by forwarding them to the MCP server.
|
|
488
541
|
*
|
|
489
542
|
* @param callback - Handler that receives list params and returns a
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
543
|
+
* `ListResourcesResult`
|
|
544
|
+
* - `params` - Request params (may include cursor for pagination)
|
|
545
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
493
546
|
*
|
|
494
547
|
* @example
|
|
495
548
|
* ```typescript
|
|
@@ -502,8 +555,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
502
555
|
* };
|
|
503
556
|
* ```
|
|
504
557
|
*
|
|
505
|
-
* @see
|
|
506
|
-
* @see
|
|
558
|
+
* @see `ListResourcesRequest` from @modelcontextprotocol/sdk for the request type
|
|
559
|
+
* @see `ListResourcesResult` from @modelcontextprotocol/sdk for the result type
|
|
507
560
|
*/
|
|
508
561
|
set onlistresources(callback: (params: ListResourcesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourcesResult>);
|
|
509
562
|
/**
|
|
@@ -514,9 +567,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
514
567
|
* these requests, typically by forwarding them to the MCP server.
|
|
515
568
|
*
|
|
516
569
|
* @param callback - Handler that receives list params and returns a
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
570
|
+
* `ListResourceTemplatesResult`
|
|
571
|
+
* - `params` - Request params (may include cursor for pagination)
|
|
572
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
520
573
|
*
|
|
521
574
|
* @example
|
|
522
575
|
* ```typescript
|
|
@@ -529,8 +582,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
529
582
|
* };
|
|
530
583
|
* ```
|
|
531
584
|
*
|
|
532
|
-
* @see
|
|
533
|
-
* @see
|
|
585
|
+
* @see `ListResourceTemplatesRequest` from @modelcontextprotocol/sdk for the request type
|
|
586
|
+
* @see `ListResourceTemplatesResult` from @modelcontextprotocol/sdk for the result type
|
|
534
587
|
*/
|
|
535
588
|
set onlistresourcetemplates(callback: (params: ListResourceTemplatesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourceTemplatesResult>);
|
|
536
589
|
/**
|
|
@@ -541,9 +594,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
541
594
|
* requests, typically by forwarding them to the MCP server.
|
|
542
595
|
*
|
|
543
596
|
* @param callback - Handler that receives read params and returns a
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
*
|
|
597
|
+
* `ReadResourceResult`
|
|
598
|
+
* - `params` - Read parameters including the resource URI
|
|
599
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
547
600
|
*
|
|
548
601
|
* @example
|
|
549
602
|
* ```typescript
|
|
@@ -556,8 +609,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
556
609
|
* };
|
|
557
610
|
* ```
|
|
558
611
|
*
|
|
559
|
-
* @see
|
|
560
|
-
* @see
|
|
612
|
+
* @see `ReadResourceRequest` from @modelcontextprotocol/sdk for the request type
|
|
613
|
+
* @see `ReadResourceResult` from @modelcontextprotocol/sdk for the result type
|
|
561
614
|
*/
|
|
562
615
|
set onreadresource(callback: (params: ReadResourceRequest["params"], extra: RequestHandlerExtra) => Promise<ReadResourceResult>);
|
|
563
616
|
/**
|
|
@@ -577,7 +630,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
577
630
|
* });
|
|
578
631
|
* ```
|
|
579
632
|
*
|
|
580
|
-
* @see
|
|
633
|
+
* @see `ResourceListChangedNotification` from @modelcontextprotocol/sdk for the notification type
|
|
581
634
|
*/
|
|
582
635
|
sendResourceListChanged(params?: ResourceListChangedNotification["params"]): Promise<void>;
|
|
583
636
|
/**
|
|
@@ -588,9 +641,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
588
641
|
* requests, typically by forwarding them to the MCP server.
|
|
589
642
|
*
|
|
590
643
|
* @param callback - Handler that receives list params and returns a
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
644
|
+
* `ListPromptsResult`
|
|
645
|
+
* - `params` - Request params (may include cursor for pagination)
|
|
646
|
+
* - `extra` - Request metadata (abort signal, session info)
|
|
594
647
|
*
|
|
595
648
|
* @example
|
|
596
649
|
* ```typescript
|
|
@@ -603,8 +656,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
603
656
|
* };
|
|
604
657
|
* ```
|
|
605
658
|
*
|
|
606
|
-
* @see
|
|
607
|
-
* @see
|
|
659
|
+
* @see `ListPromptsRequest` from @modelcontextprotocol/sdk for the request type
|
|
660
|
+
* @see `ListPromptsResult` from @modelcontextprotocol/sdk for the result type
|
|
608
661
|
*/
|
|
609
662
|
set onlistprompts(callback: (params: ListPromptsRequest["params"], extra: RequestHandlerExtra) => Promise<ListPromptsResult>);
|
|
610
663
|
/**
|
|
@@ -624,7 +677,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
624
677
|
* });
|
|
625
678
|
* ```
|
|
626
679
|
*
|
|
627
|
-
* @see
|
|
680
|
+
* @see `PromptListChangedNotification` from @modelcontextprotocol/sdk for the notification type
|
|
628
681
|
*/
|
|
629
682
|
sendPromptListChanged(params?: PromptListChangedNotification["params"]): Promise<void>;
|
|
630
683
|
/**
|
|
@@ -668,9 +721,10 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
668
721
|
/**
|
|
669
722
|
* Update the host context and notify the Guest UI of changes.
|
|
670
723
|
*
|
|
671
|
-
* Compares the new context with the current context and sends a
|
|
672
|
-
* `ui/notifications/host-context-changed` notification containing only
|
|
673
|
-
*
|
|
724
|
+
* Compares fields present in the new context with the current context and sends a
|
|
725
|
+
* `ui/notifications/host-context-changed` notification containing only fields
|
|
726
|
+
* that have been added or modified. If no fields have changed, no notification is sent.
|
|
727
|
+
* The new context fully replaces the internal state.
|
|
674
728
|
*
|
|
675
729
|
* Common use cases include notifying the Guest UI when:
|
|
676
730
|
* - Theme changes (light/dark mode toggle)
|
|
@@ -698,8 +752,13 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
698
752
|
*/
|
|
699
753
|
setHostContext(hostContext: McpUiHostContext): void;
|
|
700
754
|
/**
|
|
701
|
-
*
|
|
702
|
-
*
|
|
755
|
+
* Low-level method to notify the Guest UI of host context changes.
|
|
756
|
+
*
|
|
757
|
+
* Most hosts should use {@link setHostContext} instead, which automatically
|
|
758
|
+
* detects changes and calls this method with only the modified fields.
|
|
759
|
+
* Use this directly only when you need fine-grained control over change detection.
|
|
760
|
+
*
|
|
761
|
+
* @param params - The context fields that have changed (partial update)
|
|
703
762
|
*/
|
|
704
763
|
sendHostContextChange(params: McpUiHostContextChangedNotification["params"]): Promise<void> | void;
|
|
705
764
|
/**
|
|
@@ -786,7 +845,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
786
845
|
* any other interruption. This allows the Guest UI to update its state and
|
|
787
846
|
* display appropriate feedback to the user.
|
|
788
847
|
*
|
|
789
|
-
* @param params -
|
|
848
|
+
* @param params - Cancellation details object
|
|
790
849
|
* - `reason`: Human-readable explanation for why the tool was cancelled
|
|
791
850
|
*
|
|
792
851
|
* @example User-initiated cancellation
|
|
@@ -863,13 +922,13 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
863
922
|
* - Prompts (prompts/list, notifications/prompts/list_changed)
|
|
864
923
|
*
|
|
865
924
|
* If no client was passed to the constructor, no automatic forwarding is set up
|
|
866
|
-
* and you must register handlers manually using the
|
|
925
|
+
* and you must register handlers manually using the {@link oncalltool}, {@link onlistresources},
|
|
867
926
|
* etc. setters.
|
|
868
927
|
*
|
|
869
|
-
* After calling connect, wait for the
|
|
928
|
+
* After calling connect, wait for the {@link oninitialized} callback before sending
|
|
870
929
|
* tool input and other data to the Guest UI.
|
|
871
930
|
*
|
|
872
|
-
* @param transport - Transport layer (typically PostMessageTransport)
|
|
931
|
+
* @param transport - Transport layer (typically {@link PostMessageTransport})
|
|
873
932
|
* @returns Promise resolving when connection is established
|
|
874
933
|
*
|
|
875
934
|
* @throws {Error} If a client was passed but server capabilities are not available.
|