@vitemcp/server 1.9.3 → 1.9.4

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.
@@ -3,7 +3,7 @@ import {
3
3
  ownKeysOnly,
4
4
  toSdkSchema,
5
5
  valibotToJsonSchema
6
- } from "../chunk-NKMXT32U.js";
6
+ } from "../chunk-4LNVOTEL.js";
7
7
 
8
8
  // src/edge/index.ts
9
9
  import { createMcpHandler, McpServer } from "@modelcontextprotocol/server";
@@ -3,9 +3,9 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkWRKQIQHBcjs = require('../chunk-WRKQIQHB.cjs');
6
+ var _chunkOJUNDONAcjs = require('../chunk-OJUNDONA.cjs');
7
7
  require('../chunk-P32QRCBT.cjs');
8
- require('../chunk-SM24SJ4X.cjs');
8
+ require('../chunk-L6BHGIXM.cjs');
9
9
 
10
10
  // src/openapi/parameters.ts
11
11
  var appendQueryParameter = (query, parameter, value) => {
@@ -270,7 +270,7 @@ var buildBody = (binding, values, headers) => {
270
270
  var buildPath = (route, values) => {
271
271
  const unfilled = [...route.path.matchAll(/\{([^{}]*)\}/g)].filter(([, name]) => !values.has(name)).map(([placeholder]) => placeholder);
272
272
  if (unfilled.length > 0) {
273
- throw new (0, _chunkWRKQIQHBcjs.UserError)(
273
+ throw new (0, _chunkOJUNDONAcjs.UserError)(
274
274
  `${route.method.toUpperCase()} ${route.path} cannot be called: the OpenAPI document declares no path parameter for ${unfilled.join(", ")}.`
275
275
  );
276
276
  }
@@ -281,7 +281,7 @@ var buildPath = (route, values) => {
281
281
  const written = new Set(route.path.split("/").filter(isDotSegment));
282
282
  const introduced = path.split("/").find((segment) => isDotSegment(segment) && !written.has(segment));
283
283
  if (introduced !== void 0) {
284
- throw new (0, _chunkWRKQIQHBcjs.UserError)(
284
+ throw new (0, _chunkOJUNDONAcjs.UserError)(
285
285
  `${route.method.toUpperCase()} ${route.path} cannot be called with a path segment of "${introduced}": a URL resolves it as a step through the path, so the request would reach a different endpoint.`
286
286
  );
287
287
  }
@@ -299,7 +299,7 @@ var readResponse = async (response, options) => {
299
299
  const mediaType = contentType.split(";")[0].trim().toLowerCase();
300
300
  const label = `${route.method.toUpperCase()} ${route.path}`;
301
301
  if (!response.ok) {
302
- throw new (0, _chunkWRKQIQHBcjs.UserError)(
302
+ throw new (0, _chunkOJUNDONAcjs.UserError)(
303
303
  `${label} failed with ${response.status} ${response.statusText}: ${truncate(
304
304
  await response.text(),
305
305
  2e3
@@ -311,7 +311,7 @@ var readResponse = async (response, options) => {
311
311
  if (bytes.byteLength <= MAX_INLINE_MEDIA_BYTES) {
312
312
  return mediaType.startsWith("image/") ? { data: toBase64(bytes), mimeType: mediaType, type: "image" } : { data: toBase64(bytes), mimeType: mediaType, type: "audio" };
313
313
  }
314
- throw new (0, _chunkWRKQIQHBcjs.UserError)(
314
+ throw new (0, _chunkOJUNDONAcjs.UserError)(
315
315
  `${label} returned ${bytes.byteLength} bytes of ${contentType}, too large to return inline.`
316
316
  );
317
317
  }
@@ -321,7 +321,7 @@ var readResponse = async (response, options) => {
321
321
  return { structuredContent: parsed };
322
322
  }
323
323
  if (binding.outputSchema) {
324
- throw new (0, _chunkWRKQIQHBcjs.UserError)(
324
+ throw new (0, _chunkOJUNDONAcjs.UserError)(
325
325
  `${label} declares a JSON object response but returned ${contentType || "an untyped body"}. Set \`outputSchema: false\` if this document's response schemas do not match the API.`
326
326
  );
327
327
  }
@@ -343,7 +343,7 @@ var setHeader = (headers, name, value) => {
343
343
  try {
344
344
  headers.set(name, value);
345
345
  } catch (e2) {
346
- throw new (0, _chunkWRKQIQHBcjs.UserError)(
346
+ throw new (0, _chunkOJUNDONAcjs.UserError)(
347
347
  `"${name}" is not a valid header name, or the value given for it is not a valid header value.`
348
348
  );
349
349
  }
@@ -450,7 +450,7 @@ var readSpecText = async (spec) => {
450
450
  headers: { accept: "application/json, text/yaml, */*" }
451
451
  });
452
452
  if (!response.ok) {
453
- await _chunkWRKQIQHBcjs.cancelResponseBody.call(void 0, response);
453
+ await _chunkOJUNDONAcjs.cancelResponseBody.call(void 0, response);
454
454
  throw new Error(
455
455
  `Failed to fetch the OpenAPI document from ${spec}: ${response.status} ${response.statusText}`
456
456
  );
@@ -1029,7 +1029,7 @@ var fromOpenAPI = async (options) => {
1029
1029
  const selected = selectRoutes(extractRoutes(document), options);
1030
1030
  const names = generateToolNames(selected, options.toolNames);
1031
1031
  const normalizer = createSchemaNormalizer(document);
1032
- const server = _nullishCoalesce(options.server, () => ( new (0, _chunkWRKQIQHBcjs.ViteMCP)({
1032
+ const server = _nullishCoalesce(options.server, () => ( new (0, _chunkOJUNDONAcjs.ViteMCP)({
1033
1033
  description: _optionalChain([document, 'access', _23 => _23.info, 'optionalAccess', _24 => _24.description]),
1034
1034
  name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _25 => _25.info, 'optionalAccess', _26 => _26.title]))), () => ( "OpenAPI")),
1035
1035
  version: _nullishCoalesce(options.version, () => ( semanticVersion(_optionalChain([document, 'access', _27 => _27.info, 'optionalAccess', _28 => _28.version]))))
@@ -1068,8 +1068,8 @@ var fromOpenAPI = async (options) => {
1068
1068
  route
1069
1069
  }),
1070
1070
  name,
1071
- outputSchema: binding.outputSchema ? _chunkWRKQIQHBcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1072
- parameters: _chunkWRKQIQHBcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1071
+ outputSchema: binding.outputSchema ? _chunkOJUNDONAcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1072
+ parameters: _chunkOJUNDONAcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1073
1073
  timeoutMs: options.timeoutMs
1074
1074
  });
1075
1075
  }
@@ -3,9 +3,9 @@ import {
3
3
  ViteMCP,
4
4
  cancelResponseBody,
5
5
  jsonSchemaAdapter
6
- } from "../chunk-3O5CBV4T.js";
6
+ } from "../chunk-5RAYSJ4N.js";
7
7
  import "../chunk-4SRXSCYR.js";
8
- import "../chunk-NKMXT32U.js";
8
+ import "../chunk-4LNVOTEL.js";
9
9
 
10
10
  // src/openapi/parameters.ts
11
11
  var appendQueryParameter = (query, parameter, value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitemcp/server",
3
- "version": "1.9.3",
3
+ "version": "1.9.4",
4
4
  "main": "./dist/ViteMCP.cjs",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -1,78 +0,0 @@
1
- // src/formatBytes.ts
2
- var formatBytes = (bytes) => {
3
- if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {
4
- return `${bytes / (1024 * 1024)} MiB`;
5
- }
6
- if (bytes >= 1024 && bytes % 1024 === 0) {
7
- return `${bytes / 1024} KiB`;
8
- }
9
- return `${bytes} bytes`;
10
- };
11
-
12
- // src/ownKeysOnly.ts
13
- var ownKeysOnly = (schema) => {
14
- const standard = schema["~standard"];
15
- return Object.defineProperty(schema, "~standard", {
16
- value: {
17
- ...standard,
18
- validate: (value) => standard.validate(
19
- typeof value === "object" && value !== null && !Array.isArray(value) ? Object.assign(/* @__PURE__ */ Object.create(null), value) : value
20
- )
21
- }
22
- });
23
- };
24
-
25
- // src/toSdkSchema.ts
26
- var toSdkSchema = async (schema, io, convert) => {
27
- if (!schema) {
28
- return void 0;
29
- }
30
- const standard = schema["~standard"];
31
- if (standard.jsonSchema) {
32
- return schema;
33
- }
34
- const json = await convert(schema, io);
35
- const advertised = io === "input" ? strictInputSchema(json) : json;
36
- return {
37
- "~standard": {
38
- jsonSchema: { input: () => advertised, output: () => advertised },
39
- validate: (value) => standard.validate(value),
40
- vendor: standard.vendor,
41
- version: standard.version
42
- }
43
- };
44
- };
45
- var valibotToJsonSchema = async (schema, io) => {
46
- let converter;
47
- try {
48
- converter = await import("@valibot/to-json-schema");
49
- } catch {
50
- throw new Error(
51
- 'The "@valibot/to-json-schema" package is required to describe Valibot schemas. Install it with: npm install @valibot/to-json-schema'
52
- );
53
- }
54
- return converter.toJsonSchema(schema, {
55
- errorMode: "ignore",
56
- typeMode: io
57
- });
58
- };
59
- var strictInputSchema = (schema) => ({
60
- ...schema,
61
- additionalProperties: typeof schema.additionalProperties === "object" ? schema.additionalProperties : false,
62
- ...schema.properties && {
63
- properties: Object.fromEntries(
64
- Object.entries(schema.properties).map(([key, value]) => [
65
- key,
66
- typeof value === "object" && value.type === "object" ? strictInputSchema(value) : value
67
- ])
68
- )
69
- }
70
- });
71
-
72
- export {
73
- formatBytes,
74
- ownKeysOnly,
75
- toSdkSchema,
76
- valibotToJsonSchema
77
- };
78
- //# sourceMappingURL=chunk-NKMXT32U.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/formatBytes.ts","../src/ownKeysOnly.ts","../src/toSdkSchema.ts"],"sourcesContent":["/** Renders a byte cap the way the error message should read (e.g. \"1 MiB\"). */\nexport const formatBytes = (bytes: number): string => {\n if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {\n return `${bytes / (1024 * 1024)} MiB`;\n }\n\n if (bytes >= 1024 && bytes % 1024 === 0) {\n return `${bytes / 1024} KiB`;\n }\n\n return `${bytes} bytes`;\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Has `schema` validate an object by its own keys only.\n *\n * Zod looks each key up with `in` and reads it with `[]`, and both walk the\n * prototype chain, so an argument the client left out reads as present when\n * `Object.prototype` has a member by that name. An optional prompt argument\n * called `toString`, `constructor` or `valueOf` failed every request that left\n * it out, as \"expected string, received function\", and a required one was\n * reported as the wrong type instead of as missing. A copy of the input without\n * a prototype leaves Zod nothing to inherit.\n *\n * Only `~standard.validate` changes. The schema keeps its `shape`, which the\n * SDK reads to complete an argument, and its JSON Schema, which `prompts/list`\n * is built from.\n *\n * Shared by `ViteMCP` and `EdgeViteMCP`, which both build their prompts'\n * argument schemas with Zod.\n */\nexport const ownKeysOnly = <S extends StandardSchemaV1>(schema: S): S => {\n const standard = schema[\"~standard\"];\n\n return Object.defineProperty(schema, \"~standard\", {\n value: {\n ...standard,\n validate: (value: unknown) =>\n standard.validate(\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? Object.assign(Object.create(null), value)\n : value,\n ),\n },\n });\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema } from \"xsschema\";\n\n/**\n * Turns a Standard Schema that carries no JSON Schema into one. Which\n * libraries that can be done for depends on the runtime, so each entry point\n * supplies its own.\n */\nexport type JsonSchemaConverter = (\n schema: StandardSchemaV1,\n io: \"input\" | \"output\",\n) => Promise<JsonSchema>;\n\n/**\n * Gives the SDK a JSON Schema for a schema that has none of its own. Zod v4\n * and ArkType emit JSON Schema natively and pass through; anything else\n * (Valibot, say) is converted, and the conversion is only what `tools/list`\n * advertises. Validation stays with the library the schema was written in:\n * the conversion drops what JSON Schema cannot say — a transform, a\n * `check()` — so validating against it instead would pass `execute`\n * arguments the schema never produced.\n *\n * Advertised inputs are closed with `strictInputSchema`. Outputs are left as\n * converted, since closing them would misdescribe results the schema allows.\n *\n * Shared by `ViteMCP` and `EdgeViteMCP`, so what a tool advertises does not\n * depend on which of them serves it. Rejects when `convert` does.\n */\nexport const toSdkSchema = async (\n schema: unknown,\n io: \"input\" | \"output\",\n convert: JsonSchemaConverter,\n): Promise<unknown> => {\n if (!schema) {\n return undefined;\n }\n\n const standard = (\n schema as {\n \"~standard\": { jsonSchema?: unknown } & StandardSchemaV1.Props;\n }\n )[\"~standard\"];\n\n if (standard.jsonSchema) {\n return schema;\n }\n\n const json = await convert(schema as StandardSchemaV1, io);\n const advertised = io === \"input\" ? strictInputSchema(json) : json;\n\n return {\n \"~standard\": {\n jsonSchema: { input: () => advertised, output: () => advertised },\n validate: (value: unknown) => standard.validate(value),\n vendor: standard.vendor,\n version: standard.version,\n },\n };\n};\n\n/**\n * JSON Schema for a Valibot schema, for advertising.\n *\n * Valibot's converter is called directly so it can be told to skip what JSON\n * Schema cannot express — a transform, a `check()` — rather than refuse the\n * whole schema. Valibot still validates, so the copy only has to describe what\n * a caller sends (`typeMode: \"input\"`, which stops at the first transform) or\n * receives (`\"output\"`).\n *\n * The `import()` has to stay inside the `try`. An edge bundle is built with\n * every import resolved ahead of time, and a bundler fails the build over one\n * it cannot resolve — unless it can see the failure is handled, in which case\n * a server that never touches Valibot builds without the converter installed.\n */\nexport const valibotToJsonSchema: JsonSchemaConverter = async (schema, io) => {\n let converter;\n\n try {\n converter = await import(\"@valibot/to-json-schema\");\n } catch {\n throw new Error(\n 'The \"@valibot/to-json-schema\" package is required to describe Valibot ' +\n \"schemas. Install it with: npm install @valibot/to-json-schema\",\n );\n }\n\n return converter.toJsonSchema(schema as never, {\n errorMode: \"ignore\",\n typeMode: io,\n }) as JsonSchema;\n};\n\n/**\n * Closes an advertised input schema's objects to undeclared keys, except where\n * the schema describes those keys itself. A record's value schema, or an\n * object's rest schema, arrives as `additionalProperties`; replacing it with\n * `false` would tell clients the tool takes none of those keys, so a\n * `v.record()` argument could only ever be sent as `{}`.\n */\nconst strictInputSchema = (schema: JsonSchema): JsonSchema => ({\n ...schema,\n additionalProperties:\n typeof schema.additionalProperties === \"object\"\n ? schema.additionalProperties\n : false,\n ...(schema.properties && {\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => [\n key,\n typeof value === \"object\" && value.type === \"object\"\n ? strictInputSchema(value)\n : value,\n ]),\n ),\n }),\n});\n"],"mappings":";AACO,IAAM,cAAc,CAAC,UAA0B;AACpD,MAAI,SAAS,OAAO,QAAQ,SAAS,OAAO,UAAU,GAAG;AACvD,WAAO,GAAG,SAAS,OAAO,KAAK;AAAA,EACjC;AAEA,MAAI,SAAS,QAAQ,QAAQ,SAAS,GAAG;AACvC,WAAO,GAAG,QAAQ,IAAI;AAAA,EACxB;AAEA,SAAO,GAAG,KAAK;AACjB;;;ACSO,IAAM,cAAc,CAA6B,WAAiB;AACvE,QAAM,WAAW,OAAO,WAAW;AAEnC,SAAO,OAAO,eAAe,QAAQ,aAAa;AAAA,IAChD,OAAO;AAAA,MACL,GAAG;AAAA,MACH,UAAU,CAAC,UACT,SAAS;AAAA,QACP,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,IAC/D,OAAO,OAAO,uBAAO,OAAO,IAAI,GAAG,KAAK,IACxC;AAAA,MACN;AAAA,IACJ;AAAA,EACF,CAAC;AACH;;;ACNO,IAAM,cAAc,OACzB,QACA,IACA,YACqB;AACrB,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,QAAM,WACJ,OAGA,WAAW;AAEb,MAAI,SAAS,YAAY;AACvB,WAAO;AAAA,EACT;AAEA,QAAM,OAAO,MAAM,QAAQ,QAA4B,EAAE;AACzD,QAAM,aAAa,OAAO,UAAU,kBAAkB,IAAI,IAAI;AAE9D,SAAO;AAAA,IACL,aAAa;AAAA,MACX,YAAY,EAAE,OAAO,MAAM,YAAY,QAAQ,MAAM,WAAW;AAAA,MAChE,UAAU,CAAC,UAAmB,SAAS,SAAS,KAAK;AAAA,MACrD,QAAQ,SAAS;AAAA,MACjB,SAAS,SAAS;AAAA,IACpB;AAAA,EACF;AACF;AAgBO,IAAM,sBAA2C,OAAO,QAAQ,OAAO;AAC5E,MAAI;AAEJ,MAAI;AACF,gBAAY,MAAM,OAAO,yBAAyB;AAAA,EACpD,QAAQ;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,SAAO,UAAU,aAAa,QAAiB;AAAA,IAC7C,WAAW;AAAA,IACX,UAAU;AAAA,EACZ,CAAC;AACH;AASA,IAAM,oBAAoB,CAAC,YAAoC;AAAA,EAC7D,GAAG;AAAA,EACH,sBACE,OAAO,OAAO,yBAAyB,WACnC,OAAO,uBACP;AAAA,EACN,GAAI,OAAO,cAAc;AAAA,IACvB,YAAY,OAAO;AAAA,MACjB,OAAO,QAAQ,OAAO,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,QACtD;AAAA,QACA,OAAO,UAAU,YAAY,MAAM,SAAS,WACxC,kBAAkB,KAAK,IACvB;AAAA,MACN,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/server/server/dist/chunk-SM24SJ4X.cjs","../src/formatBytes.ts","../src/ownKeysOnly.ts","../src/toSdkSchema.ts"],"names":[],"mappings":"AAAA;ACCO,IAAM,YAAA,EAAc,CAAC,KAAA,EAAA,GAA0B;AACpD,EAAA,GAAA,CAAI,MAAA,GAAS,KAAA,EAAO,KAAA,GAAQ,MAAA,EAAA,CAAS,KAAA,EAAO,IAAA,EAAA,IAAU,CAAA,EAAG;AACvD,IAAA,OAAO,CAAA,EAAA;AACT,EAAA;AAEI,EAAA;AACK,IAAA;AACT,EAAA;AAEU,EAAA;AACZ;ADDY;AACA;AESC;AACL,EAAA;AAEC,EAAA;AACE,IAAA;AACF,MAAA;AACH,MAAA;AAEI,QAAA;AAGF,MAAA;AACJ,IAAA;AACD,EAAA;AACH;AFXY;AACA;AGIC;AAKN,EAAA;AACI,IAAA;AACT,EAAA;AAEM,EAAA;AAMF,EAAA;AACK,IAAA;AACT,EAAA;AAEM,EAAA;AACA,EAAA;AAEC,EAAA;AACL,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AACF;AAgBa;AACP,EAAA;AAEA,EAAA;AACF,IAAA;AACM,EAAA;AACA,IAAA;AACJ,MAAA;AAEF,IAAA;AACF,EAAA;AAEO,EAAA;AACL,IAAA;AACA,IAAA;AACD,EAAA;AACH;AASM;AACD,EAAA;AACH,EAAA;AAIW,EAAA;AACT,IAAA;AACE,MAAA;AACE,QAAA;AACA,QAAA;AAGD,MAAA;AACH,IAAA;AACF,EAAA;AACF;AH7CY;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/server/server/dist/chunk-SM24SJ4X.cjs","sourcesContent":[null,"/** Renders a byte cap the way the error message should read (e.g. \"1 MiB\"). */\nexport const formatBytes = (bytes: number): string => {\n if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {\n return `${bytes / (1024 * 1024)} MiB`;\n }\n\n if (bytes >= 1024 && bytes % 1024 === 0) {\n return `${bytes / 1024} KiB`;\n }\n\n return `${bytes} bytes`;\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Has `schema` validate an object by its own keys only.\n *\n * Zod looks each key up with `in` and reads it with `[]`, and both walk the\n * prototype chain, so an argument the client left out reads as present when\n * `Object.prototype` has a member by that name. An optional prompt argument\n * called `toString`, `constructor` or `valueOf` failed every request that left\n * it out, as \"expected string, received function\", and a required one was\n * reported as the wrong type instead of as missing. A copy of the input without\n * a prototype leaves Zod nothing to inherit.\n *\n * Only `~standard.validate` changes. The schema keeps its `shape`, which the\n * SDK reads to complete an argument, and its JSON Schema, which `prompts/list`\n * is built from.\n *\n * Shared by `ViteMCP` and `EdgeViteMCP`, which both build their prompts'\n * argument schemas with Zod.\n */\nexport const ownKeysOnly = <S extends StandardSchemaV1>(schema: S): S => {\n const standard = schema[\"~standard\"];\n\n return Object.defineProperty(schema, \"~standard\", {\n value: {\n ...standard,\n validate: (value: unknown) =>\n standard.validate(\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? Object.assign(Object.create(null), value)\n : value,\n ),\n },\n });\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema } from \"xsschema\";\n\n/**\n * Turns a Standard Schema that carries no JSON Schema into one. Which\n * libraries that can be done for depends on the runtime, so each entry point\n * supplies its own.\n */\nexport type JsonSchemaConverter = (\n schema: StandardSchemaV1,\n io: \"input\" | \"output\",\n) => Promise<JsonSchema>;\n\n/**\n * Gives the SDK a JSON Schema for a schema that has none of its own. Zod v4\n * and ArkType emit JSON Schema natively and pass through; anything else\n * (Valibot, say) is converted, and the conversion is only what `tools/list`\n * advertises. Validation stays with the library the schema was written in:\n * the conversion drops what JSON Schema cannot say — a transform, a\n * `check()` — so validating against it instead would pass `execute`\n * arguments the schema never produced.\n *\n * Advertised inputs are closed with `strictInputSchema`. Outputs are left as\n * converted, since closing them would misdescribe results the schema allows.\n *\n * Shared by `ViteMCP` and `EdgeViteMCP`, so what a tool advertises does not\n * depend on which of them serves it. Rejects when `convert` does.\n */\nexport const toSdkSchema = async (\n schema: unknown,\n io: \"input\" | \"output\",\n convert: JsonSchemaConverter,\n): Promise<unknown> => {\n if (!schema) {\n return undefined;\n }\n\n const standard = (\n schema as {\n \"~standard\": { jsonSchema?: unknown } & StandardSchemaV1.Props;\n }\n )[\"~standard\"];\n\n if (standard.jsonSchema) {\n return schema;\n }\n\n const json = await convert(schema as StandardSchemaV1, io);\n const advertised = io === \"input\" ? strictInputSchema(json) : json;\n\n return {\n \"~standard\": {\n jsonSchema: { input: () => advertised, output: () => advertised },\n validate: (value: unknown) => standard.validate(value),\n vendor: standard.vendor,\n version: standard.version,\n },\n };\n};\n\n/**\n * JSON Schema for a Valibot schema, for advertising.\n *\n * Valibot's converter is called directly so it can be told to skip what JSON\n * Schema cannot express — a transform, a `check()` — rather than refuse the\n * whole schema. Valibot still validates, so the copy only has to describe what\n * a caller sends (`typeMode: \"input\"`, which stops at the first transform) or\n * receives (`\"output\"`).\n *\n * The `import()` has to stay inside the `try`. An edge bundle is built with\n * every import resolved ahead of time, and a bundler fails the build over one\n * it cannot resolve — unless it can see the failure is handled, in which case\n * a server that never touches Valibot builds without the converter installed.\n */\nexport const valibotToJsonSchema: JsonSchemaConverter = async (schema, io) => {\n let converter;\n\n try {\n converter = await import(\"@valibot/to-json-schema\");\n } catch {\n throw new Error(\n 'The \"@valibot/to-json-schema\" package is required to describe Valibot ' +\n \"schemas. Install it with: npm install @valibot/to-json-schema\",\n );\n }\n\n return converter.toJsonSchema(schema as never, {\n errorMode: \"ignore\",\n typeMode: io,\n }) as JsonSchema;\n};\n\n/**\n * Closes an advertised input schema's objects to undeclared keys, except where\n * the schema describes those keys itself. A record's value schema, or an\n * object's rest schema, arrives as `additionalProperties`; replacing it with\n * `false` would tell clients the tool takes none of those keys, so a\n * `v.record()` argument could only ever be sent as `{}`.\n */\nconst strictInputSchema = (schema: JsonSchema): JsonSchema => ({\n ...schema,\n additionalProperties:\n typeof schema.additionalProperties === \"object\"\n ? schema.additionalProperties\n : false,\n ...(schema.properties && {\n properties: Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => [\n key,\n typeof value === \"object\" && value.type === \"object\"\n ? strictInputSchema(value)\n : value,\n ]),\n ),\n }),\n});\n"]}