@modelcontextprotocol/ext-apps 0.4.1 → 0.4.2
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 +266 -28
- package/dist/docs/patterns.d.ts +9 -0
- package/dist/src/app-bridge.d.ts +187 -194
- package/dist/src/app-bridge.examples.d.ts +9 -0
- package/dist/src/app-bridge.js +17 -17
- package/dist/src/app-with-deps.js +9 -9
- package/dist/src/app.d.ts +224 -197
- package/dist/src/app.examples.d.ts +9 -0
- package/dist/src/app.js +10 -10
- package/dist/src/generated/schema.d.ts +45 -33
- package/dist/src/generated/schema.test.d.ts +1 -0
- package/dist/src/message-transport.d.ts +17 -17
- package/dist/src/message-transport.examples.d.ts +9 -0
- package/dist/src/react/index.d.ts +8 -10
- package/dist/src/react/index.examples.d.ts +6 -0
- package/dist/src/react/index.js +8 -8
- package/dist/src/react/react-with-deps.js +8 -8
- package/dist/src/react/useApp.d.ts +45 -36
- package/dist/src/react/useApp.examples.d.ts +6 -0
- package/dist/src/react/useAutoResize.d.ts +10 -9
- package/dist/src/react/useAutoResize.examples.d.ts +6 -0
- package/dist/src/react/useDocumentTheme.d.ts +11 -15
- package/dist/src/react/useDocumentTheme.examples.d.ts +6 -0
- package/dist/src/react/useHostStyles.d.ts +33 -42
- package/dist/src/react/useHostStyles.examples.d.ts +6 -0
- package/dist/src/server/index.d.ts +169 -88
- package/dist/src/server/index.examples.d.ts +9 -0
- package/dist/src/server/index.js +9 -9
- package/dist/src/spec.types.d.ts +51 -35
- package/dist/src/styles.d.ts +71 -28
- package/dist/src/styles.examples.d.ts +9 -0
- package/dist/src/types.d.ts +1 -1
- package/package.json +25 -8
package/dist/src/app-bridge.d.ts
CHANGED
|
@@ -49,12 +49,12 @@ export declare function getToolUiResourceUri(tool: Partial<Tool>): string | unde
|
|
|
49
49
|
*/
|
|
50
50
|
export declare function buildAllowAttribute(permissions: McpUiResourcePermissions | undefined): string;
|
|
51
51
|
/**
|
|
52
|
-
* Options for configuring {@link AppBridge} behavior.
|
|
52
|
+
* Options for configuring {@link AppBridge `AppBridge`} behavior.
|
|
53
53
|
*
|
|
54
|
-
* @property hostContext - Optional initial host context to provide to the
|
|
54
|
+
* @property hostContext - Optional initial host context to provide to the view
|
|
55
55
|
*
|
|
56
56
|
* @see `ProtocolOptions` from @modelcontextprotocol/sdk for available options
|
|
57
|
-
* @see {@link McpUiHostContext} for the hostContext structure
|
|
57
|
+
* @see {@link McpUiHostContext `McpUiHostContext`} for the hostContext structure
|
|
58
58
|
*/
|
|
59
59
|
export type HostOptions = ProtocolOptions & {
|
|
60
60
|
hostContext?: McpUiHostContext;
|
|
@@ -77,35 +77,32 @@ export declare const SUPPORTED_PROTOCOL_VERSIONS: string[];
|
|
|
77
77
|
*/
|
|
78
78
|
type RequestHandlerExtra = Parameters<Parameters<AppBridge["setRequestHandler"]>[1]>[1];
|
|
79
79
|
/**
|
|
80
|
-
* Host-side bridge for communicating with a single
|
|
80
|
+
* Host-side bridge for communicating with a single View ({@link app!App `App`}).
|
|
81
81
|
*
|
|
82
82
|
* `AppBridge` extends the MCP SDK's `Protocol` class and acts as a proxy between
|
|
83
|
-
* the host application and a
|
|
83
|
+
* the host application and a view running in an iframe. When an MCP client
|
|
84
84
|
* is provided to the constructor, it automatically forwards MCP server capabilities
|
|
85
|
-
* (tools, resources, prompts) to the
|
|
85
|
+
* (tools, resources, prompts) to the view. It also handles the initialization
|
|
86
86
|
* handshake.
|
|
87
87
|
*
|
|
88
88
|
* ## Architecture
|
|
89
89
|
*
|
|
90
|
-
* **
|
|
90
|
+
* **View ↔ AppBridge ↔ Host ↔ MCP Server**
|
|
91
91
|
*
|
|
92
|
-
* The bridge proxies requests from the
|
|
92
|
+
* The bridge proxies requests from the view to the MCP server and forwards
|
|
93
93
|
* responses back. It also sends host-initiated notifications like tool input
|
|
94
|
-
* and results to the
|
|
94
|
+
* and results to the view.
|
|
95
95
|
*
|
|
96
96
|
* ## Lifecycle
|
|
97
97
|
*
|
|
98
98
|
* 1. **Create**: Instantiate `AppBridge` with MCP client and capabilities
|
|
99
99
|
* 2. **Connect**: Call `connect()` with transport to establish communication
|
|
100
|
-
* 3. **Wait for init**:
|
|
101
|
-
* 4. **Send data**: Call {@link sendToolInput}, {@link sendToolResult}, etc.
|
|
102
|
-
* 5. **Teardown**: Call {@link teardownResource} before unmounting iframe
|
|
100
|
+
* 3. **Wait for init**: View sends initialize request, bridge responds
|
|
101
|
+
* 4. **Send data**: Call {@link sendToolInput `sendToolInput`}, {@link sendToolResult `sendToolResult`}, etc.
|
|
102
|
+
* 5. **Teardown**: Call {@link teardownResource `teardownResource`} before unmounting iframe
|
|
103
103
|
*
|
|
104
104
|
* @example Basic usage
|
|
105
|
-
* ```
|
|
106
|
-
* import { AppBridge, PostMessageTransport } from '@modelcontextprotocol/ext-apps/app-bridge';
|
|
107
|
-
* import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
108
|
-
*
|
|
105
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_basicUsage"
|
|
109
106
|
* // Create MCP client for the server
|
|
110
107
|
* const client = new Client({
|
|
111
108
|
* name: "MyHost",
|
|
@@ -113,22 +110,22 @@ type RequestHandlerExtra = Parameters<Parameters<AppBridge["setRequestHandler"]>
|
|
|
113
110
|
* });
|
|
114
111
|
* await client.connect(serverTransport);
|
|
115
112
|
*
|
|
116
|
-
* // Create bridge for the
|
|
113
|
+
* // Create bridge for the View
|
|
117
114
|
* const bridge = new AppBridge(
|
|
118
115
|
* client,
|
|
119
116
|
* { name: "MyHost", version: "1.0.0" },
|
|
120
|
-
* { openLinks: {}, serverTools: {}, logging: {} }
|
|
117
|
+
* { openLinks: {}, serverTools: {}, logging: {} },
|
|
121
118
|
* );
|
|
122
119
|
*
|
|
123
120
|
* // Set up iframe and connect
|
|
124
|
-
* const iframe = document.getElementById(
|
|
121
|
+
* const iframe = document.getElementById("app") as HTMLIFrameElement;
|
|
125
122
|
* const transport = new PostMessageTransport(
|
|
126
123
|
* iframe.contentWindow!,
|
|
127
124
|
* iframe.contentWindow!,
|
|
128
125
|
* );
|
|
129
126
|
*
|
|
130
127
|
* bridge.oninitialized = () => {
|
|
131
|
-
* console.log("
|
|
128
|
+
* console.log("View initialized");
|
|
132
129
|
* // Now safe to send tool input
|
|
133
130
|
* bridge.sendToolInput({ arguments: { location: "NYC" } });
|
|
134
131
|
* };
|
|
@@ -147,79 +144,82 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
147
144
|
* Create a new AppBridge instance.
|
|
148
145
|
*
|
|
149
146
|
* @param _client - MCP client connected to the server, or `null`. When provided,
|
|
150
|
-
* {@link connect} will automatically set up forwarding of MCP requests/notifications
|
|
151
|
-
* between the
|
|
152
|
-
* manually using the {@link oncalltool}, {@link onlistresources}, etc. setters.
|
|
147
|
+
* {@link connect `connect`} will automatically set up forwarding of MCP requests/notifications
|
|
148
|
+
* between the View and the server. When `null`, you must register handlers
|
|
149
|
+
* manually using the {@link oncalltool `oncalltool`}, {@link onlistresources `onlistresources`}, etc. setters.
|
|
153
150
|
* @param _hostInfo - Host application identification (name and version)
|
|
154
151
|
* @param _capabilities - Features and capabilities the host supports
|
|
155
152
|
* @param options - Configuration options (inherited from Protocol)
|
|
156
153
|
*
|
|
157
154
|
* @example With MCP client (automatic forwarding)
|
|
158
|
-
* ```
|
|
155
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_constructor_withMcpClient"
|
|
159
156
|
* const bridge = new AppBridge(
|
|
160
157
|
* mcpClient,
|
|
161
158
|
* { name: "MyHost", version: "1.0.0" },
|
|
162
|
-
* { openLinks: {}, serverTools: {}, logging: {} }
|
|
159
|
+
* { openLinks: {}, serverTools: {}, logging: {} },
|
|
163
160
|
* );
|
|
164
161
|
* ```
|
|
165
162
|
*
|
|
166
163
|
* @example Without MCP client (manual handlers)
|
|
167
|
-
* ```
|
|
164
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_constructor_withoutMcpClient"
|
|
168
165
|
* const bridge = new AppBridge(
|
|
169
166
|
* null,
|
|
170
167
|
* { name: "MyHost", version: "1.0.0" },
|
|
171
|
-
* { openLinks: {}, serverTools: {}, logging: {} }
|
|
168
|
+
* { openLinks: {}, serverTools: {}, logging: {} },
|
|
172
169
|
* );
|
|
173
|
-
* bridge.oncalltool = async (params, extra) => {
|
|
170
|
+
* bridge.oncalltool = async (params, extra) => {
|
|
171
|
+
* // Handle tool calls manually
|
|
172
|
+
* return { content: [] };
|
|
173
|
+
* };
|
|
174
174
|
* ```
|
|
175
175
|
*/
|
|
176
176
|
constructor(_client: Client | null, _hostInfo: Implementation, _capabilities: McpUiHostCapabilities, options?: HostOptions);
|
|
177
177
|
/**
|
|
178
|
-
* Get the
|
|
178
|
+
* Get the view's capabilities discovered during initialization.
|
|
179
179
|
*
|
|
180
|
-
* Returns the capabilities that the
|
|
180
|
+
* Returns the capabilities that the view advertised during its
|
|
181
181
|
* initialization request. Returns `undefined` if called before
|
|
182
182
|
* initialization completes.
|
|
183
183
|
*
|
|
184
|
-
* @returns
|
|
184
|
+
* @returns view capabilities, or `undefined` if not yet initialized
|
|
185
185
|
*
|
|
186
|
-
* @example Check
|
|
187
|
-
* ```
|
|
186
|
+
* @example Check view capabilities after initialization
|
|
187
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_getAppCapabilities_checkAfterInit"
|
|
188
188
|
* bridge.oninitialized = () => {
|
|
189
189
|
* const caps = bridge.getAppCapabilities();
|
|
190
190
|
* if (caps?.tools) {
|
|
191
|
-
* console.log("
|
|
191
|
+
* console.log("View provides tools");
|
|
192
192
|
* }
|
|
193
193
|
* };
|
|
194
194
|
* ```
|
|
195
195
|
*
|
|
196
|
-
* @see {@link McpUiAppCapabilities} for the capabilities structure
|
|
196
|
+
* @see {@link McpUiAppCapabilities `McpUiAppCapabilities`} for the capabilities structure
|
|
197
197
|
*/
|
|
198
198
|
getAppCapabilities(): McpUiAppCapabilities | undefined;
|
|
199
199
|
/**
|
|
200
|
-
* Get the
|
|
200
|
+
* Get the view's implementation info discovered during initialization.
|
|
201
201
|
*
|
|
202
|
-
* Returns the
|
|
202
|
+
* Returns the view's name and version as provided in its initialization
|
|
203
203
|
* request. Returns `undefined` if called before initialization completes.
|
|
204
204
|
*
|
|
205
|
-
* @returns
|
|
205
|
+
* @returns view implementation info, or `undefined` if not yet initialized
|
|
206
206
|
*
|
|
207
|
-
* @example Log
|
|
208
|
-
* ```
|
|
207
|
+
* @example Log view information after initialization
|
|
208
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_getAppVersion_logAfterInit"
|
|
209
209
|
* bridge.oninitialized = () => {
|
|
210
210
|
* const appInfo = bridge.getAppVersion();
|
|
211
211
|
* if (appInfo) {
|
|
212
|
-
* console.log(`
|
|
212
|
+
* console.log(`View: ${appInfo.name} v${appInfo.version}`);
|
|
213
213
|
* }
|
|
214
214
|
* };
|
|
215
215
|
* ```
|
|
216
216
|
*/
|
|
217
217
|
getAppVersion(): Implementation | undefined;
|
|
218
218
|
/**
|
|
219
|
-
* Optional handler for ping requests from the
|
|
219
|
+
* Optional handler for ping requests from the view.
|
|
220
220
|
*
|
|
221
|
-
* The
|
|
222
|
-
* is alive. The {@link AppBridge} automatically responds with an empty object, but this
|
|
221
|
+
* The View can send standard MCP `ping` requests to verify the connection
|
|
222
|
+
* is alive. The {@link AppBridge `AppBridge`} automatically responds with an empty object, but this
|
|
223
223
|
* handler allows the host to observe or log ping activity.
|
|
224
224
|
*
|
|
225
225
|
* Unlike the other handlers which use setters, this is a direct property
|
|
@@ -229,25 +229,25 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
229
229
|
* @param extra - Request metadata (abort signal, session info)
|
|
230
230
|
*
|
|
231
231
|
* @example
|
|
232
|
-
* ```
|
|
232
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onping_handleRequest"
|
|
233
233
|
* bridge.onping = (params, extra) => {
|
|
234
|
-
* console.log("Received ping from
|
|
234
|
+
* console.log("Received ping from view");
|
|
235
235
|
* };
|
|
236
236
|
* ```
|
|
237
237
|
*/
|
|
238
238
|
onping?: (params: PingRequest["params"], extra: RequestHandlerExtra) => void;
|
|
239
239
|
/**
|
|
240
|
-
* Register a handler for size change notifications from the
|
|
240
|
+
* Register a handler for size change notifications from the view.
|
|
241
241
|
*
|
|
242
|
-
* The
|
|
242
|
+
* The view sends `ui/notifications/size-changed` when its rendered content
|
|
243
243
|
* size changes, typically via `ResizeObserver`. Set this callback to dynamically
|
|
244
|
-
* adjust the iframe container dimensions based on the
|
|
244
|
+
* adjust the iframe container dimensions based on the view's content.
|
|
245
245
|
*
|
|
246
|
-
* Note: This is for
|
|
247
|
-
* host container dimension changes, use {@link setHostContext}.
|
|
246
|
+
* Note: This is for View → Host communication. To notify the View of
|
|
247
|
+
* host container dimension changes, use {@link setHostContext `setHostContext`}.
|
|
248
248
|
*
|
|
249
249
|
* @example
|
|
250
|
-
* ```
|
|
250
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onsizechange_handleResize"
|
|
251
251
|
* bridge.onsizechange = ({ width, height }) => {
|
|
252
252
|
* if (width != null) {
|
|
253
253
|
* iframe.style.width = `${width}px`;
|
|
@@ -258,8 +258,8 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
258
258
|
* };
|
|
259
259
|
* ```
|
|
260
260
|
*
|
|
261
|
-
* @see {@link McpUiSizeChangedNotification} for the notification type
|
|
262
|
-
* @see {@link app!App.sendSizeChanged} - the
|
|
261
|
+
* @see {@link McpUiSizeChangedNotification `McpUiSizeChangedNotification`} for the notification type
|
|
262
|
+
* @see {@link app!App.sendSizeChanged `App.sendSizeChanged`} - the View method that sends these notifications
|
|
263
263
|
*/
|
|
264
264
|
set onsizechange(callback: (params: McpUiSizeChangedNotification["params"]) => void);
|
|
265
265
|
/**
|
|
@@ -270,7 +270,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
270
270
|
* `ui/notifications/sandbox-proxy-ready` after it loads and is ready to receive
|
|
271
271
|
* HTML content.
|
|
272
272
|
*
|
|
273
|
-
* When this fires, the host should call {@link sendSandboxResourceReady} with
|
|
273
|
+
* When this fires, the host should call {@link sendSandboxResourceReady `sendSandboxResourceReady`} with
|
|
274
274
|
* the HTML content to load into the inner sandboxed iframe.
|
|
275
275
|
*
|
|
276
276
|
* @example
|
|
@@ -289,32 +289,32 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
289
289
|
* ```
|
|
290
290
|
*
|
|
291
291
|
* @internal
|
|
292
|
-
* @see {@link McpUiSandboxProxyReadyNotification} for the notification type
|
|
293
|
-
* @see {@link sendSandboxResourceReady} for sending content to the sandbox
|
|
292
|
+
* @see {@link McpUiSandboxProxyReadyNotification `McpUiSandboxProxyReadyNotification`} for the notification type
|
|
293
|
+
* @see {@link sendSandboxResourceReady `sendSandboxResourceReady`} for sending content to the sandbox
|
|
294
294
|
*/
|
|
295
295
|
set onsandboxready(callback: (params: McpUiSandboxProxyReadyNotification["params"]) => void);
|
|
296
296
|
/**
|
|
297
|
-
* Called when the
|
|
297
|
+
* Called when the view completes initialization.
|
|
298
298
|
*
|
|
299
|
-
* Set this callback to be notified when the
|
|
299
|
+
* Set this callback to be notified when the view has finished its
|
|
300
300
|
* initialization handshake and is ready to receive tool input and other data.
|
|
301
301
|
*
|
|
302
302
|
* @example
|
|
303
|
-
* ```
|
|
303
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_oninitialized_sendToolInput"
|
|
304
304
|
* bridge.oninitialized = () => {
|
|
305
|
-
* console.log("
|
|
305
|
+
* console.log("View ready");
|
|
306
306
|
* bridge.sendToolInput({ arguments: toolArgs });
|
|
307
307
|
* };
|
|
308
308
|
* ```
|
|
309
309
|
*
|
|
310
|
-
* @see {@link McpUiInitializedNotification} for the notification type
|
|
311
|
-
* @see {@link sendToolInput} for sending tool arguments to the
|
|
310
|
+
* @see {@link McpUiInitializedNotification `McpUiInitializedNotification`} for the notification type
|
|
311
|
+
* @see {@link sendToolInput `sendToolInput`} for sending tool arguments to the View
|
|
312
312
|
*/
|
|
313
313
|
set oninitialized(callback: (params: McpUiInitializedNotification["params"]) => void);
|
|
314
314
|
/**
|
|
315
|
-
* Register a handler for message requests from the
|
|
315
|
+
* Register a handler for message requests from the view.
|
|
316
316
|
*
|
|
317
|
-
* The
|
|
317
|
+
* The view sends `ui/message` requests when it wants to add a message to
|
|
318
318
|
* the host's chat interface. This enables interactive apps to communicate with
|
|
319
319
|
* the user through the conversation thread.
|
|
320
320
|
*
|
|
@@ -330,7 +330,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
330
330
|
* - Returns: `Promise<McpUiMessageResult>` with optional `isError` flag
|
|
331
331
|
*
|
|
332
332
|
* @example
|
|
333
|
-
* ```
|
|
333
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onmessage_logMessage"
|
|
334
334
|
* bridge.onmessage = async ({ role, content }, extra) => {
|
|
335
335
|
* try {
|
|
336
336
|
* await chatManager.addMessage({ role, content, source: "app" });
|
|
@@ -342,14 +342,14 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
342
342
|
* };
|
|
343
343
|
* ```
|
|
344
344
|
*
|
|
345
|
-
* @see {@link McpUiMessageRequest} for the request type
|
|
346
|
-
* @see {@link McpUiMessageResult} for the result type
|
|
345
|
+
* @see {@link McpUiMessageRequest `McpUiMessageRequest`} for the request type
|
|
346
|
+
* @see {@link McpUiMessageResult `McpUiMessageResult`} for the result type
|
|
347
347
|
*/
|
|
348
348
|
set onmessage(callback: (params: McpUiMessageRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiMessageResult>);
|
|
349
349
|
/**
|
|
350
|
-
* Register a handler for external link requests from the
|
|
350
|
+
* Register a handler for external link requests from the view.
|
|
351
351
|
*
|
|
352
|
-
* The
|
|
352
|
+
* The view sends `ui/open-link` requests when it wants to open an external
|
|
353
353
|
* URL in the host's default browser. The handler should validate the URL and
|
|
354
354
|
* open it according to the host's security policy and user preferences.
|
|
355
355
|
*
|
|
@@ -365,7 +365,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
365
365
|
* - Returns: `Promise<McpUiOpenLinkResult>` with optional `isError` flag
|
|
366
366
|
*
|
|
367
367
|
* @example
|
|
368
|
-
* ```
|
|
368
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onopenlink_handleRequest"
|
|
369
369
|
* bridge.onopenlink = async ({ url }, extra) => {
|
|
370
370
|
* if (!isAllowedDomain(url)) {
|
|
371
371
|
* console.warn("Blocked external link:", url);
|
|
@@ -374,7 +374,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
374
374
|
*
|
|
375
375
|
* const confirmed = await showDialog({
|
|
376
376
|
* message: `Open external link?\n${url}`,
|
|
377
|
-
* buttons: ["Open", "Cancel"]
|
|
377
|
+
* buttons: ["Open", "Cancel"],
|
|
378
378
|
* });
|
|
379
379
|
*
|
|
380
380
|
* if (confirmed) {
|
|
@@ -386,14 +386,14 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
386
386
|
* };
|
|
387
387
|
* ```
|
|
388
388
|
*
|
|
389
|
-
* @see {@link McpUiOpenLinkRequest} for the request type
|
|
390
|
-
* @see {@link McpUiOpenLinkResult} for the result type
|
|
389
|
+
* @see {@link McpUiOpenLinkRequest `McpUiOpenLinkRequest`} for the request type
|
|
390
|
+
* @see {@link McpUiOpenLinkResult `McpUiOpenLinkResult`} for the result type
|
|
391
391
|
*/
|
|
392
392
|
set onopenlink(callback: (params: McpUiOpenLinkRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiOpenLinkResult>);
|
|
393
393
|
/**
|
|
394
|
-
* Register a handler for display mode change requests from the
|
|
394
|
+
* Register a handler for display mode change requests from the view.
|
|
395
395
|
*
|
|
396
|
-
* The
|
|
396
|
+
* The view sends `ui/request-display-mode` requests when it wants to change
|
|
397
397
|
* its display mode (e.g., from "inline" to "fullscreen"). The handler should
|
|
398
398
|
* check if the requested mode is in `availableDisplayModes` from the host context,
|
|
399
399
|
* update the display mode if supported, and return the actual mode that was set.
|
|
@@ -410,28 +410,23 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
410
410
|
* - Returns: `Promise<McpUiRequestDisplayModeResult>` with the actual mode set
|
|
411
411
|
*
|
|
412
412
|
* @example
|
|
413
|
-
* ```
|
|
414
|
-
* let currentDisplayMode: McpUiDisplayMode = "inline";
|
|
415
|
-
*
|
|
413
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onrequestdisplaymode_handleRequest"
|
|
416
414
|
* bridge.onrequestdisplaymode = async ({ mode }, extra) => {
|
|
417
|
-
*
|
|
418
|
-
* if (availableModes.includes(mode)) {
|
|
415
|
+
* if (availableDisplayModes.includes(mode)) {
|
|
419
416
|
* currentDisplayMode = mode;
|
|
420
|
-
* return { mode };
|
|
421
417
|
* }
|
|
422
|
-
* // Return current mode if requested mode not available
|
|
423
418
|
* return { mode: currentDisplayMode };
|
|
424
419
|
* };
|
|
425
420
|
* ```
|
|
426
421
|
*
|
|
427
|
-
* @see {@link McpUiRequestDisplayModeRequest} for the request type
|
|
428
|
-
* @see {@link McpUiRequestDisplayModeResult} for the result type
|
|
422
|
+
* @see {@link McpUiRequestDisplayModeRequest `McpUiRequestDisplayModeRequest`} for the request type
|
|
423
|
+
* @see {@link McpUiRequestDisplayModeResult `McpUiRequestDisplayModeResult`} for the result type
|
|
429
424
|
*/
|
|
430
425
|
set onrequestdisplaymode(callback: (params: McpUiRequestDisplayModeRequest["params"], extra: RequestHandlerExtra) => Promise<McpUiRequestDisplayModeResult>);
|
|
431
426
|
/**
|
|
432
|
-
* Register a handler for logging messages from the
|
|
427
|
+
* Register a handler for logging messages from the view.
|
|
433
428
|
*
|
|
434
|
-
* The
|
|
429
|
+
* The view sends standard MCP `notifications/message` (logging) notifications
|
|
435
430
|
* to report debugging information, errors, warnings, and other telemetry to the
|
|
436
431
|
* host. The host can display these in a console, log them to a file, or send
|
|
437
432
|
* them to a monitoring service.
|
|
@@ -445,22 +440,21 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
445
440
|
* - `params.data` - Log message and optional structured data
|
|
446
441
|
*
|
|
447
442
|
* @example
|
|
448
|
-
* ```
|
|
443
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onloggingmessage_handleLog"
|
|
449
444
|
* bridge.onloggingmessage = ({ level, logger, data }) => {
|
|
450
|
-
* const prefix = logger ? `[${logger}]` : "[Guest UI]";
|
|
451
445
|
* console[level === "error" ? "error" : "log"](
|
|
452
|
-
*
|
|
453
|
-
* data
|
|
446
|
+
* `[${logger ?? "View"}] ${level.toUpperCase()}:`,
|
|
447
|
+
* data,
|
|
454
448
|
* );
|
|
455
449
|
* };
|
|
456
450
|
* ```
|
|
457
451
|
*/
|
|
458
452
|
set onloggingmessage(callback: (params: LoggingMessageNotification["params"]) => void);
|
|
459
453
|
/**
|
|
460
|
-
* Register a handler for model context updates from the
|
|
454
|
+
* Register a handler for model context updates from the view.
|
|
461
455
|
*
|
|
462
|
-
* The
|
|
463
|
-
* model context. Each request overwrites the previous context stored by the
|
|
456
|
+
* The view sends `ui/update-model-context` requests to update the Host's
|
|
457
|
+
* model context. Each request overwrites the previous context stored by the view.
|
|
464
458
|
* Unlike logging messages, context updates are intended to be available to
|
|
465
459
|
* the model in future turns. Unlike messages, context updates do not trigger follow-ups.
|
|
466
460
|
*
|
|
@@ -469,26 +463,24 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
469
463
|
* update received.
|
|
470
464
|
*
|
|
471
465
|
* @example
|
|
472
|
-
* ```
|
|
473
|
-
* bridge.onupdatemodelcontext = async (
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
* timestamp: Date.now()
|
|
480
|
-
* };
|
|
466
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onupdatemodelcontext_storeContext"
|
|
467
|
+
* bridge.onupdatemodelcontext = async (
|
|
468
|
+
* { content, structuredContent },
|
|
469
|
+
* extra,
|
|
470
|
+
* ) => {
|
|
471
|
+
* // Store the context snapshot for inclusion in the next model request
|
|
472
|
+
* modelContextManager.update({ content, structuredContent });
|
|
481
473
|
* return {};
|
|
482
474
|
* };
|
|
483
475
|
* ```
|
|
484
476
|
*
|
|
485
|
-
* @see {@link McpUiUpdateModelContextRequest} for the request type
|
|
477
|
+
* @see {@link McpUiUpdateModelContextRequest `McpUiUpdateModelContextRequest`} for the request type
|
|
486
478
|
*/
|
|
487
479
|
set onupdatemodelcontext(callback: (params: McpUiUpdateModelContextRequest["params"], extra: RequestHandlerExtra) => Promise<EmptyResult>);
|
|
488
480
|
/**
|
|
489
|
-
* Register a handler for tool call requests from the
|
|
481
|
+
* Register a handler for tool call requests from the view.
|
|
490
482
|
*
|
|
491
|
-
* The
|
|
483
|
+
* The view sends `tools/call` requests to execute MCP server tools. This
|
|
492
484
|
* handler allows the host to intercept and process these requests, typically
|
|
493
485
|
* by forwarding them to the MCP server.
|
|
494
486
|
*
|
|
@@ -498,12 +490,12 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
498
490
|
* - `extra` - Request metadata (abort signal, session info)
|
|
499
491
|
*
|
|
500
492
|
* @example
|
|
501
|
-
* ```
|
|
502
|
-
* bridge.oncalltool = async (
|
|
493
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_oncalltool_forwardToServer"
|
|
494
|
+
* bridge.oncalltool = async (params, extra) => {
|
|
503
495
|
* return mcpClient.request(
|
|
504
|
-
* { method: "tools/call", params
|
|
496
|
+
* { method: "tools/call", params },
|
|
505
497
|
* CallToolResultSchema,
|
|
506
|
-
* { signal: extra.signal }
|
|
498
|
+
* { signal: extra.signal },
|
|
507
499
|
* );
|
|
508
500
|
* };
|
|
509
501
|
* ```
|
|
@@ -513,10 +505,10 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
513
505
|
*/
|
|
514
506
|
set oncalltool(callback: (params: CallToolRequest["params"], extra: RequestHandlerExtra) => Promise<CallToolResult>);
|
|
515
507
|
/**
|
|
516
|
-
* Notify the
|
|
508
|
+
* Notify the view that the MCP server's tool list has changed.
|
|
517
509
|
*
|
|
518
|
-
* The host sends `notifications/tools/list_changed` to the
|
|
519
|
-
* receives this notification from the MCP server. This allows the
|
|
510
|
+
* The host sends `notifications/tools/list_changed` to the view when it
|
|
511
|
+
* receives this notification from the MCP server. This allows the view
|
|
520
512
|
* to refresh its tool cache or UI accordingly.
|
|
521
513
|
*
|
|
522
514
|
* @param params - Optional notification params (typically empty)
|
|
@@ -533,9 +525,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
533
525
|
*/
|
|
534
526
|
sendToolListChanged(params?: ToolListChangedNotification["params"]): Promise<void>;
|
|
535
527
|
/**
|
|
536
|
-
* Register a handler for list resources requests from the
|
|
528
|
+
* Register a handler for list resources requests from the view.
|
|
537
529
|
*
|
|
538
|
-
* The
|
|
530
|
+
* The view sends `resources/list` requests to enumerate available MCP
|
|
539
531
|
* resources. This handler allows the host to intercept and process these
|
|
540
532
|
* requests, typically by forwarding them to the MCP server.
|
|
541
533
|
*
|
|
@@ -545,12 +537,12 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
545
537
|
* - `extra` - Request metadata (abort signal, session info)
|
|
546
538
|
*
|
|
547
539
|
* @example
|
|
548
|
-
* ```
|
|
540
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onlistresources_returnResources"
|
|
549
541
|
* bridge.onlistresources = async (params, extra) => {
|
|
550
542
|
* return mcpClient.request(
|
|
551
543
|
* { method: "resources/list", params },
|
|
552
544
|
* ListResourcesResultSchema,
|
|
553
|
-
* { signal: extra.signal }
|
|
545
|
+
* { signal: extra.signal },
|
|
554
546
|
* );
|
|
555
547
|
* };
|
|
556
548
|
* ```
|
|
@@ -560,9 +552,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
560
552
|
*/
|
|
561
553
|
set onlistresources(callback: (params: ListResourcesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourcesResult>);
|
|
562
554
|
/**
|
|
563
|
-
* Register a handler for list resource templates requests from the
|
|
555
|
+
* Register a handler for list resource templates requests from the view.
|
|
564
556
|
*
|
|
565
|
-
* The
|
|
557
|
+
* The view sends `resources/templates/list` requests to enumerate available
|
|
566
558
|
* MCP resource templates. This handler allows the host to intercept and process
|
|
567
559
|
* these requests, typically by forwarding them to the MCP server.
|
|
568
560
|
*
|
|
@@ -587,9 +579,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
587
579
|
*/
|
|
588
580
|
set onlistresourcetemplates(callback: (params: ListResourceTemplatesRequest["params"], extra: RequestHandlerExtra) => Promise<ListResourceTemplatesResult>);
|
|
589
581
|
/**
|
|
590
|
-
* Register a handler for read resource requests from the
|
|
582
|
+
* Register a handler for read resource requests from the view.
|
|
591
583
|
*
|
|
592
|
-
* The
|
|
584
|
+
* The view sends `resources/read` requests to retrieve the contents of an
|
|
593
585
|
* MCP resource. This handler allows the host to intercept and process these
|
|
594
586
|
* requests, typically by forwarding them to the MCP server.
|
|
595
587
|
*
|
|
@@ -599,12 +591,12 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
599
591
|
* - `extra` - Request metadata (abort signal, session info)
|
|
600
592
|
*
|
|
601
593
|
* @example
|
|
602
|
-
* ```
|
|
603
|
-
* bridge.onreadresource = async (
|
|
594
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onreadresource_returnResource"
|
|
595
|
+
* bridge.onreadresource = async (params, extra) => {
|
|
604
596
|
* return mcpClient.request(
|
|
605
|
-
* { method: "resources/read", params
|
|
597
|
+
* { method: "resources/read", params },
|
|
606
598
|
* ReadResourceResultSchema,
|
|
607
|
-
* { signal: extra.signal }
|
|
599
|
+
* { signal: extra.signal },
|
|
608
600
|
* );
|
|
609
601
|
* };
|
|
610
602
|
* ```
|
|
@@ -614,10 +606,10 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
614
606
|
*/
|
|
615
607
|
set onreadresource(callback: (params: ReadResourceRequest["params"], extra: RequestHandlerExtra) => Promise<ReadResourceResult>);
|
|
616
608
|
/**
|
|
617
|
-
* Notify the
|
|
609
|
+
* Notify the view that the MCP server's resource list has changed.
|
|
618
610
|
*
|
|
619
|
-
* The host sends `notifications/resources/list_changed` to the
|
|
620
|
-
* receives this notification from the MCP server. This allows the
|
|
611
|
+
* The host sends `notifications/resources/list_changed` to the view when it
|
|
612
|
+
* receives this notification from the MCP server. This allows the view
|
|
621
613
|
* to refresh its resource cache or UI accordingly.
|
|
622
614
|
*
|
|
623
615
|
* @param params - Optional notification params (typically empty)
|
|
@@ -634,9 +626,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
634
626
|
*/
|
|
635
627
|
sendResourceListChanged(params?: ResourceListChangedNotification["params"]): Promise<void>;
|
|
636
628
|
/**
|
|
637
|
-
* Register a handler for list prompts requests from the
|
|
629
|
+
* Register a handler for list prompts requests from the view.
|
|
638
630
|
*
|
|
639
|
-
* The
|
|
631
|
+
* The view sends `prompts/list` requests to enumerate available MCP
|
|
640
632
|
* prompts. This handler allows the host to intercept and process these
|
|
641
633
|
* requests, typically by forwarding them to the MCP server.
|
|
642
634
|
*
|
|
@@ -646,12 +638,12 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
646
638
|
* - `extra` - Request metadata (abort signal, session info)
|
|
647
639
|
*
|
|
648
640
|
* @example
|
|
649
|
-
* ```
|
|
641
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_onlistprompts_returnPrompts"
|
|
650
642
|
* bridge.onlistprompts = async (params, extra) => {
|
|
651
643
|
* return mcpClient.request(
|
|
652
644
|
* { method: "prompts/list", params },
|
|
653
645
|
* ListPromptsResultSchema,
|
|
654
|
-
* { signal: extra.signal }
|
|
646
|
+
* { signal: extra.signal },
|
|
655
647
|
* );
|
|
656
648
|
* };
|
|
657
649
|
* ```
|
|
@@ -661,10 +653,10 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
661
653
|
*/
|
|
662
654
|
set onlistprompts(callback: (params: ListPromptsRequest["params"], extra: RequestHandlerExtra) => Promise<ListPromptsResult>);
|
|
663
655
|
/**
|
|
664
|
-
* Notify the
|
|
656
|
+
* Notify the view that the MCP server's prompt list has changed.
|
|
665
657
|
*
|
|
666
|
-
* The host sends `notifications/prompts/list_changed` to the
|
|
667
|
-
* receives this notification from the MCP server. This allows the
|
|
658
|
+
* The host sends `notifications/prompts/list_changed` to the view when it
|
|
659
|
+
* receives this notification from the MCP server. This allows the view
|
|
668
660
|
* to refresh its prompt cache or UI accordingly.
|
|
669
661
|
*
|
|
670
662
|
* @param params - Optional notification params (typically empty)
|
|
@@ -710,7 +702,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
710
702
|
*
|
|
711
703
|
* @returns Host capabilities object
|
|
712
704
|
*
|
|
713
|
-
* @see {@link McpUiHostCapabilities} for the capabilities structure
|
|
705
|
+
* @see {@link McpUiHostCapabilities `McpUiHostCapabilities`} for the capabilities structure
|
|
714
706
|
*/
|
|
715
707
|
getCapabilities(): McpUiHostCapabilities;
|
|
716
708
|
/**
|
|
@@ -719,14 +711,14 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
719
711
|
*/
|
|
720
712
|
private _oninitialize;
|
|
721
713
|
/**
|
|
722
|
-
* Update the host context and notify the
|
|
714
|
+
* Update the host context and notify the view of changes.
|
|
723
715
|
*
|
|
724
716
|
* Compares fields present in the new context with the current context and sends a
|
|
725
717
|
* `ui/notifications/host-context-changed` notification containing only fields
|
|
726
718
|
* that have been added or modified. If no fields have changed, no notification is sent.
|
|
727
719
|
* The new context fully replaces the internal state.
|
|
728
720
|
*
|
|
729
|
-
* Common use cases include notifying the
|
|
721
|
+
* Common use cases include notifying the view when:
|
|
730
722
|
* - Theme changes (light/dark mode toggle)
|
|
731
723
|
* - Viewport size changes (window resize)
|
|
732
724
|
* - Display mode changes (inline/fullscreen)
|
|
@@ -735,26 +727,26 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
735
727
|
* @param hostContext - The complete new host context state
|
|
736
728
|
*
|
|
737
729
|
* @example Update theme when user toggles dark mode
|
|
738
|
-
* ```
|
|
730
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_setHostContext_updateTheme"
|
|
739
731
|
* bridge.setHostContext({ theme: "dark" });
|
|
740
732
|
* ```
|
|
741
733
|
*
|
|
742
734
|
* @example Update multiple context fields
|
|
743
|
-
* ```
|
|
735
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_setHostContext_updateMultiple"
|
|
744
736
|
* bridge.setHostContext({
|
|
745
737
|
* theme: "dark",
|
|
746
|
-
* containerDimensions: { maxHeight: 600, width: 800 }
|
|
738
|
+
* containerDimensions: { maxHeight: 600, width: 800 },
|
|
747
739
|
* });
|
|
748
740
|
* ```
|
|
749
741
|
*
|
|
750
|
-
* @see {@link McpUiHostContext} for the context structure
|
|
751
|
-
* @see {@link McpUiHostContextChangedNotification} for the notification type
|
|
742
|
+
* @see {@link McpUiHostContext `McpUiHostContext`} for the context structure
|
|
743
|
+
* @see {@link McpUiHostContextChangedNotification `McpUiHostContextChangedNotification`} for the notification type
|
|
752
744
|
*/
|
|
753
745
|
setHostContext(hostContext: McpUiHostContext): void;
|
|
754
746
|
/**
|
|
755
|
-
* Low-level method to notify the
|
|
747
|
+
* Low-level method to notify the view of host context changes.
|
|
756
748
|
*
|
|
757
|
-
* Most hosts should use {@link setHostContext} instead, which automatically
|
|
749
|
+
* Most hosts should use {@link setHostContext `setHostContext`} instead, which automatically
|
|
758
750
|
* detects changes and calls this method with only the modified fields.
|
|
759
751
|
* Use this directly only when you need fine-grained control over change detection.
|
|
760
752
|
*
|
|
@@ -762,100 +754,100 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
762
754
|
*/
|
|
763
755
|
sendHostContextChange(params: McpUiHostContextChangedNotification["params"]): Promise<void> | void;
|
|
764
756
|
/**
|
|
765
|
-
* Send complete tool arguments to the
|
|
757
|
+
* Send complete tool arguments to the view.
|
|
766
758
|
*
|
|
767
|
-
* The host MUST send this notification after the
|
|
768
|
-
* (after {@link oninitialized} callback fires) and complete tool arguments become available.
|
|
769
|
-
* This notification is sent exactly once and is required before {@link sendToolResult}.
|
|
759
|
+
* The host MUST send this notification after the View completes initialization
|
|
760
|
+
* (after {@link oninitialized `oninitialized`} callback fires) and complete tool arguments become available.
|
|
761
|
+
* This notification is sent exactly once and is required before {@link sendToolResult `sendToolResult`}.
|
|
770
762
|
*
|
|
771
763
|
* @param params - Complete tool call arguments
|
|
772
764
|
*
|
|
773
765
|
* @example
|
|
774
|
-
* ```
|
|
766
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_sendToolInput_afterInit"
|
|
775
767
|
* bridge.oninitialized = () => {
|
|
776
768
|
* bridge.sendToolInput({
|
|
777
|
-
* arguments: { location: "New York", units: "metric" }
|
|
769
|
+
* arguments: { location: "New York", units: "metric" },
|
|
778
770
|
* });
|
|
779
771
|
* };
|
|
780
772
|
* ```
|
|
781
773
|
*
|
|
782
|
-
* @see {@link McpUiToolInputNotification} for the notification type
|
|
783
|
-
* @see {@link oninitialized} for the initialization callback
|
|
784
|
-
* @see {@link sendToolResult} for sending results after execution
|
|
774
|
+
* @see {@link McpUiToolInputNotification `McpUiToolInputNotification`} for the notification type
|
|
775
|
+
* @see {@link oninitialized `oninitialized`} for the initialization callback
|
|
776
|
+
* @see {@link sendToolResult `sendToolResult`} for sending results after execution
|
|
785
777
|
*/
|
|
786
778
|
sendToolInput(params: McpUiToolInputNotification["params"]): Promise<void>;
|
|
787
779
|
/**
|
|
788
|
-
* Send streaming partial tool arguments to the
|
|
780
|
+
* Send streaming partial tool arguments to the view.
|
|
789
781
|
*
|
|
790
782
|
* The host MAY send this notification zero or more times while tool arguments
|
|
791
|
-
* are being streamed, before {@link sendToolInput} is called with complete
|
|
783
|
+
* are being streamed, before {@link sendToolInput `sendToolInput`} is called with complete
|
|
792
784
|
* arguments. This enables progressive rendering of tool arguments in the
|
|
793
|
-
*
|
|
785
|
+
* view.
|
|
794
786
|
*
|
|
795
|
-
* The arguments represent best-effort recovery of incomplete JSON.
|
|
787
|
+
* The arguments represent best-effort recovery of incomplete JSON. views
|
|
796
788
|
* SHOULD handle missing or changing fields gracefully between notifications.
|
|
797
789
|
*
|
|
798
790
|
* @param params - Partial tool call arguments (may be incomplete)
|
|
799
791
|
*
|
|
800
792
|
* @example Stream partial arguments as they arrive
|
|
801
|
-
* ```
|
|
793
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_sendToolInputPartial_streaming"
|
|
802
794
|
* // As streaming progresses...
|
|
803
795
|
* bridge.sendToolInputPartial({ arguments: { loc: "N" } });
|
|
804
796
|
* bridge.sendToolInputPartial({ arguments: { location: "New" } });
|
|
805
797
|
* bridge.sendToolInputPartial({ arguments: { location: "New York" } });
|
|
806
798
|
*
|
|
807
799
|
* // When complete, send final input
|
|
808
|
-
* bridge.sendToolInput({
|
|
800
|
+
* bridge.sendToolInput({
|
|
801
|
+
* arguments: { location: "New York", units: "metric" },
|
|
802
|
+
* });
|
|
809
803
|
* ```
|
|
810
804
|
*
|
|
811
|
-
* @see {@link McpUiToolInputPartialNotification} for the notification type
|
|
812
|
-
* @see {@link sendToolInput} for sending complete arguments
|
|
805
|
+
* @see {@link McpUiToolInputPartialNotification `McpUiToolInputPartialNotification`} for the notification type
|
|
806
|
+
* @see {@link sendToolInput `sendToolInput`} for sending complete arguments
|
|
813
807
|
*/
|
|
814
808
|
sendToolInputPartial(params: McpUiToolInputPartialNotification["params"]): Promise<void>;
|
|
815
809
|
/**
|
|
816
|
-
* Send tool execution result to the
|
|
810
|
+
* Send tool execution result to the view.
|
|
817
811
|
*
|
|
818
812
|
* The host MUST send this notification when tool execution completes successfully,
|
|
819
|
-
* provided the
|
|
813
|
+
* provided the view is still displayed. If the view was closed before execution
|
|
820
814
|
* completes, the host MAY skip this notification. This must be sent after
|
|
821
|
-
* {@link sendToolInput}.
|
|
815
|
+
* {@link sendToolInput `sendToolInput`}.
|
|
822
816
|
*
|
|
823
817
|
* @param params - Standard MCP tool execution result
|
|
824
818
|
*
|
|
825
819
|
* @example
|
|
826
|
-
* ```
|
|
827
|
-
* import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
828
|
-
*
|
|
820
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_sendToolResult_afterExecution"
|
|
829
821
|
* const result = await mcpClient.request(
|
|
830
822
|
* { method: "tools/call", params: { name: "get_weather", arguments: args } },
|
|
831
|
-
* CallToolResultSchema
|
|
823
|
+
* CallToolResultSchema,
|
|
832
824
|
* );
|
|
833
825
|
* bridge.sendToolResult(result);
|
|
834
826
|
* ```
|
|
835
827
|
*
|
|
836
|
-
* @see {@link McpUiToolResultNotification} for the notification type
|
|
837
|
-
* @see {@link sendToolInput} for sending tool arguments before results
|
|
828
|
+
* @see {@link McpUiToolResultNotification `McpUiToolResultNotification`} for the notification type
|
|
829
|
+
* @see {@link sendToolInput `sendToolInput`} for sending tool arguments before results
|
|
838
830
|
*/
|
|
839
831
|
sendToolResult(params: McpUiToolResultNotification["params"]): Promise<void>;
|
|
840
832
|
/**
|
|
841
|
-
* Notify the
|
|
833
|
+
* Notify the view that tool execution was cancelled.
|
|
842
834
|
*
|
|
843
835
|
* The host MUST send this notification if tool execution was cancelled for any
|
|
844
836
|
* reason, including user action, sampling error, classifier intervention, or
|
|
845
|
-
* any other interruption. This allows the
|
|
837
|
+
* any other interruption. This allows the view to update its state and
|
|
846
838
|
* display appropriate feedback to the user.
|
|
847
839
|
*
|
|
848
840
|
* @param params - Cancellation details object
|
|
849
841
|
* - `reason`: Human-readable explanation for why the tool was cancelled
|
|
850
842
|
*
|
|
851
843
|
* @example User-initiated cancellation
|
|
852
|
-
* ```
|
|
844
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_sendToolCancelled_userInitiated"
|
|
853
845
|
* // User clicked "Cancel" button
|
|
854
846
|
* bridge.sendToolCancelled({ reason: "User cancelled the operation" });
|
|
855
847
|
* ```
|
|
856
848
|
*
|
|
857
849
|
* @example System-level cancellation
|
|
858
|
-
* ```
|
|
850
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_sendToolCancelled_systemLevel"
|
|
859
851
|
* // Sampling error or timeout
|
|
860
852
|
* bridge.sendToolCancelled({ reason: "Request timeout after 30 seconds" });
|
|
861
853
|
*
|
|
@@ -863,9 +855,9 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
863
855
|
* bridge.sendToolCancelled({ reason: "Content policy violation detected" });
|
|
864
856
|
* ```
|
|
865
857
|
*
|
|
866
|
-
* @see {@link McpUiToolCancelledNotification} for the notification type
|
|
867
|
-
* @see {@link sendToolResult} for sending successful results
|
|
868
|
-
* @see {@link sendToolInput} for sending tool arguments
|
|
858
|
+
* @see {@link McpUiToolCancelledNotification `McpUiToolCancelledNotification`} for the notification type
|
|
859
|
+
* @see {@link sendToolResult `sendToolResult`} for sending successful results
|
|
860
|
+
* @see {@link sendToolInput `sendToolInput`} for sending tool arguments
|
|
869
861
|
*/
|
|
870
862
|
sendToolCancelled(params: McpUiToolCancelledNotification["params"]): Promise<void>;
|
|
871
863
|
/**
|
|
@@ -881,27 +873,27 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
881
873
|
* - `sandbox`: Optional sandbox attribute value (e.g., "allow-scripts")
|
|
882
874
|
*
|
|
883
875
|
* @internal
|
|
884
|
-
* @see {@link onsandboxready} for handling the sandbox proxy ready notification
|
|
876
|
+
* @see {@link onsandboxready `onsandboxready`} for handling the sandbox proxy ready notification
|
|
885
877
|
*/
|
|
886
878
|
sendSandboxResourceReady(params: McpUiSandboxResourceReadyNotification["params"]): Promise<void>;
|
|
887
879
|
/**
|
|
888
|
-
* Request graceful shutdown of the
|
|
880
|
+
* Request graceful shutdown of the view.
|
|
889
881
|
*
|
|
890
882
|
* The host MUST send this request before tearing down the UI resource (before
|
|
891
|
-
* unmounting the iframe). This gives the
|
|
883
|
+
* unmounting the iframe). This gives the view an opportunity to save state,
|
|
892
884
|
* cancel pending operations, or show confirmation dialogs.
|
|
893
885
|
*
|
|
894
886
|
* The host SHOULD wait for the response before unmounting to prevent data loss.
|
|
895
887
|
*
|
|
896
888
|
* @param params - Empty params object
|
|
897
889
|
* @param options - Request options (timeout, etc.)
|
|
898
|
-
* @returns Promise resolving when
|
|
890
|
+
* @returns Promise resolving when view confirms readiness for teardown
|
|
899
891
|
*
|
|
900
892
|
* @example
|
|
901
|
-
* ```
|
|
893
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_teardownResource_gracefulShutdown"
|
|
902
894
|
* try {
|
|
903
895
|
* await bridge.teardownResource({});
|
|
904
|
-
* //
|
|
896
|
+
* // View is ready, safe to unmount iframe
|
|
905
897
|
* iframe.remove();
|
|
906
898
|
* } catch (error) {
|
|
907
899
|
* console.error("Teardown failed:", error);
|
|
@@ -909,26 +901,26 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
909
901
|
* ```
|
|
910
902
|
*/
|
|
911
903
|
teardownResource(params: McpUiResourceTeardownRequest["params"], options?: RequestOptions): Promise<Record<string, unknown>>;
|
|
912
|
-
/** @deprecated Use {@link teardownResource} instead */
|
|
904
|
+
/** @deprecated Use {@link teardownResource `teardownResource`} instead */
|
|
913
905
|
sendResourceTeardown: AppBridge["teardownResource"];
|
|
914
906
|
/**
|
|
915
|
-
* Connect to the
|
|
907
|
+
* Connect to the view via transport and optionally set up message forwarding.
|
|
916
908
|
*
|
|
917
909
|
* This method establishes the transport connection. If an MCP client was passed
|
|
918
910
|
* to the constructor, it also automatically sets up request/notification forwarding
|
|
919
|
-
* based on the MCP server's capabilities, proxying the following to the
|
|
911
|
+
* based on the MCP server's capabilities, proxying the following to the view:
|
|
920
912
|
* - Tools (tools/call, notifications/tools/list_changed)
|
|
921
913
|
* - Resources (resources/list, resources/read, resources/templates/list, notifications/resources/list_changed)
|
|
922
914
|
* - Prompts (prompts/list, notifications/prompts/list_changed)
|
|
923
915
|
*
|
|
924
916
|
* If no client was passed to the constructor, no automatic forwarding is set up
|
|
925
|
-
* and you must register handlers manually using the {@link oncalltool}, {@link onlistresources},
|
|
917
|
+
* and you must register handlers manually using the {@link oncalltool `oncalltool`}, {@link onlistresources `onlistresources`},
|
|
926
918
|
* etc. setters.
|
|
927
919
|
*
|
|
928
|
-
* After calling connect, wait for the {@link oninitialized} callback before sending
|
|
929
|
-
* tool input and other data to the
|
|
920
|
+
* After calling connect, wait for the {@link oninitialized `oninitialized`} callback before sending
|
|
921
|
+
* tool input and other data to the View.
|
|
930
922
|
*
|
|
931
|
-
* @param transport - Transport layer (typically {@link PostMessageTransport})
|
|
923
|
+
* @param transport - Transport layer (typically {@link PostMessageTransport `PostMessageTransport`})
|
|
932
924
|
* @returns Promise resolving when connection is established
|
|
933
925
|
*
|
|
934
926
|
* @throws {Error} If a client was passed but server capabilities are not available.
|
|
@@ -937,7 +929,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
937
929
|
* before calling `bridge.connect()`.
|
|
938
930
|
*
|
|
939
931
|
* @example With MCP client (automatic forwarding)
|
|
940
|
-
* ```
|
|
932
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_connect_withMcpClient"
|
|
941
933
|
* const bridge = new AppBridge(mcpClient, hostInfo, capabilities);
|
|
942
934
|
* const transport = new PostMessageTransport(
|
|
943
935
|
* iframe.contentWindow!,
|
|
@@ -945,7 +937,7 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
945
937
|
* );
|
|
946
938
|
*
|
|
947
939
|
* bridge.oninitialized = () => {
|
|
948
|
-
* console.log("
|
|
940
|
+
* console.log("View ready");
|
|
949
941
|
* bridge.sendToolInput({ arguments: toolArgs });
|
|
950
942
|
* };
|
|
951
943
|
*
|
|
@@ -953,12 +945,13 @@ export declare class AppBridge extends Protocol<AppRequest, AppNotification, App
|
|
|
953
945
|
* ```
|
|
954
946
|
*
|
|
955
947
|
* @example Without MCP client (manual handlers)
|
|
956
|
-
* ```
|
|
948
|
+
* ```ts source="./app-bridge.examples.ts#AppBridge_connect_withoutMcpClient"
|
|
957
949
|
* const bridge = new AppBridge(null, hostInfo, capabilities);
|
|
958
950
|
*
|
|
959
951
|
* // Register handlers manually
|
|
960
952
|
* bridge.oncalltool = async (params, extra) => {
|
|
961
953
|
* // Custom tool call handling
|
|
954
|
+
* return { content: [] };
|
|
962
955
|
* };
|
|
963
956
|
*
|
|
964
957
|
* await bridge.connect(transport);
|