@modelcontextprotocol/ext-apps 1.1.1 → 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/README.md +10 -10
- package/dist/src/app-bridge.d.ts +44 -1
- package/dist/src/app-bridge.js +10 -10
- package/dist/src/app-with-deps.js +10 -10
- package/dist/src/app.d.ts +176 -10
- package/dist/src/app.js +11 -11
- package/dist/src/generated/schema.d.ts +78 -6
- package/dist/src/generated/schema.test.d.ts +2 -0
- package/dist/src/react/index.js +10 -10
- package/dist/src/react/react-with-deps.js +10 -10
- package/dist/src/server/index.js +10 -10
- package/dist/src/spec.types.d.ts +35 -2
- package/dist/src/types.d.ts +5 -5
- package/package.json +4 -23
package/dist/src/app.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type RequestOptions, Protocol, ProtocolOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
2
|
-
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
|
-
import { McpUiAppCapabilities, McpUiUpdateModelContextRequest, McpUiHostCapabilities, McpUiHostContext, McpUiHostContextChangedNotification, McpUiMessageRequest, McpUiOpenLinkRequest, McpUiResourceTeardownRequest, McpUiResourceTeardownResult, McpUiSizeChangedNotification, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolInputPartialNotification, McpUiToolResultNotification, McpUiRequestDisplayModeRequest } from "./types";
|
|
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";
|
|
6
6
|
export { PostMessageTransport } from "./message-transport";
|
|
7
7
|
export * from "./types";
|
|
@@ -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
|
|
18
|
-
*
|
|
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
|
|
22
|
-
* ```ts source="./app.examples.ts#
|
|
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 (
|
|
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
|
-
* //
|
|
38
|
-
* const
|
|
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
|
*
|
|
@@ -708,6 +807,73 @@ export declare class App extends Protocol<AppRequest, AppNotification, AppResult
|
|
|
708
807
|
}>;
|
|
709
808
|
/** @deprecated Use {@link openLink `openLink`} instead */
|
|
710
809
|
sendOpenLink: App["openLink"];
|
|
810
|
+
/**
|
|
811
|
+
* Request the host to download a file.
|
|
812
|
+
*
|
|
813
|
+
* Since MCP Apps run in sandboxed iframes where direct downloads are blocked,
|
|
814
|
+
* this provides a host-mediated mechanism for file exports. The host will
|
|
815
|
+
* typically show a confirmation dialog before initiating the download.
|
|
816
|
+
*
|
|
817
|
+
* Uses standard MCP resource types: `EmbeddedResource` for inline content
|
|
818
|
+
* and `ResourceLink` for content the host can fetch directly.
|
|
819
|
+
*
|
|
820
|
+
* @param params - Resource contents to download
|
|
821
|
+
* @param options - Request options (timeout, etc.)
|
|
822
|
+
* @returns Result with `isError: true` if the host denied the request (e.g., user cancelled)
|
|
823
|
+
*
|
|
824
|
+
* @throws {Error} If the request times out or the connection is lost
|
|
825
|
+
*
|
|
826
|
+
* @example Download a JSON file (embedded text resource)
|
|
827
|
+
* ```ts
|
|
828
|
+
* const data = JSON.stringify({ items: selectedItems }, null, 2);
|
|
829
|
+
* const { isError } = await app.downloadFile({
|
|
830
|
+
* contents: [{
|
|
831
|
+
* type: "resource",
|
|
832
|
+
* resource: {
|
|
833
|
+
* uri: "file:///export.json",
|
|
834
|
+
* mimeType: "application/json",
|
|
835
|
+
* text: data,
|
|
836
|
+
* },
|
|
837
|
+
* }],
|
|
838
|
+
* });
|
|
839
|
+
* if (isError) {
|
|
840
|
+
* console.warn("Download denied or cancelled");
|
|
841
|
+
* }
|
|
842
|
+
* ```
|
|
843
|
+
*
|
|
844
|
+
* @example Download binary content (embedded blob resource)
|
|
845
|
+
* ```ts
|
|
846
|
+
* const { isError } = await app.downloadFile({
|
|
847
|
+
* contents: [{
|
|
848
|
+
* type: "resource",
|
|
849
|
+
* resource: {
|
|
850
|
+
* uri: "file:///image.png",
|
|
851
|
+
* mimeType: "image/png",
|
|
852
|
+
* blob: base64EncodedPng,
|
|
853
|
+
* },
|
|
854
|
+
* }],
|
|
855
|
+
* });
|
|
856
|
+
* ```
|
|
857
|
+
*
|
|
858
|
+
* @example Download via resource link (host fetches)
|
|
859
|
+
* ```ts
|
|
860
|
+
* const { isError } = await app.downloadFile({
|
|
861
|
+
* contents: [{
|
|
862
|
+
* type: "resource_link",
|
|
863
|
+
* uri: "https://api.example.com/reports/q4.pdf",
|
|
864
|
+
* name: "Q4 Report",
|
|
865
|
+
* mimeType: "application/pdf",
|
|
866
|
+
* }],
|
|
867
|
+
* });
|
|
868
|
+
* ```
|
|
869
|
+
*
|
|
870
|
+
* @see {@link McpUiDownloadFileRequest `McpUiDownloadFileRequest`} for request structure
|
|
871
|
+
* @see {@link McpUiDownloadFileResult `McpUiDownloadFileResult`} for result structure
|
|
872
|
+
*/
|
|
873
|
+
downloadFile(params: McpUiDownloadFileRequest["params"], options?: RequestOptions): Promise<{
|
|
874
|
+
[x: string]: unknown;
|
|
875
|
+
isError?: boolean | undefined;
|
|
876
|
+
}>;
|
|
711
877
|
/**
|
|
712
878
|
* Request a change to the display mode.
|
|
713
879
|
*
|