xmcp 0.7.0 → 0.7.1
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/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -3
- package/src/auth/api-key.ts +0 -120
- package/src/auth/jwt.ts +0 -52
- package/src/cli/commands/create/__tests__/create.test.ts +0 -99
- package/src/cli/commands/create/index.ts +0 -74
- package/src/cli/commands/create/templates/index.ts +0 -4
- package/src/cli/commands/create/templates/prompt.ts +0 -30
- package/src/cli/commands/create/templates/resource.ts +0 -20
- package/src/cli/commands/create/templates/tool.ts +0 -34
- package/src/cli/commands/create/templates/widget.ts +0 -33
- package/src/cli/utils/naming.ts +0 -39
- package/src/cli.ts +0 -125
- package/src/client/headers.ts +0 -61
- package/src/client/index.ts +0 -180
- package/src/client/types.ts +0 -122
- package/src/client/utils.ts +0 -133
- package/src/cloudflare.ts +0 -6
- package/src/compiler/build-telemetry.ts +0 -88
- package/src/compiler/client/component-compiler.ts +0 -250
- package/src/compiler/client/transpile.ts +0 -21
- package/src/compiler/compiler-context.ts +0 -61
- package/src/compiler/config/__tests__/config.test.ts +0 -459
- package/src/compiler/config/index.ts +0 -62
- package/src/compiler/config/injection.ts +0 -210
- package/src/compiler/config/schemas/bundler.ts +0 -12
- package/src/compiler/config/schemas/experimental/index.ts +0 -22
- package/src/compiler/config/schemas/index.ts +0 -20
- package/src/compiler/config/schemas/paths.ts +0 -35
- package/src/compiler/config/schemas/template.ts +0 -80
- package/src/compiler/config/schemas/transport/http.ts +0 -116
- package/src/compiler/config/schemas/transport/stdio.ts +0 -31
- package/src/compiler/config/schemas/typescript.ts +0 -26
- package/src/compiler/config/utils.ts +0 -168
- package/src/compiler/generate-env-code.ts +0 -5
- package/src/compiler/generate-import-code.ts +0 -187
- package/src/compiler/generate-tools-code.ts +0 -174
- package/src/compiler/get-bundler-config/get-entries.ts +0 -44
- package/src/compiler/get-bundler-config/get-externals.ts +0 -114
- package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
- package/src/compiler/get-bundler-config/index.ts +0 -288
- package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
- package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
- package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
- package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
- package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
- package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
- package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
- package/src/compiler/index.ts +0 -484
- package/src/compiler/on-first-build.ts +0 -54
- package/src/compiler/parse-xmcp-config.ts +0 -200
- package/src/compiler/start-http-server.ts +0 -42
- package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
- package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
- package/src/compiler/utils/config-detection.ts +0 -34
- package/src/compiler/utils/path-utils.ts +0 -22
- package/src/compiler/watcher-recovery.ts +0 -72
- package/src/host-bridge.ts +0 -36
- package/src/index.ts +0 -94
- package/src/platforms/build-cloudflare-output.ts +0 -116
- package/src/platforms/build-vercel-output.ts +0 -131
- package/src/plugins/index.ts +0 -1
- package/src/plugins/x402/index.ts +0 -24
- package/src/runtime/adapters/express/index.ts +0 -75
- package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
- package/src/runtime/adapters/fastify/index.ts +0 -78
- package/src/runtime/adapters/nestjs/index.ts +0 -16
- package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
- package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
- package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
- package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
- package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
- package/src/runtime/adapters/nextjs/auth.ts +0 -265
- package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
- package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
- package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
- package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
- package/src/runtime/adapters/nextjs/index.ts +0 -121
- package/src/runtime/contexts/client-info-context.ts +0 -16
- package/src/runtime/contexts/http-request-context.ts +0 -21
- package/src/runtime/contexts/http-transport-context.ts +0 -18
- package/src/runtime/headers.ts +0 -42
- package/src/runtime/middlewares/utils.ts +0 -72
- package/src/runtime/platforms/cloudflare/cors.ts +0 -44
- package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
- package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
- package/src/runtime/platforms/cloudflare/types.ts +0 -23
- package/src/runtime/platforms/cloudflare/worker.ts +0 -270
- package/src/runtime/templates/home.ts +0 -746
- package/src/runtime/transports/http/base-streamable-http.ts +0 -46
- package/src/runtime/transports/http/cors/headers.ts +0 -58
- package/src/runtime/transports/http/cors/index.ts +0 -34
- package/src/runtime/transports/http/index.ts +0 -78
- package/src/runtime/transports/http/stateless-streamable-http.ts +0 -353
- package/src/runtime/transports/http/web-stateless-http.ts +0 -288
- package/src/runtime/transports/stdio/index.ts +0 -109
- package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
- package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
- package/src/runtime/utils/client-info.ts +0 -114
- package/src/runtime/utils/elicitation.ts +0 -396
- package/src/runtime/utils/ext-apps-registry.ts +0 -151
- package/src/runtime/utils/mcp-app-protocol.ts +0 -16
- package/src/runtime/utils/mcp-app-types.ts +0 -113
- package/src/runtime/utils/mcp-host-bridge.ts +0 -473
- package/src/runtime/utils/path-to-tool-name.ts +0 -69
- package/src/runtime/utils/prompt-loader.ts +0 -151
- package/src/runtime/utils/prompts.ts +0 -69
- package/src/runtime/utils/react/generate-html.ts +0 -69
- package/src/runtime/utils/react/index.ts +0 -6
- package/src/runtime/utils/request-tool-names.ts +0 -48
- package/src/runtime/utils/resource-loader.ts +0 -151
- package/src/runtime/utils/resources.ts +0 -331
- package/src/runtime/utils/server.ts +0 -107
- package/src/runtime/utils/tool-loader.ts +0 -149
- package/src/runtime/utils/tools.ts +0 -183
- package/src/runtime/utils/transformers/prompt.ts +0 -120
- package/src/runtime/utils/transformers/resource.ts +0 -196
- package/src/runtime/utils/transformers/tool.ts +0 -400
- package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
- package/src/runtime/utils/ui/flatten-meta.ts +0 -44
- package/src/runtime/utils/ui/split-meta.ts +0 -78
- package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
- package/src/runtime/utils/validators/index.ts +0 -138
- package/src/telemetry/ci-info.ts +0 -6
- package/src/telemetry/debug.ts +0 -8
- package/src/telemetry/events/definitions.ts +0 -52
- package/src/telemetry/events/detached-flush.ts +0 -83
- package/src/telemetry/events/post-payload.ts +0 -141
- package/src/telemetry/events/tracker.ts +0 -281
- package/src/telemetry/index.ts +0 -7
- package/src/telemetry/metadata.ts +0 -49
- package/src/telemetry/project-id.ts +0 -35
- package/src/telemetry/storage.ts +0 -218
- package/src/types/adapter.d.ts +0 -5
- package/src/types/client-info.ts +0 -20
- package/src/types/declarations.ts +0 -37
- package/src/types/injected.d.ts +0 -62
- package/src/types/middleware.ts +0 -19
- package/src/types/prompt.ts +0 -6
- package/src/types/resource.ts +0 -15
- package/src/types/tool.ts +0 -192
- package/src/types/ui-meta.ts +0 -42
- package/src/utils/cli-icons.ts +0 -5
- package/src/utils/constants.ts +0 -31
- package/src/utils/context.ts +0 -105
- package/src/utils/detect-package-manager.ts +0 -46
- package/src/utils/file-watcher.ts +0 -66
- package/src/utils/fs-utils.ts +0 -16
- package/src/utils/path-validation.ts +0 -66
- package/src/utils/port-utils.ts +0 -43
- package/src/utils/spawn-process.ts +0 -49
- package/src/utils/subscribable.ts +0 -62
|
@@ -1,396 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ElicitRequestFormParamsSchema,
|
|
3
|
-
ElicitRequestURLParamsSchema,
|
|
4
|
-
ElicitResultSchema,
|
|
5
|
-
} from "@modelcontextprotocol/sdk/types";
|
|
6
|
-
import type {
|
|
7
|
-
ElicitFormField,
|
|
8
|
-
ElicitFormRequest,
|
|
9
|
-
ElicitRequest,
|
|
10
|
-
ElicitResult,
|
|
11
|
-
ElicitUrlRequest,
|
|
12
|
-
ToolExtraArguments,
|
|
13
|
-
ToolRequestOptions,
|
|
14
|
-
} from "@/types/tool";
|
|
15
|
-
|
|
16
|
-
type ElicitRequestSender = Pick<ToolExtraArguments, "sendRequest">;
|
|
17
|
-
|
|
18
|
-
const ALLOWED_FORM_REQUEST_KEYS = new Set(["message", "mode", "requestedSchema"]);
|
|
19
|
-
const ALLOWED_URL_REQUEST_KEYS = new Set([
|
|
20
|
-
"elicitationId",
|
|
21
|
-
"message",
|
|
22
|
-
"mode",
|
|
23
|
-
"url",
|
|
24
|
-
]);
|
|
25
|
-
const ALLOWED_FORM_SCHEMA_KEYS = new Set(["properties", "required", "type"]);
|
|
26
|
-
const ALLOWED_STRING_FIELD_KEYS = new Set([
|
|
27
|
-
"default",
|
|
28
|
-
"description",
|
|
29
|
-
"format",
|
|
30
|
-
"maxLength",
|
|
31
|
-
"minLength",
|
|
32
|
-
"title",
|
|
33
|
-
"type",
|
|
34
|
-
]);
|
|
35
|
-
const ALLOWED_ENUM_FIELD_KEYS = new Set([
|
|
36
|
-
"default",
|
|
37
|
-
"description",
|
|
38
|
-
"enum",
|
|
39
|
-
"enumNames",
|
|
40
|
-
"title",
|
|
41
|
-
"type",
|
|
42
|
-
]);
|
|
43
|
-
const ALLOWED_BOOLEAN_FIELD_KEYS = new Set([
|
|
44
|
-
"default",
|
|
45
|
-
"description",
|
|
46
|
-
"title",
|
|
47
|
-
"type",
|
|
48
|
-
]);
|
|
49
|
-
const ALLOWED_NUMBER_FIELD_KEYS = new Set([
|
|
50
|
-
"default",
|
|
51
|
-
"description",
|
|
52
|
-
"maximum",
|
|
53
|
-
"minimum",
|
|
54
|
-
"title",
|
|
55
|
-
"type",
|
|
56
|
-
]);
|
|
57
|
-
const ALLOWED_STRING_FORMATS = new Set(["date", "date-time", "email", "uri"]);
|
|
58
|
-
|
|
59
|
-
export async function elicitFromTool(
|
|
60
|
-
extra: ElicitRequestSender,
|
|
61
|
-
request: ElicitRequest,
|
|
62
|
-
options?: ToolRequestOptions
|
|
63
|
-
): Promise<ElicitResult> {
|
|
64
|
-
const params = normalizeElicitationRequest(request);
|
|
65
|
-
const result = await extra.sendRequest(
|
|
66
|
-
{ method: "elicitation/create", params },
|
|
67
|
-
ElicitResultSchema,
|
|
68
|
-
options
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
...result,
|
|
73
|
-
content: result.content ?? undefined,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function normalizeElicitationRequest(request: ElicitRequest) {
|
|
78
|
-
const mode = request.mode ?? "form";
|
|
79
|
-
|
|
80
|
-
if (mode === "url") {
|
|
81
|
-
assertValidUrlRequest(request);
|
|
82
|
-
return ElicitRequestURLParamsSchema.parse(request);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (mode !== "form") {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Unsupported elicitation mode "${String((request as { mode?: unknown }).mode)}". Expected "form" or "url".`
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
assertValidFormRequest(request);
|
|
92
|
-
return ElicitRequestFormParamsSchema.parse({
|
|
93
|
-
...request,
|
|
94
|
-
mode: "form",
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function assertValidFormRequest(
|
|
99
|
-
request: ElicitRequest
|
|
100
|
-
): asserts request is ElicitFormRequest {
|
|
101
|
-
assertPlainObject(request, "Elicitation request must be a plain object.");
|
|
102
|
-
assertAllowedKeys(request, ALLOWED_FORM_REQUEST_KEYS, "Form elicitation");
|
|
103
|
-
assertString(request.message, "Form elicitation requires a string message.");
|
|
104
|
-
|
|
105
|
-
const requestedSchema = request.requestedSchema;
|
|
106
|
-
assertPlainObject(
|
|
107
|
-
requestedSchema,
|
|
108
|
-
"Form elicitation requires a flat object schema."
|
|
109
|
-
);
|
|
110
|
-
assertAllowedKeys(
|
|
111
|
-
requestedSchema,
|
|
112
|
-
ALLOWED_FORM_SCHEMA_KEYS,
|
|
113
|
-
"Form elicitation schema"
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
if (requestedSchema.type !== "object") {
|
|
117
|
-
throw new Error('Form elicitation schema must use type "object".');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
assertPlainObject(
|
|
121
|
-
requestedSchema.properties,
|
|
122
|
-
"Form elicitation schema requires a properties object."
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
for (const [fieldName, field] of Object.entries(requestedSchema.properties)) {
|
|
126
|
-
assertSupportedFormField(fieldName, field);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (typeof requestedSchema.required === "undefined") {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
!Array.isArray(requestedSchema.required) ||
|
|
135
|
-
requestedSchema.required.some((fieldName) => typeof fieldName !== "string")
|
|
136
|
-
) {
|
|
137
|
-
throw new Error(
|
|
138
|
-
"Form elicitation schema required fields must be a string array."
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
for (const fieldName of requestedSchema.required) {
|
|
143
|
-
if (!(fieldName in requestedSchema.properties)) {
|
|
144
|
-
throw new Error(
|
|
145
|
-
`Form elicitation schema required field "${fieldName}" is not defined in properties.`
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function assertValidUrlRequest(
|
|
152
|
-
request: ElicitRequest
|
|
153
|
-
): asserts request is ElicitUrlRequest {
|
|
154
|
-
assertPlainObject(request, "Elicitation request must be a plain object.");
|
|
155
|
-
assertAllowedKeys(request, ALLOWED_URL_REQUEST_KEYS, "URL elicitation");
|
|
156
|
-
assertString(request.message, "URL elicitation requires a string message.");
|
|
157
|
-
assertNonEmptyString(
|
|
158
|
-
request.elicitationId,
|
|
159
|
-
"URL elicitation requires a non-empty elicitationId."
|
|
160
|
-
);
|
|
161
|
-
assertNonEmptyString(request.url, "URL elicitation requires a non-empty URL.");
|
|
162
|
-
|
|
163
|
-
let parsedUrl: URL;
|
|
164
|
-
try {
|
|
165
|
-
parsedUrl = new URL(request.url);
|
|
166
|
-
} catch {
|
|
167
|
-
throw new Error("URL elicitation requires a valid http or https URL.");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
171
|
-
throw new Error("URL elicitation requires a valid http or https URL.");
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function assertSupportedFormField(
|
|
176
|
-
fieldName: string,
|
|
177
|
-
field: unknown
|
|
178
|
-
): asserts field is ElicitFormField {
|
|
179
|
-
assertPlainObject(
|
|
180
|
-
field,
|
|
181
|
-
`Form elicitation field "${fieldName}" must be a plain object.`
|
|
182
|
-
);
|
|
183
|
-
assertOptionalString(
|
|
184
|
-
field.title,
|
|
185
|
-
`Form elicitation field "${fieldName}" title must be a string.`
|
|
186
|
-
);
|
|
187
|
-
assertOptionalString(
|
|
188
|
-
field.description,
|
|
189
|
-
`Form elicitation field "${fieldName}" description must be a string.`
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
if (field.type === "string" && "enum" in field) {
|
|
193
|
-
assertAllowedKeys(
|
|
194
|
-
field,
|
|
195
|
-
ALLOWED_ENUM_FIELD_KEYS,
|
|
196
|
-
`Form elicitation field "${fieldName}"`
|
|
197
|
-
);
|
|
198
|
-
assertStringArray(
|
|
199
|
-
field.enum,
|
|
200
|
-
`Form elicitation field "${fieldName}" enum values must be strings.`
|
|
201
|
-
);
|
|
202
|
-
assertOptionalStringArray(
|
|
203
|
-
field.enumNames,
|
|
204
|
-
`Form elicitation field "${fieldName}" enumNames must be strings.`
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
if (
|
|
208
|
-
typeof field.enumNames !== "undefined" &&
|
|
209
|
-
field.enumNames.length !== field.enum.length
|
|
210
|
-
) {
|
|
211
|
-
throw new Error(
|
|
212
|
-
`Form elicitation field "${fieldName}" enumNames length must match enum length.`
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
assertOptionalString(
|
|
217
|
-
field.default,
|
|
218
|
-
`Form elicitation field "${fieldName}" default must be a string.`
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
if (
|
|
222
|
-
typeof field.default !== "undefined" &&
|
|
223
|
-
!field.enum.includes(field.default)
|
|
224
|
-
) {
|
|
225
|
-
throw new Error(
|
|
226
|
-
`Form elicitation field "${fieldName}" default must be one of its enum values.`
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (field.type === "string" && !("enum" in field)) {
|
|
234
|
-
assertAllowedKeys(
|
|
235
|
-
field,
|
|
236
|
-
ALLOWED_STRING_FIELD_KEYS,
|
|
237
|
-
`Form elicitation field "${fieldName}"`
|
|
238
|
-
);
|
|
239
|
-
assertOptionalNumber(
|
|
240
|
-
field.minLength,
|
|
241
|
-
`Form elicitation field "${fieldName}" minLength must be a number.`
|
|
242
|
-
);
|
|
243
|
-
assertOptionalNumber(
|
|
244
|
-
field.maxLength,
|
|
245
|
-
`Form elicitation field "${fieldName}" maxLength must be a number.`
|
|
246
|
-
);
|
|
247
|
-
assertOptionalString(
|
|
248
|
-
field.default,
|
|
249
|
-
`Form elicitation field "${fieldName}" default must be a string.`
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
const format = field.format;
|
|
253
|
-
assertOptionalString(
|
|
254
|
-
format,
|
|
255
|
-
`Form elicitation field "${fieldName}" format must be a string.`
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
if (typeof format !== "undefined" && !ALLOWED_STRING_FORMATS.has(format)) {
|
|
259
|
-
throw new Error(
|
|
260
|
-
`Form elicitation field "${fieldName}" format must be one of: ${Array.from(ALLOWED_STRING_FORMATS).join(", ")}.`
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (field.type === "boolean") {
|
|
268
|
-
assertAllowedKeys(
|
|
269
|
-
field,
|
|
270
|
-
ALLOWED_BOOLEAN_FIELD_KEYS,
|
|
271
|
-
`Form elicitation field "${fieldName}"`
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
if (
|
|
275
|
-
typeof field.default !== "undefined" &&
|
|
276
|
-
typeof field.default !== "boolean"
|
|
277
|
-
) {
|
|
278
|
-
throw new Error(
|
|
279
|
-
`Form elicitation field "${fieldName}" default must be a boolean.`
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (field.type === "number" || field.type === "integer") {
|
|
287
|
-
assertAllowedKeys(
|
|
288
|
-
field,
|
|
289
|
-
ALLOWED_NUMBER_FIELD_KEYS,
|
|
290
|
-
`Form elicitation field "${fieldName}"`
|
|
291
|
-
);
|
|
292
|
-
assertOptionalNumber(
|
|
293
|
-
field.minimum,
|
|
294
|
-
`Form elicitation field "${fieldName}" minimum must be a number.`
|
|
295
|
-
);
|
|
296
|
-
assertOptionalNumber(
|
|
297
|
-
field.maximum,
|
|
298
|
-
`Form elicitation field "${fieldName}" maximum must be a number.`
|
|
299
|
-
);
|
|
300
|
-
assertOptionalNumber(
|
|
301
|
-
field.default,
|
|
302
|
-
`Form elicitation field "${fieldName}" default must be a number.`
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
throw new Error(
|
|
309
|
-
`Form elicitation field "${fieldName}" uses unsupported type "${String((field as { type?: unknown }).type)}". Supported types are string, boolean, number, integer, and string enums.`
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function assertAllowedKeys(
|
|
314
|
-
value: Record<string, unknown>,
|
|
315
|
-
allowedKeys: Set<string>,
|
|
316
|
-
label: string
|
|
317
|
-
): void {
|
|
318
|
-
const extraKeys = Object.keys(value).filter((key) => !allowedKeys.has(key));
|
|
319
|
-
|
|
320
|
-
if (extraKeys.length === 0) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
throw new Error(
|
|
325
|
-
`${label} includes unsupported key(s): ${extraKeys.join(", ")}.`
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
function assertPlainObject(
|
|
330
|
-
value: unknown,
|
|
331
|
-
errorMessage: string
|
|
332
|
-
): asserts value is Record<string, unknown> {
|
|
333
|
-
if (
|
|
334
|
-
typeof value !== "object" ||
|
|
335
|
-
value === null ||
|
|
336
|
-
Array.isArray(value)
|
|
337
|
-
) {
|
|
338
|
-
throw new Error(errorMessage);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function assertString(
|
|
343
|
-
value: unknown,
|
|
344
|
-
errorMessage: string
|
|
345
|
-
): asserts value is string {
|
|
346
|
-
if (typeof value !== "string") {
|
|
347
|
-
throw new Error(errorMessage);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function assertNonEmptyString(
|
|
352
|
-
value: unknown,
|
|
353
|
-
errorMessage: string
|
|
354
|
-
): asserts value is string {
|
|
355
|
-
if (typeof value !== "string" || value.trim().length === 0) {
|
|
356
|
-
throw new Error(errorMessage);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
function assertOptionalString(
|
|
361
|
-
value: unknown,
|
|
362
|
-
errorMessage: string
|
|
363
|
-
): asserts value is string | undefined {
|
|
364
|
-
if (typeof value !== "undefined" && typeof value !== "string") {
|
|
365
|
-
throw new Error(errorMessage);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function assertOptionalNumber(
|
|
370
|
-
value: unknown,
|
|
371
|
-
errorMessage: string
|
|
372
|
-
): asserts value is number | undefined {
|
|
373
|
-
if (typeof value !== "undefined" && typeof value !== "number") {
|
|
374
|
-
throw new Error(errorMessage);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function assertStringArray(
|
|
379
|
-
value: unknown,
|
|
380
|
-
errorMessage: string
|
|
381
|
-
): asserts value is string[] {
|
|
382
|
-
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
383
|
-
throw new Error(errorMessage);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function assertOptionalStringArray(
|
|
388
|
-
value: unknown,
|
|
389
|
-
errorMessage: string
|
|
390
|
-
): asserts value is string[] | undefined {
|
|
391
|
-
if (typeof value === "undefined") {
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
assertStringArray(value, errorMessage);
|
|
396
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { UserToolHandler } from "./transformers/tool";
|
|
2
|
-
|
|
3
|
-
interface UIResourceMeta {
|
|
4
|
-
/**
|
|
5
|
-
* Content Security Policy configuration
|
|
6
|
-
*
|
|
7
|
-
* Servers declare which external origins their UI needs to access.
|
|
8
|
-
* Hosts use this to enforce appropriate CSP headers.
|
|
9
|
-
*/
|
|
10
|
-
csp?: {
|
|
11
|
-
/**
|
|
12
|
-
* Origins for network requests
|
|
13
|
-
*
|
|
14
|
-
* - Empty or omitted = no external connections (secure default)
|
|
15
|
-
* - Maps to CSP `connect-src` directive
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ["https://api.weather.com", "wss://realtime.service.com"]
|
|
19
|
-
*/
|
|
20
|
-
connectDomains?: string[];
|
|
21
|
-
/**
|
|
22
|
-
* Origins for static resources (images, scripts, stylesheets, fonts)
|
|
23
|
-
*
|
|
24
|
-
* - Empty or omitted = no external resources (secure default)
|
|
25
|
-
* - Wildcard subdomains supported: `https://*.example.com`
|
|
26
|
-
* - Maps to CSP `img-src`, `script-src`, `style-src`, `font-src` directives
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ["https://cdn.jsdelivr.net", "https://*.cloudflare.com"]
|
|
30
|
-
*/
|
|
31
|
-
resourceDomains?: string[];
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Dedicated origin for widget
|
|
35
|
-
*
|
|
36
|
-
* Optional domain for the widget's sandbox origin. Useful when widgets need
|
|
37
|
-
* dedicated origins for API key allowlists or cross-origin isolation.
|
|
38
|
-
*
|
|
39
|
-
* If omitted, Host uses default sandbox origin.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* "https://weather-widget.example.com"
|
|
43
|
-
*/
|
|
44
|
-
domain?: string;
|
|
45
|
-
/**
|
|
46
|
-
* Visual boundary preference
|
|
47
|
-
*
|
|
48
|
-
* Boolean indicating the UI prefers a visible border. Useful for widgets
|
|
49
|
-
* that might blend with host background.
|
|
50
|
-
*
|
|
51
|
-
* - `true`: Request visible border (host decides styling)
|
|
52
|
-
* - `false` or omitted: No preference
|
|
53
|
-
*/
|
|
54
|
-
prefersBorder?: boolean;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface UIResource {
|
|
58
|
-
/**
|
|
59
|
-
* Unique identifier for the UI resource
|
|
60
|
-
*
|
|
61
|
-
* MUST use the `ui://` URI scheme to distinguish UI resources from other
|
|
62
|
-
* MCP resource types.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* "ui://weather-dashboard"
|
|
66
|
-
*/
|
|
67
|
-
uri: string;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Human-readable display name for the UI resource
|
|
71
|
-
*
|
|
72
|
-
* Used for listing and identifying the resource in host interfaces.
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* "Weather Dashboard"
|
|
76
|
-
*/
|
|
77
|
-
name: string;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Optional description of the UI resource's purpose and functionality
|
|
81
|
-
*
|
|
82
|
-
* Provides context about what the UI does and when to use it.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* "Interactive weather visualization with real-time updates"
|
|
86
|
-
*/
|
|
87
|
-
description?: string;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* MIME type of the UI content
|
|
91
|
-
*
|
|
92
|
-
* SHOULD be `text/html;profile=mcp-app` for HTML-based UIs in the initial MVP.
|
|
93
|
-
* Other content types are reserved for future extensions.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* "text/html;profile=mcp-app"
|
|
97
|
-
*/
|
|
98
|
-
mimeType: "text/html;profile=mcp-app";
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Resource metadata for security and rendering configuration
|
|
102
|
-
*
|
|
103
|
-
* Includes Content Security Policy configuration, dedicated domain settings,
|
|
104
|
-
* and visual preferences.
|
|
105
|
-
*/
|
|
106
|
-
_meta?: {
|
|
107
|
-
ui?: UIResourceMeta;
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Path to the tool file (for React bundling)
|
|
111
|
-
*/
|
|
112
|
-
toolPath?: string;
|
|
113
|
-
/**
|
|
114
|
-
* Tool handler function
|
|
115
|
-
*/
|
|
116
|
-
handler: UserToolHandler;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
class UIResourceRegistry {
|
|
120
|
-
private resources = new Map<string, UIResource>();
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Add a resource to the registry
|
|
124
|
-
*/
|
|
125
|
-
add(toolName: string, resource: UIResource): void {
|
|
126
|
-
this.resources.set(toolName, resource);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Get all registered resources
|
|
131
|
-
*/
|
|
132
|
-
getAll(): Map<string, UIResource> {
|
|
133
|
-
return this.resources;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Clear all resources (useful for testing or reinitialization)
|
|
138
|
-
*/
|
|
139
|
-
clear(): void {
|
|
140
|
-
this.resources.clear();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Check if a resource exists
|
|
145
|
-
*/
|
|
146
|
-
has(toolName: string): boolean {
|
|
147
|
-
return this.resources.has(toolName);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export const uIResourceRegistry = new UIResourceRegistry();
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export const MCP_APPS_PROTOCOL_VERSION = "2026-01-26";
|
|
2
|
-
|
|
3
|
-
export const INITIALIZE_METHOD = "ui/initialize";
|
|
4
|
-
export const INITIALIZED_METHOD = "ui/notifications/initialized";
|
|
5
|
-
export const REQUEST_DISPLAY_MODE_METHOD = "ui/request-display-mode";
|
|
6
|
-
export const REQUEST_DISPLAY_MODE_METHOD_LEGACY = "ui/requestDisplayMode";
|
|
7
|
-
export const OPEN_LINK_METHOD = "ui/open-link";
|
|
8
|
-
export const OPEN_LINK_METHOD_LEGACY = "ui/openLink";
|
|
9
|
-
export const UPDATE_MODEL_CONTEXT_METHOD = "ui/update-model-context";
|
|
10
|
-
export const UI_MESSAGE_METHOD = "ui/message";
|
|
11
|
-
export const LOG_MESSAGE_METHOD = "notifications/message";
|
|
12
|
-
export const RESOURCES_READ_METHOD = "resources/read";
|
|
13
|
-
export const HOST_CONTEXT_CHANGED_METHOD =
|
|
14
|
-
"ui/notifications/host-context-changed";
|
|
15
|
-
export const HOST_CONTEXT_CHANGED_METHOD_LEGACY = "ui/hostContextChanged";
|
|
16
|
-
export const SIZE_CHANGED_METHOD = "ui/notifications/size-changed";
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
export type McpUiDisplayMode = "inline" | "fullscreen" | "pip";
|
|
2
|
-
|
|
3
|
-
export interface McpHostCallToolParams {
|
|
4
|
-
name: string;
|
|
5
|
-
arguments?: Record<string, unknown>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface McpHostOpenLinkParams {
|
|
9
|
-
url: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface McpHostRequestDisplayModeParams {
|
|
13
|
-
mode: McpUiDisplayMode;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface McpHostRequestDisplayModeResult {
|
|
17
|
-
mode: McpUiDisplayMode | string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface McpHostSendMessageParams {
|
|
21
|
-
role?: string;
|
|
22
|
-
content: unknown;
|
|
23
|
-
[key: string]: unknown;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface McpHostUpdateModelContextParams {
|
|
27
|
-
content?: unknown;
|
|
28
|
-
role?: string;
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface McpHostToolContentItem {
|
|
33
|
-
type: string;
|
|
34
|
-
text?: string;
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface McpHostToolResult {
|
|
39
|
-
content?: McpHostToolContentItem[];
|
|
40
|
-
structuredContent?: unknown;
|
|
41
|
-
isError?: boolean;
|
|
42
|
-
[key: string]: unknown;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface McpHostResourceContentItem {
|
|
46
|
-
uri?: string;
|
|
47
|
-
mimeType?: string;
|
|
48
|
-
text?: string;
|
|
49
|
-
blob?: string;
|
|
50
|
-
[key: string]: unknown;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface McpHostReadResourceResult {
|
|
54
|
-
contents?: McpHostResourceContentItem[];
|
|
55
|
-
[key: string]: unknown;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface McpHostMessageResult {
|
|
59
|
-
role?: string;
|
|
60
|
-
content?: unknown;
|
|
61
|
-
[key: string]: unknown;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface McpHostModelContextResult {
|
|
65
|
-
ok?: boolean;
|
|
66
|
-
[key: string]: unknown;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface McpHostContainerDimensions {
|
|
70
|
-
width?: number;
|
|
71
|
-
height?: number;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface McpHostStyleContext {
|
|
75
|
-
variables?: Record<string, string>;
|
|
76
|
-
css?: {
|
|
77
|
-
fonts?: string[];
|
|
78
|
-
[key: string]: unknown;
|
|
79
|
-
};
|
|
80
|
-
[key: string]: unknown;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface McpHostContext {
|
|
84
|
-
theme?: string;
|
|
85
|
-
displayMode?: McpUiDisplayMode | string;
|
|
86
|
-
locale?: string;
|
|
87
|
-
timeZone?: string;
|
|
88
|
-
platform?: string;
|
|
89
|
-
availableDisplayModes?: McpUiDisplayMode[];
|
|
90
|
-
containerDimensions?: McpHostContainerDimensions;
|
|
91
|
-
safeAreaInsets?: {
|
|
92
|
-
top?: number;
|
|
93
|
-
right?: number;
|
|
94
|
-
bottom?: number;
|
|
95
|
-
left?: number;
|
|
96
|
-
};
|
|
97
|
-
toolInfo?: Record<string, unknown>;
|
|
98
|
-
deviceCapabilities?: Record<string, unknown>;
|
|
99
|
-
styles?: McpHostStyleContext;
|
|
100
|
-
[key: string]: unknown;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface McpHostCapabilities {
|
|
104
|
-
serverTools?: { listChanged?: boolean; call?: boolean };
|
|
105
|
-
serverResources?: { listChanged?: boolean; read?: boolean };
|
|
106
|
-
openLinks?: boolean;
|
|
107
|
-
updateModelContext?: boolean | string[];
|
|
108
|
-
message?: boolean;
|
|
109
|
-
logging?: boolean;
|
|
110
|
-
downloadFile?: boolean;
|
|
111
|
-
sandbox?: Record<string, unknown>;
|
|
112
|
-
[key: string]: unknown;
|
|
113
|
-
}
|