@modelcontextprotocol/ext-apps 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/src/app-bridge.d.ts +33 -2
- package/dist/src/app-bridge.js +6 -6
- package/dist/src/app.d.ts +102 -3
- package/dist/src/app.js +13 -13
- package/dist/src/generated/schema.d.ts +612 -0
- package/dist/src/generated/schema.test.d.ts +26 -0
- package/dist/src/react/index.js +7 -7
- package/dist/src/spec.types.d.ts +339 -0
- package/dist/src/types.d.ts +8 -845
- package/package.json +8 -4
package/dist/src/app.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RequestOptions, Protocol, ProtocolOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
2
2
|
import { CallToolRequest, CallToolResult, Implementation, ListToolsRequest, LoggingMessageNotification, Notification, Request, Result } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
import { McpUiAppCapabilities, McpUiHostCapabilities, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiSizeChangedNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification } from "./types";
|
|
3
|
+
import { McpUiAppCapabilities, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiResourceTeardownRequest, McpUiResourceTeardownResult, McpUiSizeChangedNotification, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification } from "./types";
|
|
4
4
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
5
5
|
export { PostMessageTransport } from "./message-transport";
|
|
6
6
|
export * from "./types";
|
|
@@ -143,6 +143,7 @@ export declare class App extends Protocol<Request, Notification, Result> {
|
|
|
143
143
|
private options;
|
|
144
144
|
private _hostCapabilities?;
|
|
145
145
|
private _hostInfo?;
|
|
146
|
+
private _hostContext?;
|
|
146
147
|
/**
|
|
147
148
|
* Create a new MCP App instance.
|
|
148
149
|
*
|
|
@@ -209,6 +210,39 @@ export declare class App extends Protocol<Request, Notification, Result> {
|
|
|
209
210
|
* @see {@link connect} for the initialization handshake
|
|
210
211
|
*/
|
|
211
212
|
getHostVersion(): Implementation | undefined;
|
|
213
|
+
/**
|
|
214
|
+
* Get the host context discovered during initialization.
|
|
215
|
+
*
|
|
216
|
+
* Returns the host context that was provided in the initialization response,
|
|
217
|
+
* including tool info, theme, viewport, locale, and other environment details.
|
|
218
|
+
* This context is automatically updated when the host sends
|
|
219
|
+
* `ui/notifications/host-context-changed` notifications.
|
|
220
|
+
*
|
|
221
|
+
* Returns `undefined` if called before connection is established.
|
|
222
|
+
*
|
|
223
|
+
* @returns Host context, or `undefined` if not yet connected
|
|
224
|
+
*
|
|
225
|
+
* @example Access host context after connection
|
|
226
|
+
* ```typescript
|
|
227
|
+
* await app.connect(transport);
|
|
228
|
+
* const context = app.getHostContext();
|
|
229
|
+
* if (context === undefined) {
|
|
230
|
+
* console.error("Not connected");
|
|
231
|
+
* return;
|
|
232
|
+
* }
|
|
233
|
+
* if (context.theme === "dark") {
|
|
234
|
+
* document.body.classList.add("dark-theme");
|
|
235
|
+
* }
|
|
236
|
+
* if (context.toolInfo) {
|
|
237
|
+
* console.log("Tool:", context.toolInfo.tool.name);
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*
|
|
241
|
+
* @see {@link connect} for the initialization handshake
|
|
242
|
+
* @see {@link onhostcontextchanged} for context change notifications
|
|
243
|
+
* @see {@link McpUiHostContext} for the context structure
|
|
244
|
+
*/
|
|
245
|
+
getHostContext(): McpUiHostContext | undefined;
|
|
212
246
|
/**
|
|
213
247
|
* Convenience handler for receiving complete tool input from the host.
|
|
214
248
|
*
|
|
@@ -305,6 +339,34 @@ export declare class App extends Protocol<Request, Notification, Result> {
|
|
|
305
339
|
* @see {@link ontoolinput} for the initial tool input handler
|
|
306
340
|
*/
|
|
307
341
|
set ontoolresult(callback: (params: McpUiToolResultNotification["params"]) => void);
|
|
342
|
+
/**
|
|
343
|
+
* Convenience handler for receiving tool cancellation notifications from the host.
|
|
344
|
+
*
|
|
345
|
+
* Set this property to register a handler that will be called when the host
|
|
346
|
+
* notifies that tool execution was cancelled. This can occur for various reasons
|
|
347
|
+
* including user action, sampling error, classifier intervention, or other
|
|
348
|
+
* interruptions. Apps should update their state and display appropriate feedback.
|
|
349
|
+
*
|
|
350
|
+
* This setter is a convenience wrapper around `setNotificationHandler()` that
|
|
351
|
+
* automatically handles the notification schema and extracts the params for you.
|
|
352
|
+
*
|
|
353
|
+
* Register handlers before calling {@link connect} to avoid missing notifications.
|
|
354
|
+
*
|
|
355
|
+
* @param callback - Function called when tool execution is cancelled
|
|
356
|
+
*
|
|
357
|
+
* @example Handle tool cancellation
|
|
358
|
+
* ```typescript
|
|
359
|
+
* app.ontoolcancelled = (params) => {
|
|
360
|
+
* console.log("Tool cancelled:", params.reason);
|
|
361
|
+
* showCancelledMessage(params.reason ?? "Operation was cancelled");
|
|
362
|
+
* };
|
|
363
|
+
* ```
|
|
364
|
+
*
|
|
365
|
+
* @see {@link setNotificationHandler} for the underlying method
|
|
366
|
+
* @see {@link McpUiToolCancelledNotification} for the notification structure
|
|
367
|
+
* @see {@link ontoolresult} for successful tool completion
|
|
368
|
+
*/
|
|
369
|
+
set ontoolcancelled(callback: (params: McpUiToolCancelledNotification["params"]) => void);
|
|
308
370
|
/**
|
|
309
371
|
* Convenience handler for host context changes (theme, viewport, locale, etc.).
|
|
310
372
|
*
|
|
@@ -336,6 +398,37 @@ export declare class App extends Protocol<Request, Notification, Result> {
|
|
|
336
398
|
* @see {@link McpUiHostContext} for the full context structure
|
|
337
399
|
*/
|
|
338
400
|
set onhostcontextchanged(callback: (params: McpUiHostContextChangedNotification["params"]) => void);
|
|
401
|
+
/**
|
|
402
|
+
* Convenience handler for graceful shutdown requests from the host.
|
|
403
|
+
*
|
|
404
|
+
* Set this property to register a handler that will be called when the host
|
|
405
|
+
* requests the app to prepare for teardown. This allows the app to perform
|
|
406
|
+
* cleanup operations (save state, close connections, etc.) before being unmounted.
|
|
407
|
+
*
|
|
408
|
+
* The handler can be sync or async. The host will wait for the returned promise
|
|
409
|
+
* to resolve before proceeding with teardown.
|
|
410
|
+
*
|
|
411
|
+
* This setter is a convenience wrapper around `setRequestHandler()` that
|
|
412
|
+
* automatically handles the request schema.
|
|
413
|
+
*
|
|
414
|
+
* Register handlers before calling {@link connect} to avoid missing requests.
|
|
415
|
+
*
|
|
416
|
+
* @param callback - Function called when teardown is requested.
|
|
417
|
+
* Can return void or a Promise that resolves when cleanup is complete.
|
|
418
|
+
*
|
|
419
|
+
* @example Perform cleanup before teardown
|
|
420
|
+
* ```typescript
|
|
421
|
+
* app.onteardown = async () => {
|
|
422
|
+
* await saveState();
|
|
423
|
+
* closeConnections();
|
|
424
|
+
* console.log("App ready for teardown");
|
|
425
|
+
* };
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @see {@link setRequestHandler} for the underlying method
|
|
429
|
+
* @see {@link McpUiResourceTeardownRequest} for the request structure
|
|
430
|
+
*/
|
|
431
|
+
set onteardown(callback: (params: McpUiResourceTeardownRequest["params"], extra: RequestHandlerExtra) => McpUiResourceTeardownResult | Promise<McpUiResourceTeardownResult>);
|
|
339
432
|
/**
|
|
340
433
|
* Convenience handler for tool call requests from the host.
|
|
341
434
|
*
|
|
@@ -489,7 +582,10 @@ export declare class App extends Protocol<Request, Notification, Result> {
|
|
|
489
582
|
*
|
|
490
583
|
* @see {@link McpUiMessageRequest} for request structure
|
|
491
584
|
*/
|
|
492
|
-
sendMessage(params: McpUiMessageRequest["params"], options?: RequestOptions): Promise<
|
|
585
|
+
sendMessage(params: McpUiMessageRequest["params"], options?: RequestOptions): Promise<{
|
|
586
|
+
[x: string]: unknown;
|
|
587
|
+
isError?: boolean | undefined;
|
|
588
|
+
}>;
|
|
493
589
|
/**
|
|
494
590
|
* Send log messages to the host for debugging and telemetry.
|
|
495
591
|
*
|
|
@@ -535,7 +631,10 @@ export declare class App extends Protocol<Request, Notification, Result> {
|
|
|
535
631
|
*
|
|
536
632
|
* @see {@link McpUiOpenLinkRequest} for request structure
|
|
537
633
|
*/
|
|
538
|
-
sendOpenLink(params: McpUiOpenLinkRequest["params"], options?: RequestOptions): Promise<
|
|
634
|
+
sendOpenLink(params: McpUiOpenLinkRequest["params"], options?: RequestOptions): Promise<{
|
|
635
|
+
[x: string]: unknown;
|
|
636
|
+
isError?: boolean | undefined;
|
|
637
|
+
}>;
|
|
539
638
|
/**
|
|
540
639
|
* Notify the host of UI size changes.
|
|
541
640
|
*
|