@vitemcp/server 1.9.4 → 1.9.5

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.
@@ -10,9 +10,15 @@ var formatBytes = (bytes) => {
10
10
  };
11
11
 
12
12
  // src/ownKeysOnly.ts
13
- var ownKeysOnly = (schema) => Object.defineProperty(schema, "~standard", {
14
- value: withOwnKeysOnly(schema["~standard"])
15
- });
13
+ var ownKeysOnly = (schema) => {
14
+ const standard = withOwnKeysOnly(schema["~standard"]);
15
+ return Object.defineProperty(schema, "~standard", {
16
+ value: {
17
+ ...standard,
18
+ validate: (value) => standard.validate(value ?? {})
19
+ }
20
+ });
21
+ };
16
22
  var withOwnKeysOnly = (standard) => ({
17
23
  ...standard,
18
24
  validate: async (value) => {
@@ -112,4 +118,4 @@ export {
112
118
  toSdkSchema,
113
119
  valibotToJsonSchema
114
120
  };
115
- //# sourceMappingURL=chunk-4LNVOTEL.js.map
121
+ //# sourceMappingURL=chunk-XQI4HYU6.js.map
@@ -0,0 +1 @@
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 by own keys only — see `withOwnKeysOnly` — by\n * replacing its `~standard` in place. 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 * For the argument schemas `ViteMCP` and `EdgeViteMCP` build for their\n * prompts. A tool's schemas belong to whoever wrote the tool, so\n * `toSdkSchema` wraps them instead.\n *\n * An argument map the request left out validates as an empty one, as the SDK\n * already arranges for a tool's. `prompts/get` may omit `arguments`, and the\n * SDK validates the map as it was sent, so a prompt whose arguments are all\n * optional refused the request as \"expected object, received undefined\".\n */\nexport const ownKeysOnly = <S extends StandardSchemaV1>(schema: S): S => {\n const standard = withOwnKeysOnly(schema[\"~standard\"]);\n\n return Object.defineProperty(schema, \"~standard\", {\n value: {\n ...standard,\n validate: (value: unknown) => standard.validate(value ?? {}),\n },\n });\n};\n\n/**\n * `standard`, with a `validate` that sees only the keys an object has of its\n * own.\n *\n * Zod and Valibot look each key up with `in` and read it with `[]`, and both\n * walk the prototype chain, so a key that was left out reads as present when\n * `Object.prototype` has a member by that name. An optional argument called\n * `toString`, `constructor` or `valueOf`, at any depth, failed every request\n * that left it out, as \"expected string, received function\", and a required\n * one was reported as the wrong type instead of as missing. Validating a copy\n * whose objects have no prototype leaves the library nothing to inherit.\n *\n * A library that hands its input back, as ArkType and `jsonSchemaAdapter` do,\n * hands back the copy, so the copied objects get their prototype back before\n * the value goes on: `execute` still receives ordinary objects.\n */\nexport const withOwnKeysOnly = <P extends StandardSchemaV1.Props>(\n standard: P,\n): P => ({\n ...standard,\n validate: async (value: unknown) => {\n const copies = new Map<object, object>();\n const result = await standard.validate(withoutPrototypes(value, copies));\n\n if (!result.issues && copies.size > 0) {\n restorePrototypes(result.value, new Set(copies.values()), new Set());\n }\n\n return result;\n },\n});\n\n/**\n * `value`, with each plain object in it, at any depth, copied onto one without\n * a prototype, and each array copied to reach them. `copies` maps every\n * original to its copy, so one that occurs twice, or inside itself, is copied\n * once.\n */\nconst withoutPrototypes = (\n value: unknown,\n copies: Map<object, object>,\n): unknown => {\n if (!isPlain(value)) {\n return value;\n }\n\n const existing = copies.get(value);\n\n if (existing) {\n return existing;\n }\n\n const copy: Record<string, unknown> = Array.isArray(value)\n ? []\n : Object.create(null);\n\n copies.set(value, copy);\n\n for (const [key, item] of Object.entries(value)) {\n copy[key] = withoutPrototypes(item, copies);\n }\n\n return copy;\n};\n\n/**\n * Gives each object copy in `copies` that `value` holds, at any depth,\n * `Object.prototype` back.\n */\nconst restorePrototypes = (\n value: unknown,\n copies: Set<object>,\n seen: Set<object>,\n): void => {\n if (!isPlain(value) || seen.has(value)) {\n return;\n }\n\n seen.add(value);\n\n if (copies.has(value) && !Array.isArray(value)) {\n Object.setPrototypeOf(value, Object.prototype);\n }\n\n for (const item of Object.values(value)) {\n restorePrototypes(item, copies, seen);\n }\n};\n\n/**\n * An array, or an object made by a literal or without a prototype: what JSON\n * parses to, and the only kinds of object that are copied.\n */\nconst isPlain = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n return (\n Array.isArray(value) || prototype === Object.prototype || prototype === null\n );\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema } from \"xsschema\";\n\nimport { withOwnKeysOnly } from \"./ownKeysOnly.js\";\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 * A tool's schema as the SDK registers it: one that validates by own keys only\n * (see `withOwnKeysOnly`) and carries a JSON Schema. The schema itself is left\n * as it was, since whoever wrote it may use it elsewhere.\n *\n * Zod v4 and ArkType emit JSON Schema natively, and theirs is kept; anything\n * else (Valibot, say) is converted, and the conversion is only what\n * `tools/list` advertises. Validation stays with the library the schema was\n * written in: the conversion drops what JSON Schema cannot say — a transform,\n * a `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 = withOwnKeysOnly(\n (\n schema as {\n \"~standard\": { jsonSchema?: unknown } & StandardSchemaV1.Props;\n }\n )[\"~standard\"],\n );\n\n if (standard.jsonSchema) {\n return { \"~standard\": standard };\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 ...standard,\n jsonSchema: { input: () => advertised, output: () => advertised },\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":"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","names":[]}
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// src/formatBytes.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/formatBytes.ts
2
2
  var formatBytes = (bytes) => {
3
3
  if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {
4
4
  return `${bytes / (1024 * 1024)} MiB`;
@@ -10,9 +10,15 @@ var formatBytes = (bytes) => {
10
10
  };
11
11
 
12
12
  // src/ownKeysOnly.ts
13
- var ownKeysOnly = (schema) => Object.defineProperty(schema, "~standard", {
14
- value: withOwnKeysOnly(schema["~standard"])
15
- });
13
+ var ownKeysOnly = (schema) => {
14
+ const standard = withOwnKeysOnly(schema["~standard"]);
15
+ return Object.defineProperty(schema, "~standard", {
16
+ value: {
17
+ ...standard,
18
+ validate: (value) => standard.validate(_nullishCoalesce(value, () => ( {})))
19
+ }
20
+ });
21
+ };
16
22
  var withOwnKeysOnly = (standard) => ({
17
23
  ...standard,
18
24
  validate: async (value) => {
@@ -112,4 +118,4 @@ var strictInputSchema = (schema) => ({
112
118
 
113
119
 
114
120
  exports.formatBytes = formatBytes; exports.ownKeysOnly = ownKeysOnly; exports.toSdkSchema = toSdkSchema; exports.valibotToJsonSchema = valibotToJsonSchema;
115
- //# sourceMappingURL=chunk-L6BHGIXM.cjs.map
121
+ //# sourceMappingURL=chunk-ZVA6Y7EO.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/server/server/dist/chunk-ZVA6Y7EO.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;AEMC;AACL,EAAA;AAEC,EAAA;AACE,IAAA;AACF,MAAA;AACH,MAAA;AACF,IAAA;AACD,EAAA;AACH;AAkBa;AAGR,EAAA;AACO,EAAA;AACF,IAAA;AACA,IAAA;AAED,IAAA;AACH,MAAA;AACF,IAAA;AAEO,IAAA;AACT,EAAA;AACF;AAQM;AAIC,EAAA;AACI,IAAA;AACT,EAAA;AAEM,EAAA;AAEF,EAAA;AACK,IAAA;AACT,EAAA;AAEM,EAAA;AAIC,EAAA;AAEP,EAAA;AACU,IAAA;AACV,EAAA;AAEO,EAAA;AACT;AAMM;AAKC,EAAA;AACH,IAAA;AACF,EAAA;AAES,EAAA;AAEL,EAAA;AACK,IAAA;AACT,EAAA;AAEA,EAAA;AACE,IAAA;AACF,EAAA;AACF;AAMM;AACA,EAAA;AACK,IAAA;AACT,EAAA;AAEM,EAAA;AAGJ,EAAA;AAEJ;AFjEY;AACA;AGlCC;AAKN,EAAA;AACI,IAAA;AACT,EAAA;AAEM,EAAA;AAKF,IAAA;AACJ,EAAA;AAEI,EAAA;AACK,IAAA;AACT,EAAA;AAEM,EAAA;AACA,EAAA;AAEC,EAAA;AACL,IAAA;AACK,MAAA;AACH,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;AHPY;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/server/server/dist/chunk-ZVA6Y7EO.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 by own keys only — see `withOwnKeysOnly` — by\n * replacing its `~standard` in place. 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 * For the argument schemas `ViteMCP` and `EdgeViteMCP` build for their\n * prompts. A tool's schemas belong to whoever wrote the tool, so\n * `toSdkSchema` wraps them instead.\n *\n * An argument map the request left out validates as an empty one, as the SDK\n * already arranges for a tool's. `prompts/get` may omit `arguments`, and the\n * SDK validates the map as it was sent, so a prompt whose arguments are all\n * optional refused the request as \"expected object, received undefined\".\n */\nexport const ownKeysOnly = <S extends StandardSchemaV1>(schema: S): S => {\n const standard = withOwnKeysOnly(schema[\"~standard\"]);\n\n return Object.defineProperty(schema, \"~standard\", {\n value: {\n ...standard,\n validate: (value: unknown) => standard.validate(value ?? {}),\n },\n });\n};\n\n/**\n * `standard`, with a `validate` that sees only the keys an object has of its\n * own.\n *\n * Zod and Valibot look each key up with `in` and read it with `[]`, and both\n * walk the prototype chain, so a key that was left out reads as present when\n * `Object.prototype` has a member by that name. An optional argument called\n * `toString`, `constructor` or `valueOf`, at any depth, failed every request\n * that left it out, as \"expected string, received function\", and a required\n * one was reported as the wrong type instead of as missing. Validating a copy\n * whose objects have no prototype leaves the library nothing to inherit.\n *\n * A library that hands its input back, as ArkType and `jsonSchemaAdapter` do,\n * hands back the copy, so the copied objects get their prototype back before\n * the value goes on: `execute` still receives ordinary objects.\n */\nexport const withOwnKeysOnly = <P extends StandardSchemaV1.Props>(\n standard: P,\n): P => ({\n ...standard,\n validate: async (value: unknown) => {\n const copies = new Map<object, object>();\n const result = await standard.validate(withoutPrototypes(value, copies));\n\n if (!result.issues && copies.size > 0) {\n restorePrototypes(result.value, new Set(copies.values()), new Set());\n }\n\n return result;\n },\n});\n\n/**\n * `value`, with each plain object in it, at any depth, copied onto one without\n * a prototype, and each array copied to reach them. `copies` maps every\n * original to its copy, so one that occurs twice, or inside itself, is copied\n * once.\n */\nconst withoutPrototypes = (\n value: unknown,\n copies: Map<object, object>,\n): unknown => {\n if (!isPlain(value)) {\n return value;\n }\n\n const existing = copies.get(value);\n\n if (existing) {\n return existing;\n }\n\n const copy: Record<string, unknown> = Array.isArray(value)\n ? []\n : Object.create(null);\n\n copies.set(value, copy);\n\n for (const [key, item] of Object.entries(value)) {\n copy[key] = withoutPrototypes(item, copies);\n }\n\n return copy;\n};\n\n/**\n * Gives each object copy in `copies` that `value` holds, at any depth,\n * `Object.prototype` back.\n */\nconst restorePrototypes = (\n value: unknown,\n copies: Set<object>,\n seen: Set<object>,\n): void => {\n if (!isPlain(value) || seen.has(value)) {\n return;\n }\n\n seen.add(value);\n\n if (copies.has(value) && !Array.isArray(value)) {\n Object.setPrototypeOf(value, Object.prototype);\n }\n\n for (const item of Object.values(value)) {\n restorePrototypes(item, copies, seen);\n }\n};\n\n/**\n * An array, or an object made by a literal or without a prototype: what JSON\n * parses to, and the only kinds of object that are copied.\n */\nconst isPlain = (value: unknown): value is Record<string, unknown> => {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const prototype: unknown = Object.getPrototypeOf(value);\n\n return (\n Array.isArray(value) || prototype === Object.prototype || prototype === null\n );\n};\n","import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { JsonSchema } from \"xsschema\";\n\nimport { withOwnKeysOnly } from \"./ownKeysOnly.js\";\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 * A tool's schema as the SDK registers it: one that validates by own keys only\n * (see `withOwnKeysOnly`) and carries a JSON Schema. The schema itself is left\n * as it was, since whoever wrote it may use it elsewhere.\n *\n * Zod v4 and ArkType emit JSON Schema natively, and theirs is kept; anything\n * else (Valibot, say) is converted, and the conversion is only what\n * `tools/list` advertises. Validation stays with the library the schema was\n * written in: the conversion drops what JSON Schema cannot say — a transform,\n * a `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 = withOwnKeysOnly(\n (\n schema as {\n \"~standard\": { jsonSchema?: unknown } & StandardSchemaV1.Props;\n }\n )[\"~standard\"],\n );\n\n if (standard.jsonSchema) {\n return { \"~standard\": standard };\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 ...standard,\n jsonSchema: { input: () => advertised, output: () => advertised },\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"]}
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkL6BHGIXMcjs = require('../chunk-L6BHGIXM.cjs');
6
+ var _chunkZVA6Y7EOcjs = require('../chunk-ZVA6Y7EO.cjs');
7
7
 
8
8
  // src/edge/index.ts
9
9
  var _server = require('@modelcontextprotocol/server');
@@ -16,7 +16,7 @@ var convertToJsonSchema = async (schema, io) => {
16
16
  `Schema library "${vendor}" carries no JSON Schema (\`~standard.jsonSchema\`), and EdgeViteMCP converts only Valibot's. Use Zod 4, ArkType or Valibot.`
17
17
  );
18
18
  }
19
- return _chunkL6BHGIXMcjs.valibotToJsonSchema.call(void 0, schema, io);
19
+ return _chunkZVA6Y7EOcjs.valibotToJsonSchema.call(void 0, schema, io);
20
20
  };
21
21
  var readCappedRequest = async (request, maxBytes) => {
22
22
  if (!request.body) {
@@ -107,7 +107,7 @@ var EdgeViteMCP = class {
107
107
  }
108
108
  if (!capped) {
109
109
  return invalidRequest(
110
- `Request body exceeds ${_chunkL6BHGIXMcjs.formatBytes.call(void 0, this.#maxBodySize)}`
110
+ `Request body exceeds ${_chunkZVA6Y7EOcjs.formatBytes.call(void 0, this.#maxBodySize)}`
111
111
  );
112
112
  }
113
113
  this.#handler ??= _server.createMcpHandler.call(void 0, () => this.#buildServer());
@@ -172,7 +172,7 @@ var EdgeViteMCP = class {
172
172
  for (const arg of _nullishCoalesce(prompt.arguments, () => ( []))) {
173
173
  shape[arg.name] = arg.required ? _zod.z.string() : _zod.z.string().optional();
174
174
  }
175
- const argsSchema = _optionalChain([prompt, 'access', _ => _.arguments, 'optionalAccess', _2 => _2.length]) ? _chunkL6BHGIXMcjs.ownKeysOnly.call(void 0, _zod.z.object(shape)) : void 0;
175
+ const argsSchema = _optionalChain([prompt, 'access', _ => _.arguments, 'optionalAccess', _2 => _2.length]) ? _chunkZVA6Y7EOcjs.ownKeysOnly.call(void 0, _zod.z.object(shape)) : void 0;
176
176
  const load = async (args) => {
177
177
  const text = await prompt.load(_nullishCoalesce(args, () => ( {})));
178
178
  return {
@@ -202,7 +202,7 @@ var EdgeViteMCP = class {
202
202
  #sdkSchemaFor(tool) {
203
203
  let schema = this.#toolSchemas.get(tool);
204
204
  if (!schema) {
205
- schema = _chunkL6BHGIXMcjs.toSdkSchema.call(void 0, tool.parameters, "input", convertToJsonSchema).then(
205
+ schema = _chunkZVA6Y7EOcjs.toSdkSchema.call(void 0, tool.parameters, "input", convertToJsonSchema).then(
206
206
  (inputSchema) => ({ inputSchema }),
207
207
  (error) => {
208
208
  this.#logger.error(
@@ -3,7 +3,7 @@ import {
3
3
  ownKeysOnly,
4
4
  toSdkSchema,
5
5
  valibotToJsonSchema
6
- } from "../chunk-4LNVOTEL.js";
6
+ } from "../chunk-XQI4HYU6.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 _chunkOJUNDONAcjs = require('../chunk-OJUNDONA.cjs');
7
- require('../chunk-P32QRCBT.cjs');
8
- require('../chunk-L6BHGIXM.cjs');
6
+ var _chunkIBZFPUBFcjs = require('../chunk-IBZFPUBF.cjs');
7
+ require('../chunk-NSHLX6PZ.cjs');
8
+ require('../chunk-ZVA6Y7EO.cjs');
9
9
 
10
10
  // src/openapi/parameters.ts
11
11
  var appendQueryParameter = (query, parameter, value) => {
@@ -242,7 +242,8 @@ var appendFormValue = (form, name, value) => {
242
242
  };
243
243
  var buildBody = (binding, values, headers) => {
244
244
  const encoding = binding.bodyEncoding;
245
- if (!encoding || Object.keys(values).length === 0) {
245
+ const sendEmpty = _optionalChain([encoding, 'optionalAccess', _3 => _3.kind]) === "json" && binding.bodyRequired;
246
+ if (!encoding || Object.keys(values).length === 0 && !sendEmpty) {
246
247
  return void 0;
247
248
  }
248
249
  const payload = binding.wholeBodyKey ? values[binding.wholeBodyKey] : values;
@@ -270,7 +271,7 @@ var buildBody = (binding, values, headers) => {
270
271
  var buildPath = (route, values) => {
271
272
  const unfilled = [...route.path.matchAll(/\{([^{}]*)\}/g)].filter(([, name]) => !values.has(name)).map(([placeholder]) => placeholder);
272
273
  if (unfilled.length > 0) {
273
- throw new (0, _chunkOJUNDONAcjs.UserError)(
274
+ throw new (0, _chunkIBZFPUBFcjs.UserError)(
274
275
  `${route.method.toUpperCase()} ${route.path} cannot be called: the OpenAPI document declares no path parameter for ${unfilled.join(", ")}.`
275
276
  );
276
277
  }
@@ -281,7 +282,7 @@ var buildPath = (route, values) => {
281
282
  const written = new Set(route.path.split("/").filter(isDotSegment));
282
283
  const introduced = path.split("/").find((segment) => isDotSegment(segment) && !written.has(segment));
283
284
  if (introduced !== void 0) {
284
- throw new (0, _chunkOJUNDONAcjs.UserError)(
285
+ throw new (0, _chunkIBZFPUBFcjs.UserError)(
285
286
  `${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
287
  );
287
288
  }
@@ -299,7 +300,7 @@ var readResponse = async (response, options) => {
299
300
  const mediaType = contentType.split(";")[0].trim().toLowerCase();
300
301
  const label = `${route.method.toUpperCase()} ${route.path}`;
301
302
  if (!response.ok) {
302
- throw new (0, _chunkOJUNDONAcjs.UserError)(
303
+ throw new (0, _chunkIBZFPUBFcjs.UserError)(
303
304
  `${label} failed with ${response.status} ${response.statusText}: ${truncate(
304
305
  await response.text(),
305
306
  2e3
@@ -311,7 +312,7 @@ var readResponse = async (response, options) => {
311
312
  if (bytes.byteLength <= MAX_INLINE_MEDIA_BYTES) {
312
313
  return mediaType.startsWith("image/") ? { data: toBase64(bytes), mimeType: mediaType, type: "image" } : { data: toBase64(bytes), mimeType: mediaType, type: "audio" };
313
314
  }
314
- throw new (0, _chunkOJUNDONAcjs.UserError)(
315
+ throw new (0, _chunkIBZFPUBFcjs.UserError)(
315
316
  `${label} returned ${bytes.byteLength} bytes of ${contentType}, too large to return inline.`
316
317
  );
317
318
  }
@@ -321,7 +322,7 @@ var readResponse = async (response, options) => {
321
322
  return { structuredContent: parsed };
322
323
  }
323
324
  if (binding.outputSchema) {
324
- throw new (0, _chunkOJUNDONAcjs.UserError)(
325
+ throw new (0, _chunkIBZFPUBFcjs.UserError)(
325
326
  `${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
327
  );
327
328
  }
@@ -343,7 +344,7 @@ var setHeader = (headers, name, value) => {
343
344
  try {
344
345
  headers.set(name, value);
345
346
  } catch (e2) {
346
- throw new (0, _chunkOJUNDONAcjs.UserError)(
347
+ throw new (0, _chunkIBZFPUBFcjs.UserError)(
347
348
  `"${name}" is not a valid header name, or the value given for it is not a valid header value.`
348
349
  );
349
350
  }
@@ -388,8 +389,8 @@ var loadSpec = async (spec) => {
388
389
  return { document: assertOpenApi3(parsed), origin };
389
390
  };
390
391
  var assertOpenApi3 = (document) => {
391
- if (!_optionalChain([document, 'optionalAccess', _3 => _3.openapi, 'optionalAccess', _4 => _4.startsWith, 'call', _5 => _5("3.")])) {
392
- const found = _nullishCoalesce(_optionalChain([document, 'optionalAccess', _6 => _6.openapi]), () => ( (_optionalChain([document, 'optionalAccess', _7 => _7.swagger]) ? `Swagger ${document.swagger}` : void 0)));
392
+ if (!_optionalChain([document, 'optionalAccess', _4 => _4.openapi, 'optionalAccess', _5 => _5.startsWith, 'call', _6 => _6("3.")])) {
393
+ const found = _nullishCoalesce(_optionalChain([document, 'optionalAccess', _7 => _7.openapi]), () => ( (_optionalChain([document, 'optionalAccess', _8 => _8.swagger]) ? `Swagger ${document.swagger}` : void 0)));
393
394
  throw new Error(
394
395
  `fromOpenAPI supports OpenAPI 3.x documents only (found ${_nullishCoalesce(found, () => ( "no recognisable version field"))}). Convert a Swagger 2.0 document first \u2014 https://converter.swagger.io converts one in place.`
395
396
  );
@@ -450,7 +451,7 @@ var readSpecText = async (spec) => {
450
451
  headers: { accept: "application/json, text/yaml, */*" }
451
452
  });
452
453
  if (!response.ok) {
453
- await _chunkOJUNDONAcjs.cancelResponseBody.call(void 0, response);
454
+ await _chunkIBZFPUBFcjs.cancelResponseBody.call(void 0, response);
454
455
  throw new Error(
455
456
  `Failed to fetch the OpenAPI document from ${spec}: ${response.status} ${response.statusText}`
456
457
  );
@@ -529,7 +530,7 @@ var mergeParameters = (pathLevel, operationLevel) => {
529
530
  (parameter) => !overridden.has(`${parameter.in}:${parameter.name}`)
530
531
  ),
531
532
  ...operationLevel
532
- ].filter((parameter) => _optionalChain([parameter, 'optionalAccess', _8 => _8.name]) && parameter.in);
533
+ ].filter((parameter) => _optionalChain([parameter, 'optionalAccess', _9 => _9.name]) && parameter.in);
533
534
  };
534
535
  var resolvePathItem = (document, pathItem) => {
535
536
  const followed = /* @__PURE__ */ new Set();
@@ -571,7 +572,7 @@ var readPointer = (root, pointer) => {
571
572
  let node = root;
572
573
  for (const rawSegment of path.slice(1).split("/")) {
573
574
  const segment = decodeSegment(rawSegment);
574
- node = _optionalChain([node, 'optionalAccess', _9 => _9[segment]]);
575
+ node = _optionalChain([node, 'optionalAccess', _10 => _10[segment]]);
575
576
  }
576
577
  return node;
577
578
  };
@@ -602,7 +603,7 @@ var generateToolNames = (routes, override) => {
602
603
  return names;
603
604
  };
604
605
  var baseNameFor = (route, override) => {
605
- const explicit = typeof override === "function" ? override(toOperationSummary(route)) : route.operationId ? _optionalChain([override, 'optionalAccess', _10 => _10[route.operationId]]) : void 0;
606
+ const explicit = typeof override === "function" ? override(toOperationSummary(route)) : route.operationId ? _optionalChain([override, 'optionalAccess', _11 => _11[route.operationId]]) : void 0;
606
607
  if (explicit) {
607
608
  return explicit;
608
609
  }
@@ -769,7 +770,7 @@ var readPointer2 = (root, pointer) => {
769
770
  }
770
771
  let node = root;
771
772
  for (const segment of pointer.split("/").slice(1)) {
772
- node = _optionalChain([node, 'optionalAccess', _11 => _11[decodeSegment2(segment)]]);
773
+ node = _optionalChain([node, 'optionalAccess', _12 => _12[decodeSegment2(segment)]]);
773
774
  }
774
775
  return node;
775
776
  };
@@ -841,6 +842,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
841
842
  }
842
843
  return {
843
844
  bodyEncoding: body.encoding,
845
+ bodyRequired: body.required,
844
846
  caveat: body.caveat,
845
847
  inputSchema,
846
848
  outputSchema: withOutputSchema ? buildOutputSchema(route, normalizer) : void 0,
@@ -850,7 +852,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
850
852
  };
851
853
  var describeBody = (route, normalizer) => {
852
854
  const properties = /* @__PURE__ */ new Map();
853
- const content = route.method === "get" ? void 0 : _optionalChain([route, 'access', _12 => _12.requestBody, 'optionalAccess', _13 => _13.content]);
855
+ const content = route.method === "get" ? void 0 : _optionalChain([route, 'access', _13 => _13.requestBody, 'optionalAccess', _14 => _14.content]);
854
856
  if (!content || Object.keys(content).length === 0) {
855
857
  return { properties };
856
858
  }
@@ -863,15 +865,15 @@ var describeBody = (route, normalizer) => {
863
865
  }
864
866
  const kind = encodingKindFor(contentType);
865
867
  const encoding = { contentType, kind };
866
- const required = _nullishCoalesce(_optionalChain([route, 'access', _14 => _14.requestBody, 'optionalAccess', _15 => _15.required]), () => ( false));
867
- const rawSchema = _optionalChain([content, 'access', _16 => _16[contentType], 'optionalAccess', _17 => _17.schema]);
868
+ const required = _nullishCoalesce(_optionalChain([route, 'access', _15 => _15.requestBody, 'optionalAccess', _16 => _16.required]), () => ( false));
869
+ const rawSchema = _optionalChain([content, 'access', _17 => _17[contentType], 'optionalAccess', _18 => _18.schema]);
868
870
  const schema = rawSchema ? normalizer.normalize(rawSchema) : void 0;
869
871
  if (kind === "text") {
870
872
  properties.set("body", { required, schema: _nullishCoalesce(schema, () => ( { type: "string" })) });
871
- return { encoding, properties, wholeBodyKey: "body" };
873
+ return { encoding, properties, required, wholeBodyKey: "body" };
872
874
  }
873
875
  if (!schema) {
874
- return { encoding, properties };
876
+ return { encoding, properties, required };
875
877
  }
876
878
  const object = flattenObject(schema, normalizer.definitions);
877
879
  if (object && Object.keys(object.properties).length > 0) {
@@ -881,17 +883,17 @@ var describeBody = (route, normalizer) => {
881
883
  schema: property
882
884
  });
883
885
  }
884
- return { encoding, properties };
886
+ return { encoding, properties, required };
885
887
  }
886
888
  properties.set("body", { required, schema });
887
- return { encoding, properties, wholeBodyKey: "body" };
889
+ return { encoding, properties, required, wholeBodyKey: "body" };
888
890
  };
889
891
  var MAX_OUTPUT_SCHEMA_DEFINITIONS = 100;
890
892
  var buildOutputSchema = (route, normalizer) => {
891
893
  const status = Object.keys(route.responses).filter((code) => /^2\d\d$/.test(code)).sort()[0];
892
- const content = status ? _optionalChain([route, 'access', _18 => _18.responses, 'access', _19 => _19[status], 'optionalAccess', _20 => _20.content]) : void 0;
894
+ const content = status ? _optionalChain([route, 'access', _19 => _19.responses, 'access', _20 => _20[status], 'optionalAccess', _21 => _21.content]) : void 0;
893
895
  const contentType = content && findJsonContentType(Object.keys(content));
894
- const raw = contentType ? _optionalChain([content, 'optionalAccess', _21 => _21[contentType], 'optionalAccess', _22 => _22.schema]) : void 0;
896
+ const raw = contentType ? _optionalChain([content, 'optionalAccess', _22 => _22[contentType], 'optionalAccess', _23 => _23.schema]) : void 0;
895
897
  if (!raw) {
896
898
  return void 0;
897
899
  }
@@ -1029,10 +1031,10 @@ var fromOpenAPI = async (options) => {
1029
1031
  const selected = selectRoutes(extractRoutes(document), options);
1030
1032
  const names = generateToolNames(selected, options.toolNames);
1031
1033
  const normalizer = createSchemaNormalizer(document);
1032
- const server = _nullishCoalesce(options.server, () => ( new (0, _chunkOJUNDONAcjs.ViteMCP)({
1033
- description: _optionalChain([document, 'access', _23 => _23.info, 'optionalAccess', _24 => _24.description]),
1034
- name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _25 => _25.info, 'optionalAccess', _26 => _26.title]))), () => ( "OpenAPI")),
1035
- version: _nullishCoalesce(options.version, () => ( semanticVersion(_optionalChain([document, 'access', _27 => _27.info, 'optionalAccess', _28 => _28.version]))))
1034
+ const server = _nullishCoalesce(options.server, () => ( new (0, _chunkIBZFPUBFcjs.ViteMCP)({
1035
+ description: _optionalChain([document, 'access', _24 => _24.info, 'optionalAccess', _25 => _25.description]),
1036
+ name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _26 => _26.info, 'optionalAccess', _27 => _27.title]))), () => ( "OpenAPI")),
1037
+ version: _nullishCoalesce(options.version, () => ( semanticVersion(_optionalChain([document, 'access', _28 => _28.info, 'optionalAccess', _29 => _29.version]))))
1036
1038
  })));
1037
1039
  for (const route of selected) {
1038
1040
  const name = names.get(route);
@@ -1068,8 +1070,8 @@ var fromOpenAPI = async (options) => {
1068
1070
  route
1069
1071
  }),
1070
1072
  name,
1071
- outputSchema: binding.outputSchema ? _chunkOJUNDONAcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1072
- parameters: _chunkOJUNDONAcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1073
+ outputSchema: binding.outputSchema ? _chunkIBZFPUBFcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1074
+ parameters: _chunkIBZFPUBFcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1073
1075
  timeoutMs: options.timeoutMs
1074
1076
  });
1075
1077
  }