@modelcontextprotocol/ext-apps 1.0.0 → 1.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 +158 -417
- package/dist/src/app-bridge.d.ts +14 -0
- package/dist/src/app-bridge.js +25 -8
- package/dist/src/app-with-deps.js +24 -7
- package/dist/src/app.d.ts +15 -21
- package/dist/src/app.js +26 -9
- package/dist/src/generated/schema.d.ts +9 -0
- package/dist/src/react/index.js +23 -6
- package/dist/src/react/react-with-deps.js +23 -6
- package/dist/src/react/useApp.d.ts +2 -2
- package/dist/src/server/index.d.ts +91 -18
- package/dist/src/server/index.js +25 -8
- package/dist/src/spec.types.d.ts +110 -13
- package/dist/src/styles.d.ts +12 -12
- package/package.json +3 -3
|
@@ -97,8 +97,8 @@ export interface AppState {
|
|
|
97
97
|
* app.onerror = (error) => {
|
|
98
98
|
* console.log("Error:", error);
|
|
99
99
|
* };
|
|
100
|
-
* app.onhostcontextchanged = (
|
|
101
|
-
* setHostContext((prev) => ({ ...prev, ...
|
|
100
|
+
* app.onhostcontextchanged = (ctx) => {
|
|
101
|
+
* setHostContext((prev) => ({ ...prev, ...ctx }));
|
|
102
102
|
* };
|
|
103
103
|
* },
|
|
104
104
|
* });
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
import { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE, McpUiResourceMeta, McpUiToolMeta, McpUiClientCapabilities } from "../app.js";
|
|
34
|
-
import type { McpServer, RegisteredTool, ResourceMetadata, ToolCallback, ReadResourceCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
34
|
+
import type { McpServer, RegisteredTool, ResourceMetadata, ToolCallback, ReadResourceCallback as _ReadResourceCallback, RegisteredResource } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
35
35
|
import type { AnySchema, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
36
|
-
import type { ClientCapabilities, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
36
|
+
import type { ClientCapabilities, ReadResourceResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
37
37
|
export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE };
|
|
38
|
-
export type { ResourceMetadata, ToolCallback
|
|
38
|
+
export type { ResourceMetadata, ToolCallback };
|
|
39
39
|
/**
|
|
40
40
|
* Base tool configuration matching the standard MCP server tool options.
|
|
41
41
|
* Extended by {@link McpUiAppToolConfig `McpUiAppToolConfig`} to add UI metadata requirements.
|
|
@@ -81,12 +81,19 @@ export interface McpUiAppToolConfig extends ToolConfig {
|
|
|
81
81
|
* Extends the base MCP SDK `ResourceMetadata` with optional UI metadata
|
|
82
82
|
* for configuring security policies and rendering preferences.
|
|
83
83
|
*
|
|
84
|
+
* The `_meta.ui` field here is included in the `resources/list` response and serves as
|
|
85
|
+
* a static default for hosts to review at connection time. When the `resources/read`
|
|
86
|
+
* content item also includes `_meta.ui`, the content-item value takes precedence.
|
|
87
|
+
*
|
|
84
88
|
* @see {@link registerAppResource `registerAppResource`} for usage
|
|
85
89
|
*/
|
|
86
90
|
export interface McpUiAppResourceConfig extends ResourceMetadata {
|
|
87
91
|
/**
|
|
88
92
|
* Optional UI metadata for the resource.
|
|
89
|
-
*
|
|
93
|
+
*
|
|
94
|
+
* This appears on the resource entry in `resources/list` and acts as a listing-level
|
|
95
|
+
* fallback. Individual content items returned by `resources/read` may include their
|
|
96
|
+
* own `_meta.ui` which takes precedence over this value.
|
|
90
97
|
*/
|
|
91
98
|
_meta?: {
|
|
92
99
|
/**
|
|
@@ -177,6 +184,14 @@ export declare function registerAppTool<OutputArgs extends ZodRawShapeCompat | A
|
|
|
177
184
|
inputSchema?: InputArgs;
|
|
178
185
|
outputSchema?: OutputArgs;
|
|
179
186
|
}, cb: ToolCallback<InputArgs>): RegisteredTool;
|
|
187
|
+
export type McpUiReadResourceResult = ReadResourceResult & {
|
|
188
|
+
_meta?: {
|
|
189
|
+
ui?: McpUiResourceMeta;
|
|
190
|
+
[key: string]: unknown;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
export type McpUiReadResourceCallback = (uri: URL, extra: Parameters<_ReadResourceCallback>[1]) => McpUiReadResourceResult | Promise<McpUiReadResourceResult>;
|
|
194
|
+
export type ReadResourceCallback = McpUiReadResourceCallback;
|
|
180
195
|
/**
|
|
181
196
|
* Register an app resource with the MCP server.
|
|
182
197
|
*
|
|
@@ -211,7 +226,7 @@ export declare function registerAppTool<OutputArgs extends ZodRawShapeCompat | A
|
|
|
211
226
|
* );
|
|
212
227
|
* ```
|
|
213
228
|
*
|
|
214
|
-
* @example With CSP configuration for
|
|
229
|
+
* @example With CSP configuration for network access
|
|
215
230
|
* ```ts source="./index.examples.ts#registerAppResource_withCsp"
|
|
216
231
|
* registerAppResource(
|
|
217
232
|
* server,
|
|
@@ -240,9 +255,57 @@ export declare function registerAppTool<OutputArgs extends ZodRawShapeCompat | A
|
|
|
240
255
|
* );
|
|
241
256
|
* ```
|
|
242
257
|
*
|
|
258
|
+
* @example With stable origin for external API CORS allowlists
|
|
259
|
+
* ```ts source="./index.examples.ts#registerAppResource_withDomain"
|
|
260
|
+
* // Computes a stable origin from an MCP server URL for hosting in Claude.
|
|
261
|
+
* function computeAppDomainForClaude(mcpServerUrl: string): string {
|
|
262
|
+
* const hash = crypto
|
|
263
|
+
* .createHash("sha256")
|
|
264
|
+
* .update(mcpServerUrl)
|
|
265
|
+
* .digest("hex")
|
|
266
|
+
* .slice(0, 32);
|
|
267
|
+
* return `${hash}.claudemcpcontent.com`;
|
|
268
|
+
* }
|
|
269
|
+
*
|
|
270
|
+
* const APP_DOMAIN = computeAppDomainForClaude("https://example.com/mcp");
|
|
271
|
+
*
|
|
272
|
+
* registerAppResource(
|
|
273
|
+
* server,
|
|
274
|
+
* "Company Dashboard",
|
|
275
|
+
* "ui://dashboard/view.html",
|
|
276
|
+
* {
|
|
277
|
+
* description: "Internal dashboard with company data",
|
|
278
|
+
* },
|
|
279
|
+
* async () => ({
|
|
280
|
+
* contents: [
|
|
281
|
+
* {
|
|
282
|
+
* uri: "ui://dashboard/view.html",
|
|
283
|
+
* mimeType: RESOURCE_MIME_TYPE,
|
|
284
|
+
* text: dashboardHtml,
|
|
285
|
+
* _meta: {
|
|
286
|
+
* ui: {
|
|
287
|
+
* // CSP: tell browser the app is allowed to make requests
|
|
288
|
+
* csp: {
|
|
289
|
+
* connectDomains: ["https://api.example.com"],
|
|
290
|
+
* },
|
|
291
|
+
* // CORS: give app a stable origin for the API server to allowlist
|
|
292
|
+
* //
|
|
293
|
+
* // (Public APIs that use `Access-Control-Allow-Origin: *` or API
|
|
294
|
+
* // key auth don't need this.)
|
|
295
|
+
* domain: APP_DOMAIN,
|
|
296
|
+
* },
|
|
297
|
+
* },
|
|
298
|
+
* },
|
|
299
|
+
* ],
|
|
300
|
+
* }),
|
|
301
|
+
* );
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @see {@link McpUiResourceMeta `McpUiResourceMeta`} for `_meta.ui` configuration options
|
|
305
|
+
* @see {@link McpUiResourceCsp `McpUiResourceCsp`} for CSP domain allowlist configuration
|
|
243
306
|
* @see {@link registerAppTool `registerAppTool`} to register tools that reference this resource
|
|
244
307
|
*/
|
|
245
|
-
export declare function registerAppResource(server: Pick<McpServer, "registerResource">, name: string, uri: string, config: McpUiAppResourceConfig, readCallback:
|
|
308
|
+
export declare function registerAppResource(server: Pick<McpServer, "registerResource">, name: string, uri: string, config: McpUiAppResourceConfig, readCallback: McpUiReadResourceCallback): RegisteredResource;
|
|
246
309
|
/**
|
|
247
310
|
* Extension identifier for MCP Apps capability negotiation.
|
|
248
311
|
*
|
|
@@ -263,21 +326,31 @@ export declare const EXTENSION_ID = "io.modelcontextprotocol/ui";
|
|
|
263
326
|
* @returns The MCP Apps capability settings, or `undefined` if not supported
|
|
264
327
|
*
|
|
265
328
|
* @example Check for MCP Apps support in server initialization
|
|
266
|
-
* ```
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* server.oninitialized = ({ clientCapabilities }) => {
|
|
329
|
+
* ```ts source="./index.examples.ts#getUiCapability_checkSupport"
|
|
330
|
+
* server.server.oninitialized = () => {
|
|
331
|
+
* const clientCapabilities = server.server.getClientCapabilities();
|
|
270
332
|
* const uiCap = getUiCapability(clientCapabilities);
|
|
333
|
+
*
|
|
271
334
|
* if (uiCap?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) {
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
335
|
+
* // App-enhanced tool
|
|
336
|
+
* registerAppTool(
|
|
337
|
+
* server,
|
|
338
|
+
* "weather",
|
|
339
|
+
* {
|
|
340
|
+
* description: "Get weather information with interactive dashboard",
|
|
341
|
+
* _meta: { ui: { resourceUri: "ui://weather/dashboard" } },
|
|
342
|
+
* },
|
|
343
|
+
* weatherHandler,
|
|
344
|
+
* );
|
|
276
345
|
* } else {
|
|
277
|
-
* //
|
|
278
|
-
* server.registerTool(
|
|
279
|
-
*
|
|
280
|
-
*
|
|
346
|
+
* // Text-only fallback
|
|
347
|
+
* server.registerTool(
|
|
348
|
+
* "weather",
|
|
349
|
+
* {
|
|
350
|
+
* description: "Get weather information",
|
|
351
|
+
* },
|
|
352
|
+
* textWeatherHandler,
|
|
353
|
+
* );
|
|
281
354
|
* }
|
|
282
355
|
* };
|
|
283
356
|
* ```
|