@blade-hq/agent-react 2612.0.0-beta.68 → 2612.0.0-beta.69
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/{chunk-SA2U6KC5.js → chunk-HCW7SI5Q.js} +321 -257
- package/dist/chunk-HCW7SI5Q.js.map +1 -0
- package/dist/{chunk-SK5LWVRX.js → chunk-XP6T6SHZ.js} +2 -2
- package/dist/components/McpAppFrame.d.ts +17 -0
- package/dist/index.js +2 -2
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +4 -2
- package/dist/internal.js.map +1 -1
- package/dist/tool-details.js +1 -1
- package/node_modules/@modelcontextprotocol/ext-apps/LICENSE +216 -0
- package/node_modules/@modelcontextprotocol/ext-apps/README.md +284 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/docs/patterns.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.d.ts +1348 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.js +39 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-bridge.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app-with-deps.js +82 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.d.ts +1214 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.js +39 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/app.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/constants.d.ts +65 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.d.ts +47 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/events.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.d.ts +1047 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.json +6170 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/generated/schema.test.d.ts +41 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/interop-v1.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.d.ts +66 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/legacy-handlers.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.d.ts +126 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/message-transport.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.d.ts +37 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/index.js +39 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/react-with-deps.js +82 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.d.ts +115 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useApp.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.d.ts +54 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useAutoResize.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.d.ts +44 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useDocumentTheme.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.d.ts +113 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/react/useHostStyles.examples.d.ts +6 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.d.ts +381 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.js +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/server/index.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/spec.types.d.ts +698 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/standard-schema.d.ts +23 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.d.ts +184 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/styles.examples.d.ts +9 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/types.d.ts +33 -0
- package/node_modules/@modelcontextprotocol/ext-apps/dist/src/wire-compat.test.d.ts +1 -0
- package/node_modules/@modelcontextprotocol/ext-apps/package.json +144 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/package.json +6 -2
- package/dist/chunk-SA2U6KC5.js.map +0 -1
- /package/dist/{chunk-SK5LWVRX.js.map → chunk-XP6T6SHZ.js.map} +0 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for MCP servers to register tools and resources that display interactive UIs.
|
|
3
|
+
*
|
|
4
|
+
* Use these helpers instead of the base SDK's `registerTool` and `registerResource` when
|
|
5
|
+
* your tool should render an {@link app!App `App`} in the client. They handle UI metadata normalization
|
|
6
|
+
* and provide sensible defaults for the MCP Apps MIME type ({@link RESOURCE_MIME_TYPE `RESOURCE_MIME_TYPE`}).
|
|
7
|
+
*
|
|
8
|
+
* @module server-helpers
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts source="./index.examples.ts#index_overview"
|
|
12
|
+
* // Register a tool that displays a view
|
|
13
|
+
* registerAppTool(
|
|
14
|
+
* server,
|
|
15
|
+
* "weather",
|
|
16
|
+
* {
|
|
17
|
+
* description: "Get weather forecast",
|
|
18
|
+
* _meta: { ui: { resourceUri: "ui://weather/view.html" } },
|
|
19
|
+
* },
|
|
20
|
+
* toolCallback,
|
|
21
|
+
* );
|
|
22
|
+
*
|
|
23
|
+
* // Register the HTML resource the tool references
|
|
24
|
+
* registerAppResource(
|
|
25
|
+
* server,
|
|
26
|
+
* "Weather View",
|
|
27
|
+
* "ui://weather/view.html",
|
|
28
|
+
* {},
|
|
29
|
+
* readCallback,
|
|
30
|
+
* );
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
import { McpUiResourceMeta, McpUiToolMeta, McpUiClientCapabilities } from "../spec.types.js";
|
|
34
|
+
import { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE } from "../constants.js";
|
|
35
|
+
import type { CallToolResult, ClientCapabilities, InputRequiredResult, McpServer, ReadResourceResult, RegisteredTool, ResourceMetadata, ServerContext, StandardSchemaWithJSON, ToolAnnotations, ToolCallback, ReadResourceCallback as _ReadResourceCallback, RegisteredResource } from "@modelcontextprotocol/server";
|
|
36
|
+
import type { z } from "zod/v4";
|
|
37
|
+
export { RESOURCE_URI_META_KEY, RESOURCE_MIME_TYPE };
|
|
38
|
+
export type { ResourceMetadata, ToolCallback };
|
|
39
|
+
/**
|
|
40
|
+
* A plain `{ field: z.string() }` record accepted by the deprecated raw-shape
|
|
41
|
+
* form of {@link registerAppTool `registerAppTool`}; the SDK auto-wraps it with `z.object()`.
|
|
42
|
+
*
|
|
43
|
+
* @deprecated Wrap with `z.object({...})` instead.
|
|
44
|
+
*/
|
|
45
|
+
export type ZodRawShape = Record<string, z.ZodType>;
|
|
46
|
+
/**
|
|
47
|
+
* {@link ToolCallback `ToolCallback`} variant used when `inputSchema` is a {@link ZodRawShape `ZodRawShape`}.
|
|
48
|
+
* Mirrors the callback type of the SDK's deprecated `registerTool` overload.
|
|
49
|
+
*
|
|
50
|
+
* @deprecated Wrap with `z.object({...})` instead and use {@link ToolCallback `ToolCallback`}.
|
|
51
|
+
*/
|
|
52
|
+
export type LegacyToolCallback<Args extends ZodRawShape | undefined> = Args extends ZodRawShape ? (args: z.infer<z.ZodObject<Args>>, ctx: ServerContext) => CallToolResult | InputRequiredResult | Promise<CallToolResult | InputRequiredResult> : (ctx: ServerContext) => CallToolResult | InputRequiredResult | Promise<CallToolResult | InputRequiredResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Base tool configuration matching the standard MCP server tool options.
|
|
55
|
+
* Extended by {@link McpUiAppToolConfig `McpUiAppToolConfig`} to add UI metadata requirements.
|
|
56
|
+
*
|
|
57
|
+
* `inputSchema`/`outputSchema` accept any Standard JSON Schema (zod v4, ArkType,
|
|
58
|
+
* Valibot, ...). A raw zod shape (`{ field: z.string() }`) is still accepted for
|
|
59
|
+
* backward compatibility but deprecated.
|
|
60
|
+
*/
|
|
61
|
+
export interface ToolConfig {
|
|
62
|
+
title?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
inputSchema?: ZodRawShape | StandardSchemaWithJSON;
|
|
65
|
+
outputSchema?: ZodRawShape | StandardSchemaWithJSON;
|
|
66
|
+
annotations?: ToolAnnotations;
|
|
67
|
+
_meta?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Configuration for tools that render an interactive UI.
|
|
71
|
+
*
|
|
72
|
+
* Extends {@link ToolConfig `ToolConfig`} with a required `_meta` field that specifies UI metadata.
|
|
73
|
+
* The UI resource can be specified in two ways:
|
|
74
|
+
* - `_meta.ui.resourceUri` (preferred)
|
|
75
|
+
* - `_meta["ui/resourceUri"]` (deprecated, for backward compatibility)
|
|
76
|
+
*
|
|
77
|
+
* @see {@link registerAppTool `registerAppTool`} for the recommended way to register app tools
|
|
78
|
+
*/
|
|
79
|
+
export interface McpUiAppToolConfig extends ToolConfig {
|
|
80
|
+
_meta: {
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
} & ({
|
|
83
|
+
ui: McpUiToolMeta;
|
|
84
|
+
} | {
|
|
85
|
+
/**
|
|
86
|
+
* URI of the UI resource to display for this tool.
|
|
87
|
+
* This is converted to `_meta["ui/resourceUri"]`.
|
|
88
|
+
*
|
|
89
|
+
* @example "ui://weather/view.html"
|
|
90
|
+
*
|
|
91
|
+
* @deprecated Use `_meta.ui.resourceUri` instead.
|
|
92
|
+
*/
|
|
93
|
+
[RESOURCE_URI_META_KEY]?: string;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* MCP App Resource configuration for {@link registerAppResource `registerAppResource`}.
|
|
98
|
+
*
|
|
99
|
+
* Extends the base MCP SDK `ResourceMetadata` with optional UI metadata
|
|
100
|
+
* for configuring security policies and rendering preferences.
|
|
101
|
+
*
|
|
102
|
+
* The `_meta.ui` field here is included in the `resources/list` response and serves as
|
|
103
|
+
* a static default for hosts to review at connection time. When the `resources/read`
|
|
104
|
+
* content item also includes `_meta.ui`, the content-item value takes precedence.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link registerAppResource `registerAppResource`} for usage
|
|
107
|
+
*/
|
|
108
|
+
export interface McpUiAppResourceConfig extends ResourceMetadata {
|
|
109
|
+
/**
|
|
110
|
+
* Optional UI metadata for the resource.
|
|
111
|
+
*
|
|
112
|
+
* This appears on the resource entry in `resources/list` and acts as a listing-level
|
|
113
|
+
* fallback. Individual content items returned by `resources/read` may include their
|
|
114
|
+
* own `_meta.ui` which takes precedence over this value.
|
|
115
|
+
*/
|
|
116
|
+
_meta?: {
|
|
117
|
+
/**
|
|
118
|
+
* UI-specific metadata including CSP configuration and rendering preferences.
|
|
119
|
+
*/
|
|
120
|
+
ui?: McpUiResourceMeta;
|
|
121
|
+
[key: string]: unknown;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Register an app tool with the MCP server.
|
|
126
|
+
*
|
|
127
|
+
* This is a convenience wrapper around `server.registerTool` that normalizes
|
|
128
|
+
* UI metadata: if `_meta.ui.resourceUri` is set, the legacy `_meta["ui/resourceUri"]`
|
|
129
|
+
* key is also populated (and vice versa) for compatibility with older hosts.
|
|
130
|
+
*
|
|
131
|
+
* @param server - The MCP server instance
|
|
132
|
+
* @param name - Tool name/identifier
|
|
133
|
+
* @param config - Tool configuration with `_meta` field containing UI metadata
|
|
134
|
+
* @param cb - Tool handler function
|
|
135
|
+
*
|
|
136
|
+
* @example Basic usage
|
|
137
|
+
* ```ts source="./index.examples.ts#registerAppTool_basicUsage"
|
|
138
|
+
* registerAppTool(
|
|
139
|
+
* server,
|
|
140
|
+
* "get-weather",
|
|
141
|
+
* {
|
|
142
|
+
* title: "Get Weather",
|
|
143
|
+
* description: "Get current weather for a location",
|
|
144
|
+
* inputSchema: z.object({ location: z.string() }),
|
|
145
|
+
* _meta: {
|
|
146
|
+
* ui: { resourceUri: "ui://weather/view.html" },
|
|
147
|
+
* },
|
|
148
|
+
* },
|
|
149
|
+
* async (args) => {
|
|
150
|
+
* const weather = await fetchWeather(args.location);
|
|
151
|
+
* return { content: [{ type: "text", text: JSON.stringify(weather) }] };
|
|
152
|
+
* },
|
|
153
|
+
* );
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* @example Tool visible to model but not callable by UI
|
|
157
|
+
* ```ts source="./index.examples.ts#registerAppTool_modelOnlyVisibility"
|
|
158
|
+
* registerAppTool(
|
|
159
|
+
* server,
|
|
160
|
+
* "show-cart",
|
|
161
|
+
* {
|
|
162
|
+
* description: "Display the user's shopping cart",
|
|
163
|
+
* _meta: {
|
|
164
|
+
* ui: {
|
|
165
|
+
* resourceUri: "ui://shop/cart.html",
|
|
166
|
+
* visibility: ["model"],
|
|
167
|
+
* },
|
|
168
|
+
* },
|
|
169
|
+
* },
|
|
170
|
+
* async () => {
|
|
171
|
+
* const cart = await getCart();
|
|
172
|
+
* return { content: [{ type: "text", text: JSON.stringify(cart) }] };
|
|
173
|
+
* },
|
|
174
|
+
* );
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @example Tool hidden from model, only callable by UI
|
|
178
|
+
* ```ts source="./index.examples.ts#registerAppTool_appOnlyVisibility"
|
|
179
|
+
* registerAppTool(
|
|
180
|
+
* server,
|
|
181
|
+
* "update-quantity",
|
|
182
|
+
* {
|
|
183
|
+
* description: "Update item quantity in cart",
|
|
184
|
+
* inputSchema: z.object({ itemId: z.string(), quantity: z.number() }),
|
|
185
|
+
* _meta: {
|
|
186
|
+
* ui: {
|
|
187
|
+
* resourceUri: "ui://shop/cart.html",
|
|
188
|
+
* visibility: ["app"],
|
|
189
|
+
* },
|
|
190
|
+
* },
|
|
191
|
+
* },
|
|
192
|
+
* async ({ itemId, quantity }) => {
|
|
193
|
+
* const cart = await updateCartItem(itemId, quantity);
|
|
194
|
+
* return { content: [{ type: "text", text: JSON.stringify(cart) }] };
|
|
195
|
+
* },
|
|
196
|
+
* );
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @see {@link registerAppResource `registerAppResource`} to register the HTML resource referenced by the tool
|
|
200
|
+
*/
|
|
201
|
+
export declare function registerAppTool<OutputArgs extends StandardSchemaWithJSON, InputArgs extends StandardSchemaWithJSON | undefined = undefined>(server: Pick<McpServer, "registerTool">, name: string, config: McpUiAppToolConfig & {
|
|
202
|
+
inputSchema?: InputArgs;
|
|
203
|
+
outputSchema?: OutputArgs;
|
|
204
|
+
}, cb: ToolCallback<InputArgs>): RegisteredTool;
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated Wrap with `z.object({...})` instead. Raw-shape form:
|
|
207
|
+
* `inputSchema`/`outputSchema` may be a plain `{ field: z.string() }` record;
|
|
208
|
+
* the SDK auto-wraps it with `z.object()`.
|
|
209
|
+
*/
|
|
210
|
+
export declare function registerAppTool<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape | StandardSchemaWithJSON | undefined = undefined>(server: Pick<McpServer, "registerTool">, name: string, config: McpUiAppToolConfig & {
|
|
211
|
+
inputSchema?: InputArgs;
|
|
212
|
+
outputSchema?: OutputArgs;
|
|
213
|
+
}, cb: LegacyToolCallback<InputArgs>): RegisteredTool;
|
|
214
|
+
export type McpUiReadResourceResult = ReadResourceResult & {
|
|
215
|
+
_meta?: {
|
|
216
|
+
ui?: McpUiResourceMeta;
|
|
217
|
+
[key: string]: unknown;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
export type McpUiReadResourceCallback = (uri: URL, extra: Parameters<_ReadResourceCallback>[1]) => McpUiReadResourceResult | Promise<McpUiReadResourceResult>;
|
|
221
|
+
export type ReadResourceCallback = McpUiReadResourceCallback;
|
|
222
|
+
/**
|
|
223
|
+
* Register an app resource with the MCP server.
|
|
224
|
+
*
|
|
225
|
+
* This is a convenience wrapper around `server.registerResource` that:
|
|
226
|
+
* - Defaults the MIME type to {@link RESOURCE_MIME_TYPE `RESOURCE_MIME_TYPE`} (`"text/html;profile=mcp-app"`)
|
|
227
|
+
* - Provides a cleaner API matching the SDK's callback signature
|
|
228
|
+
*
|
|
229
|
+
* @param server - The MCP server instance
|
|
230
|
+
* @param name - Human-readable resource name
|
|
231
|
+
* @param uri - Resource URI (should match the `_meta.ui` field in tool config)
|
|
232
|
+
* @param config - Resource configuration
|
|
233
|
+
* @param readCallback - Callback that returns the resource contents
|
|
234
|
+
*
|
|
235
|
+
* @example Basic usage
|
|
236
|
+
* ```ts source="./index.examples.ts#registerAppResource_basicUsage"
|
|
237
|
+
* registerAppResource(
|
|
238
|
+
* server,
|
|
239
|
+
* "Weather View",
|
|
240
|
+
* "ui://weather/view.html",
|
|
241
|
+
* {
|
|
242
|
+
* description: "Interactive weather display",
|
|
243
|
+
* },
|
|
244
|
+
* async () => ({
|
|
245
|
+
* contents: [
|
|
246
|
+
* {
|
|
247
|
+
* uri: "ui://weather/view.html",
|
|
248
|
+
* mimeType: RESOURCE_MIME_TYPE,
|
|
249
|
+
* text: await fs.readFile("dist/view.html", "utf-8"),
|
|
250
|
+
* },
|
|
251
|
+
* ],
|
|
252
|
+
* }),
|
|
253
|
+
* );
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* @example With CSP configuration for network access
|
|
257
|
+
* ```ts source="./index.examples.ts#registerAppResource_withCsp"
|
|
258
|
+
* registerAppResource(
|
|
259
|
+
* server,
|
|
260
|
+
* "Music Player",
|
|
261
|
+
* "ui://music/player.html",
|
|
262
|
+
* {
|
|
263
|
+
* description: "Audio player with external soundfonts",
|
|
264
|
+
* },
|
|
265
|
+
* async () => ({
|
|
266
|
+
* contents: [
|
|
267
|
+
* {
|
|
268
|
+
* uri: "ui://music/player.html",
|
|
269
|
+
* mimeType: RESOURCE_MIME_TYPE,
|
|
270
|
+
* text: musicPlayerHtml,
|
|
271
|
+
* _meta: {
|
|
272
|
+
* ui: {
|
|
273
|
+
* csp: {
|
|
274
|
+
* resourceDomains: ["https://cdn.example.com"], // For scripts/styles/images
|
|
275
|
+
* connectDomains: ["https://api.example.com"], // For fetch/WebSocket
|
|
276
|
+
* },
|
|
277
|
+
* },
|
|
278
|
+
* },
|
|
279
|
+
* },
|
|
280
|
+
* ],
|
|
281
|
+
* }),
|
|
282
|
+
* );
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @example With stable origin for external API CORS allowlists
|
|
286
|
+
* ```ts source="./index.examples.ts#registerAppResource_withDomain"
|
|
287
|
+
* // Computes a stable origin from an MCP server URL for hosting in Claude.
|
|
288
|
+
* function computeAppDomainForClaude(mcpServerUrl: string): string {
|
|
289
|
+
* const hash = crypto
|
|
290
|
+
* .createHash("sha256")
|
|
291
|
+
* .update(mcpServerUrl)
|
|
292
|
+
* .digest("hex")
|
|
293
|
+
* .slice(0, 32);
|
|
294
|
+
* return `${hash}.claudemcpcontent.com`;
|
|
295
|
+
* }
|
|
296
|
+
*
|
|
297
|
+
* const APP_DOMAIN = computeAppDomainForClaude("https://example.com/mcp");
|
|
298
|
+
*
|
|
299
|
+
* registerAppResource(
|
|
300
|
+
* server,
|
|
301
|
+
* "Company Dashboard",
|
|
302
|
+
* "ui://dashboard/view.html",
|
|
303
|
+
* {
|
|
304
|
+
* description: "Internal dashboard with company data",
|
|
305
|
+
* },
|
|
306
|
+
* async () => ({
|
|
307
|
+
* contents: [
|
|
308
|
+
* {
|
|
309
|
+
* uri: "ui://dashboard/view.html",
|
|
310
|
+
* mimeType: RESOURCE_MIME_TYPE,
|
|
311
|
+
* text: dashboardHtml,
|
|
312
|
+
* _meta: {
|
|
313
|
+
* ui: {
|
|
314
|
+
* // CSP: tell browser the app is allowed to make requests
|
|
315
|
+
* csp: {
|
|
316
|
+
* connectDomains: ["https://api.example.com"],
|
|
317
|
+
* },
|
|
318
|
+
* // CORS: give app a stable origin for the API server to allowlist
|
|
319
|
+
* //
|
|
320
|
+
* // (Public APIs that use `Access-Control-Allow-Origin: *` or API
|
|
321
|
+
* // key auth don't need this.)
|
|
322
|
+
* domain: APP_DOMAIN,
|
|
323
|
+
* },
|
|
324
|
+
* },
|
|
325
|
+
* },
|
|
326
|
+
* ],
|
|
327
|
+
* }),
|
|
328
|
+
* );
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* @see {@link McpUiResourceMeta `McpUiResourceMeta`} for `_meta.ui` configuration options
|
|
332
|
+
* @see {@link McpUiResourceCsp `McpUiResourceCsp`} for CSP domain allowlist configuration
|
|
333
|
+
* @see {@link registerAppTool `registerAppTool`} to register tools that reference this resource
|
|
334
|
+
*/
|
|
335
|
+
export declare function registerAppResource(server: Pick<McpServer, "registerResource">, name: string, uri: string, config: McpUiAppResourceConfig, readCallback: McpUiReadResourceCallback): RegisteredResource;
|
|
336
|
+
/**
|
|
337
|
+
* Extension identifier for MCP Apps capability negotiation.
|
|
338
|
+
*
|
|
339
|
+
* Used as the key in `extensions` to advertise MCP Apps support.
|
|
340
|
+
*/
|
|
341
|
+
export declare const EXTENSION_ID = "io.modelcontextprotocol/ui";
|
|
342
|
+
/**
|
|
343
|
+
* Get MCP Apps capability settings from client capabilities.
|
|
344
|
+
*
|
|
345
|
+
* This helper retrieves the capability object from the `extensions` field
|
|
346
|
+
* where MCP Apps advertises its support.
|
|
347
|
+
*
|
|
348
|
+
* @param clientCapabilities - The client capabilities from the initialize response
|
|
349
|
+
* @returns The MCP Apps capability settings, or `undefined` if not supported
|
|
350
|
+
*
|
|
351
|
+
* @example Check for MCP Apps support in server initialization
|
|
352
|
+
* ```ts source="./index.examples.ts#getUiCapability_checkSupport"
|
|
353
|
+
* server.server.oninitialized = () => {
|
|
354
|
+
* const clientCapabilities = server.server.getClientCapabilities();
|
|
355
|
+
* const uiCap = getUiCapability(clientCapabilities);
|
|
356
|
+
*
|
|
357
|
+
* if (uiCap?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) {
|
|
358
|
+
* // App-enhanced tool
|
|
359
|
+
* registerAppTool(
|
|
360
|
+
* server,
|
|
361
|
+
* "weather",
|
|
362
|
+
* {
|
|
363
|
+
* description: "Get weather information with interactive dashboard",
|
|
364
|
+
* _meta: { ui: { resourceUri: "ui://weather/dashboard" } },
|
|
365
|
+
* },
|
|
366
|
+
* weatherHandler,
|
|
367
|
+
* );
|
|
368
|
+
* } else {
|
|
369
|
+
* // Text-only fallback
|
|
370
|
+
* server.registerTool(
|
|
371
|
+
* "weather",
|
|
372
|
+
* {
|
|
373
|
+
* description: "Get weather information",
|
|
374
|
+
* },
|
|
375
|
+
* textWeatherHandler,
|
|
376
|
+
* );
|
|
377
|
+
* }
|
|
378
|
+
* };
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
export declare function getUiCapability(clientCapabilities: ClientCapabilities | null | undefined): McpUiClientCapabilities | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-checked examples for {@link registerAppTool `registerAppTool`} and {@link registerAppResource `registerAppResource`}.
|
|
3
|
+
*
|
|
4
|
+
* These examples are included in the API documentation via `@includeCode` tags.
|
|
5
|
+
* Each function's region markers define the code snippet that appears in the docs.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var D="ui/resourceUri",L="text/html;profile=mcp-app";function j(B,Q,F,V){let q=F._meta,J=q.ui,Z=q[D],$=q;if(J?.resourceUri&&!Z)$={...q,[D]:J.resourceUri};else if(Z&&!J?.resourceUri)$={...q,ui:{...J,resourceUri:Z}};return B.registerTool(Q,{...F,_meta:$},V)}function G(B,Q,F,V,q){return B.registerResource(Q,F,{mimeType:L,...V},q)}var W="io.modelcontextprotocol/ui";function H(B){if(!B)return;return B.extensions?.[W]}export{j as registerAppTool,G as registerAppResource,H as getUiCapability,D as RESOURCE_URI_META_KEY,L as RESOURCE_MIME_TYPE,W as EXTENSION_ID};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|