@modelcontextprotocol/ext-apps 1.1.2 → 1.2.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/dist/src/app.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type RequestOptions, Protocol, ProtocolOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
2
- import { CallToolRequest, CallToolResult, Implementation, ListToolsRequest, LoggingMessageNotification } from "@modelcontextprotocol/sdk/types.js";
2
+ import { CallToolRequest, CallToolResult, Implementation, ListResourcesRequest, ListResourcesResult, ListToolsRequest, LoggingMessageNotification, ReadResourceRequest, ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
3
3
  import { AppNotification, AppRequest, AppResult } from "./types";
4
4
  import { McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiDownloadFileRequest, McpUiResourceTeardownRequest, McpUiResourceTeardownResult, McpUiSizeChangedNotification, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiRequestDisplayModeRequest } from "./types";
5
5
  import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
@@ -14,12 +14,30 @@ export { applyHostStyleVariables, applyHostFonts, getDocumentTheme, applyDocumen
14
14
  * When hosts see a tool with this metadata, they fetch and render the
15
15
  * corresponding {@link App `App`}.
16
16
  *
17
- * **Note**: This constant is provided for reference. App developers typically
18
- * don't need to use it directly. Prefer using {@link server-helpers!registerAppTool `registerAppTool`}
19
- * with the `_meta.ui.resourceUri` format instead.
17
+ * **Note**: This constant is provided for reference and backwards compatibility.
18
+ * Server developers should use {@link server-helpers!registerAppTool `registerAppTool`}
19
+ * with the `_meta.ui.resourceUri` format instead. Host developers must check both
20
+ * formats for compatibility.
20
21
  *
21
- * @example How MCP servers use this key (server-side, not in Apps)
22
- * ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_serverSide"
22
+ * @example Modern format (server-side, not in Apps)
23
+ * ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_modernFormat"
24
+ * // Preferred: Use registerAppTool with nested ui.resourceUri
25
+ * registerAppTool(
26
+ * server,
27
+ * "weather",
28
+ * {
29
+ * description: "Get weather forecast",
30
+ * _meta: {
31
+ * ui: { resourceUri: "ui://weather/forecast" },
32
+ * },
33
+ * },
34
+ * handler,
35
+ * );
36
+ * ```
37
+ *
38
+ * @example Legacy format (deprecated, for backwards compatibility)
39
+ * ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_legacyFormat"
40
+ * // Deprecated: Direct use of RESOURCE_URI_META_KEY
23
41
  * server.registerTool(
24
42
  * "weather",
25
43
  * {
@@ -32,10 +50,13 @@ export { applyHostStyleVariables, applyHostFonts, getDocumentTheme, applyDocumen
32
50
  * );
33
51
  * ```
34
52
  *
35
- * @example How hosts check for this metadata (host-side)
53
+ * @example How hosts check for this metadata (must support both formats)
36
54
  * ```ts source="./app.examples.ts#RESOURCE_URI_META_KEY_hostSide"
37
- * // Check tool definition metadata (from tools/list response):
38
- * const uiUri = tool._meta?.[RESOURCE_URI_META_KEY];
55
+ * // Hosts should check both modern and legacy formats
56
+ * const meta = tool._meta;
57
+ * const uiMeta = meta?.ui as McpUiToolMeta | undefined;
58
+ * const legacyUri = meta?.[RESOURCE_URI_META_KEY] as string | undefined;
59
+ * const uiUri = uiMeta?.resourceUri ?? legacyUri;
39
60
  * if (typeof uiUri === "string" && uiUri.startsWith("ui://")) {
40
61
  * // Fetch the resource and display the UI
41
62
  * }
@@ -541,6 +562,84 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
541
562
  * ```
542
563
  */
543
564
  callServerTool(params: CallToolRequest["params"], options?: RequestOptions): Promise<CallToolResult>;
565
+ /**
566
+ * Read a resource from the originating MCP server (proxied through the host).
567
+ *
568
+ * Apps can read resources to access files, data, or other content provided by
569
+ * the MCP server. Resources are identified by URI (e.g., `file:///path/to/file`
570
+ * or custom schemes like `videos://bunny-1mb`). The host proxies the request to
571
+ * the actual MCP server and returns the resource content.
572
+ *
573
+ * @param params - Resource URI to read
574
+ * @param options - Request options (timeout, etc.)
575
+ * @returns Resource content with URI, name, description, mimeType, and contents array
576
+ *
577
+ * @throws {Error} If the resource does not exist on the server
578
+ * @throws {Error} If the request times out or the connection is lost
579
+ * @throws {Error} If the host rejects the request
580
+ *
581
+ * @example Read a video resource and play it
582
+ * ```ts source="./app.examples.ts#App_readServerResource_playVideo"
583
+ * try {
584
+ * const result = await app.readServerResource({
585
+ * uri: "videos://bunny-1mb",
586
+ * });
587
+ * const content = result.contents[0];
588
+ * if (content && "blob" in content) {
589
+ * const binary = Uint8Array.from(atob(content.blob), (c) =>
590
+ * c.charCodeAt(0),
591
+ * );
592
+ * const url = URL.createObjectURL(
593
+ * new Blob([binary], { type: content.mimeType || "video/mp4" }),
594
+ * );
595
+ * videoElement.src = url;
596
+ * videoElement.play();
597
+ * }
598
+ * } catch (error) {
599
+ * console.error("Failed to read resource:", error);
600
+ * }
601
+ * ```
602
+ *
603
+ * @see {@link listServerResources `listServerResources`} to discover available resources
604
+ */
605
+ readServerResource(params: ReadResourceRequest["params"], options?: RequestOptions): Promise<ReadResourceResult>;
606
+ /**
607
+ * List available resources from the originating MCP server (proxied through the host).
608
+ *
609
+ * Apps can list resources to discover what content is available on the MCP server.
610
+ * This enables dynamic resource discovery and building resource browsers or pickers.
611
+ * The host proxies the request to the actual MCP server and returns the resource list.
612
+ *
613
+ * Results may be paginated using the `cursor` parameter for servers with many resources.
614
+ *
615
+ * @param params - Optional parameters (omit for all resources, or `{ cursor }` for pagination)
616
+ * @param options - Request options (timeout, etc.)
617
+ * @returns List of resources with their URIs, names, descriptions, mimeTypes, and optional pagination cursor
618
+ *
619
+ * @throws {Error} If the request times out or the connection is lost
620
+ * @throws {Error} If the host rejects the request
621
+ *
622
+ * @example Discover available videos and build a picker UI
623
+ * ```ts source="./app.examples.ts#App_listServerResources_buildPicker"
624
+ * try {
625
+ * const result = await app.listServerResources();
626
+ * const videoResources = result.resources.filter((r) =>
627
+ * r.mimeType?.startsWith("video/"),
628
+ * );
629
+ * videoResources.forEach((resource) => {
630
+ * const option = document.createElement("option");
631
+ * option.value = resource.uri;
632
+ * option.textContent = resource.description || resource.name;
633
+ * selectElement.appendChild(option);
634
+ * });
635
+ * } catch (error) {
636
+ * console.error("Failed to list resources:", error);
637
+ * }
638
+ * ```
639
+ *
640
+ * @see {@link readServerResource `readServerResource`} to read a specific resource
641
+ */
642
+ listServerResources(params?: ListResourcesRequest["params"], options?: RequestOptions): Promise<ListResourcesResult>;
544
643
  /**
545
644
  * Send a message to the host's chat interface.
546
645
  *