@vitemcp/server 1.9.6 → 1.9.8

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.
@@ -1 +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":";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;;;ACMO,IAAM,cAAc,CAA6B,WAAiB;AACvE,QAAM,WAAW,gBAAgB,OAAO,WAAW,CAAC;AAEpD,SAAO,OAAO,eAAe,QAAQ,aAAa;AAAA,IAChD,OAAO;AAAA,MACL,GAAG;AAAA,MACH,UAA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names":[]}
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 *\n * Nor is an object closed whose keys are declared elsewhere: in its `allOf`,\n * `anyOf` or `oneOf` branches — a `v.intersect()`, `v.union()` or\n * `v.variant()` — or behind a `$ref`, which is how a `v.lazy()` arrives.\n * `additionalProperties` sees only the `properties` beside it, so closing one\n * refused every key declared elsewhere, and every argument with them.\n */\nconst strictInputSchema = (schema: JsonSchema): JsonSchema => ({\n ...schema,\n ...(!(schema.allOf ?? schema.anyOf ?? schema.oneOf ?? schema.$ref) && {\n additionalProperties:\n typeof schema.additionalProperties === \"object\"\n ? schema.additionalProperties\n : false,\n }),\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;;;ACMO,IAAM,cAAc,CAA6B,WAAiB;A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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,12 +1,12 @@
1
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkNSHLX6PZcjs = require('./chunk-NSHLX6PZ.cjs');
3
+ var _chunkNLFL6ISLcjs = require('./chunk-NLFL6ISL.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
- var _chunkZVA6Y7EOcjs = require('./chunk-ZVA6Y7EO.cjs');
9
+ var _chunkDURXYPPRcjs = require('./chunk-DURXYPPR.cjs');
10
10
 
11
11
  // src/ViteMCP.ts
12
12
 
@@ -358,10 +358,29 @@ function jsonSchemaAdapter(schema) {
358
358
  }
359
359
  };
360
360
  }
361
+ var dialectOf = ($schema) => {
362
+ if (typeof $schema !== "string") {
363
+ return "2020-12";
364
+ }
365
+ switch ($schema.replace(/^https?:\/\//, "").replace(/#$/, "")) {
366
+ case "json-schema.org/draft-06/schema":
367
+ case "json-schema.org/draft-07/schema":
368
+ return "draft-07";
369
+ case "json-schema.org/draft/2019-09/schema":
370
+ return "2019-09";
371
+ case "json-schema.org/draft/2020-12/schema":
372
+ return "2020-12";
373
+ }
374
+ throw new Error(
375
+ `JSON Schema declares an unsupported dialect ("$schema": "${$schema}"). jsonSchemaAdapter validates 2020-12, 2019-09, draft-07 and draft-06.`
376
+ );
377
+ };
361
378
  async function compileSchema(schema) {
379
+ const { $schema, ...body } = schema;
380
+ const dialect = dialectOf($schema);
362
381
  let ajvModule;
363
382
  try {
364
- ajvModule = await Promise.resolve().then(() => _interopRequireWildcard(require("ajv")));
383
+ ajvModule = dialect === "2020-12" ? await Promise.resolve().then(() => _interopRequireWildcard(require("ajv/dist/2020.js"))) : dialect === "2019-09" ? await Promise.resolve().then(() => _interopRequireWildcard(require("ajv/dist/2019.js"))) : await Promise.resolve().then(() => _interopRequireWildcard(require("ajv")));
365
384
  } catch (e5) {
366
385
  throw new Error(
367
386
  'The "ajv" package is required to validate JSON Schema tool parameters. Install it with: npm install ajv'
@@ -377,7 +396,7 @@ async function compileSchema(schema) {
377
396
  addFormats(ajv);
378
397
  } catch (e6) {
379
398
  }
380
- return ajv.compile(schema);
399
+ return ajv.compile(body);
381
400
  }
382
401
  function toIssue(error) {
383
402
  const path = error.instancePath.split("/").slice(1).map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~")).map((segment) => {
@@ -415,8 +434,35 @@ var UnexpectedStateError = class extends ViteMCPError {
415
434
  };
416
435
  var UserError = class extends UnexpectedStateError {
417
436
  };
437
+ var XML_PROLOG_ITEM = /^(?:<\?[\s\S]*?\?>|<!--[\s\S]*?-->|<!DOCTYPE\s[^[>]*(?:\[[\s\S]*?\])?\s*>)/;
438
+ var isSvg = (data) => {
439
+ let text = data.toString("utf8").trimStart();
440
+ let item = XML_PROLOG_ITEM.exec(text);
441
+ while (item) {
442
+ text = text.slice(item[0].length).trimStart();
443
+ item = XML_PROLOG_ITEM.exec(text);
444
+ }
445
+ return /^<svg[\s/>]/.test(text);
446
+ };
447
+ var mediaTypeOf = (data, kind, sniffed, declared) => {
448
+ if (_optionalChain([sniffed, 'optionalAccess', _9 => _9.startsWith, 'call', _10 => _10(`${kind}/`)])) {
449
+ return sniffed;
450
+ }
451
+ if (kind === "image" && isSvg(data)) {
452
+ return "image/svg+xml";
453
+ }
454
+ if (kind === "audio" && (sniffed === "video/mp4" || sniffed === "video/webm")) {
455
+ return sniffed.replace("video/", "audio/");
456
+ }
457
+ const declaredType = _optionalChain([declared, 'optionalAccess', _11 => _11.split, 'call', _12 => _12(";"), 'access', _13 => _13[0], 'access', _14 => _14.trim, 'call', _15 => _15(), 'access', _16 => _16.toLowerCase, 'call', _17 => _17()]);
458
+ if (_optionalChain([declaredType, 'optionalAccess', _18 => _18.startsWith, 'call', _19 => _19(`${kind}/`)])) {
459
+ return declaredType;
460
+ }
461
+ return _nullishCoalesce(sniffed, () => ( (kind === "image" ? "image/png" : "audio/mpeg")));
462
+ };
418
463
  var readMedia = async (source, kind) => {
419
464
  let rawData;
465
+ let declared = null;
420
466
  try {
421
467
  if ("url" in source) {
422
468
  const response = await _undici.fetch.call(void 0, source.url, {
@@ -426,6 +472,7 @@ var readMedia = async (source, kind) => {
426
472
  await cancelResponseBody(response);
427
473
  throw new Error(`Server responded with status: ${response.status}`);
428
474
  }
475
+ declared = response.headers.get("content-type");
429
476
  rawData = Buffer.from(await response.arrayBuffer());
430
477
  } else if ("path" in source) {
431
478
  rawData = await _promises.readFile.call(void 0, source.path);
@@ -449,10 +496,10 @@ var readMedia = async (source, kind) => {
449
496
  throw new Error(`Unexpected error processing ${kind}: ${String(error)}`);
450
497
  }
451
498
  const { fileTypeFromBuffer } = await Promise.resolve().then(() => _interopRequireWildcard(require("file-type")));
452
- const mimeType = await fileTypeFromBuffer(rawData);
499
+ const sniffed = await fileTypeFromBuffer(rawData);
453
500
  return {
454
501
  data: rawData.toString("base64"),
455
- mimeType: _nullishCoalesce(_optionalChain([mimeType, 'optionalAccess', _9 => _9.mime]), () => ( (kind === "image" ? "image/png" : "audio/mpeg")))
502
+ mimeType: mediaTypeOf(rawData, kind, _optionalChain([sniffed, 'optionalAccess', _20 => _20.mime]), declared)
456
503
  };
457
504
  };
458
505
  var imageContent = async (source) => {
@@ -518,7 +565,7 @@ var ViteMCP = class {
518
565
  * picking a port first and binding it afterwards.
519
566
  */
520
567
  get port() {
521
- const address = _optionalChain([this, 'access', _10 => _10.#httpServer, 'optionalAccess', _11 => _11.address, 'call', _12 => _12()]);
568
+ const address = _optionalChain([this, 'access', _21 => _21.#httpServer, 'optionalAccess', _22 => _22.address, 'call', _23 => _23()]);
522
569
  return address && typeof address === "object" ? address.port : null;
523
570
  }
524
571
  get serverState() {
@@ -561,32 +608,46 @@ var ViteMCP = class {
561
608
  this.#authenticate = _nullishCoalesce(options.authenticate, () => ( (provider ? ((request) => provider.authenticate(request)) : void 0)));
562
609
  this.#honoApp = this.#freshApp();
563
610
  }
611
+ // An entry added under a key already in use replaces the one there: the SDK
612
+ // refuses to register a key twice, and as the server is rebuilt for every
613
+ // request, a duplicate failed every request, not only its own. Keys are the
614
+ // SDK's — a resource's URI, and every other entry's name.
564
615
  addPrompt(prompt) {
616
+ this.#prompts = this.#prompts.filter((p) => p.name !== prompt.name);
565
617
  this.#prompts.push(prompt);
566
618
  this.#notifyListChanged("prompts");
567
619
  }
568
620
  addPrompts(prompts) {
569
621
  for (const prompt of prompts) {
622
+ this.#prompts = this.#prompts.filter((p) => p.name !== prompt.name);
570
623
  this.#prompts.push(prompt);
571
624
  }
572
625
  this.#notifyListChanged("prompts");
573
626
  }
574
627
  addResource(resource) {
628
+ this.#resources = this.#resources.filter((r) => r.uri !== resource.uri);
575
629
  this.#resources.push(resource);
576
630
  this.#notifyListChanged("resources");
577
631
  }
578
632
  addResources(resources) {
579
633
  for (const resource of resources) {
634
+ this.#resources = this.#resources.filter((r) => r.uri !== resource.uri);
580
635
  this.#resources.push(resource);
581
636
  }
582
637
  this.#notifyListChanged("resources");
583
638
  }
584
639
  addResourceTemplate(template) {
640
+ this.#resourceTemplates = this.#resourceTemplates.filter(
641
+ (r) => r.name !== template.name
642
+ );
585
643
  this.#resourceTemplates.push(template);
586
644
  this.#notifyListChanged("resources");
587
645
  }
588
646
  addResourceTemplates(templates) {
589
647
  for (const template of templates) {
648
+ this.#resourceTemplates = this.#resourceTemplates.filter(
649
+ (r) => r.name !== template.name
650
+ );
590
651
  this.#resourceTemplates.push(template);
591
652
  }
592
653
  this.#notifyListChanged("resources");
@@ -594,6 +655,7 @@ var ViteMCP = class {
594
655
  addTool(tool) {
595
656
  assertStandardSchema(tool.parameters, tool.name, "parameters");
596
657
  assertStandardSchema(tool.outputSchema, tool.name, "outputSchema");
658
+ this.#tools = this.#tools.filter((t) => t.name !== tool.name);
597
659
  this.#tools.push(tool);
598
660
  this.#notifyListChanged("tools");
599
661
  }
@@ -601,6 +663,9 @@ var ViteMCP = class {
601
663
  for (const tool of tools) {
602
664
  assertStandardSchema(tool.parameters, tool.name, "parameters");
603
665
  assertStandardSchema(tool.outputSchema, tool.name, "outputSchema");
666
+ }
667
+ for (const tool of tools) {
668
+ this.#tools = this.#tools.filter((t) => t.name !== tool.name);
604
669
  this.#tools.push(tool);
605
670
  }
606
671
  this.#notifyListChanged("tools");
@@ -672,7 +737,7 @@ var ViteMCP = class {
672
737
  * client is never reached.
673
738
  */
674
739
  notifyResourceUpdated(uri) {
675
- _optionalChain([this, 'access', _13 => _13.#handler, 'optionalAccess', _14 => _14.notify, 'access', _15 => _15.resourceUpdated, 'call', _16 => _16(uri)]);
740
+ _optionalChain([this, 'access', _24 => _24.#handler, 'optionalAccess', _25 => _25.notify, 'access', _26 => _26.resourceUpdated, 'call', _27 => _27(uri)]);
676
741
  }
677
742
  removePrompt(name) {
678
743
  this.#prompts = this.#prompts.filter((p) => p.name !== name);
@@ -711,6 +776,11 @@ var ViteMCP = class {
711
776
  this.#notifyListChanged("tools");
712
777
  }
713
778
  async start(options) {
779
+ if (options.transportType === "stdio" ? this.#stdioHandle : this.#httpServer) {
780
+ throw new UnexpectedStateError(
781
+ `ViteMCP is already running on ${options.transportType === "stdio" ? "stdio" : "HTTP"}; call stop() before starting it again`
782
+ );
783
+ }
714
784
  this.#serverState = "starting" /* Starting */;
715
785
  try {
716
786
  if (options.transportType === "stdio") {
@@ -736,9 +806,9 @@ var ViteMCP = class {
736
806
  });
737
807
  }
738
808
  this.#connectedServers = [];
739
- await _optionalChain([this, 'access', _17 => _17.#stdioHandle, 'optionalAccess', _18 => _18.close, 'optionalCall', _19 => _19()]);
809
+ await _optionalChain([this, 'access', _28 => _28.#stdioHandle, 'optionalAccess', _29 => _29.close, 'optionalCall', _30 => _30()]);
740
810
  this.#stdioHandle = null;
741
- await _optionalChain([this, 'access', _20 => _20.#handler, 'optionalAccess', _21 => _21.close, 'call', _22 => _22()]);
811
+ await _optionalChain([this, 'access', _31 => _31.#handler, 'optionalAccess', _32 => _32.close, 'call', _33 => _33()]);
742
812
  this.#handler = null;
743
813
  if (this.#httpServer) {
744
814
  await new Promise(
@@ -825,17 +895,18 @@ var ViteMCP = class {
825
895
  const { context, release } = this.#makeContext(
826
896
  auth,
827
897
  ctx,
828
- _optionalChain([timeout, 'optionalAccess', _23 => _23.controller, 'access', _24 => _24.signal])
898
+ _optionalChain([timeout, 'optionalAccess', _34 => _34.controller, 'access', _35 => _35.signal])
829
899
  );
830
900
  try {
831
901
  const result = await (timeout ? withTimeout(tool.execute(args, context), timeout, tool.name) : tool.execute(args, context));
832
902
  return normalizeToolResult(result, tool.outputSchema !== void 0);
833
903
  } catch (error) {
834
904
  if (error instanceof UserError) {
905
+ const structuredContent = error.extras && await matchesOutputSchema(schemas.outputSchema, error.extras) ? error.extras : void 0;
835
906
  return {
836
907
  content: [{ text: error.message, type: "text" }],
837
908
  isError: true,
838
- ...error.extras ? { structuredContent: error.extras } : {}
909
+ ...structuredContent ? { structuredContent } : {}
839
910
  };
840
911
  }
841
912
  throw error;
@@ -997,7 +1068,7 @@ var ViteMCP = class {
997
1068
  return {
998
1069
  publish: (event) => events.publish(event),
999
1070
  subscribe: (listener) => {
1000
- const auth = _optionalChain([this, 'access', _25 => _25.#authStore, 'access', _26 => _26.getStore, 'call', _27 => _27(), 'optionalAccess', _28 => _28.auth]);
1071
+ const auth = _optionalChain([this, 'access', _36 => _36.#authStore, 'access', _37 => _37.getStore, 'call', _38 => _38(), 'optionalAccess', _39 => _39.auth]);
1001
1072
  return events.subscribe((event) => {
1002
1073
  if (event.kind !== "resource_updated" || this.#canRead(event.uri, auth)) {
1003
1074
  listener(event);
@@ -1020,23 +1091,31 @@ var ViteMCP = class {
1020
1091
  *
1021
1092
  * `timeoutSignal` is folded into `context.signal` for a tool that declares
1022
1093
  * `timeoutMs`; everything else mirrors the SDK's request signal alone. Call
1023
- * `release()` once the handler has settled — see {@link requestScope}.
1094
+ * `release()` once the handler has settled — see {@link requestScope}. It
1095
+ * also ends the context's notifications, as an abort does.
1024
1096
  */
1025
1097
  #makeContext(auth, rawCtx, timeoutSignal) {
1026
1098
  const ctx = rawCtx;
1027
- const mcpReq = _optionalChain([ctx, 'optionalAccess', _29 => _29.mcpReq]);
1028
- const requestedLevel = _optionalChain([mcpReq, 'optionalAccess', _30 => _30.envelope, 'optionalAccess', _31 => _31[_server.LOG_LEVEL_META_KEY]]);
1099
+ const mcpReq = _optionalChain([ctx, 'optionalAccess', _40 => _40.mcpReq]);
1100
+ const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _41 => _41.signal]), timeoutSignal);
1101
+ let settled = false;
1102
+ const notify = async (notification) => {
1103
+ if (settled || scope.signal.aborted) {
1104
+ return;
1105
+ }
1106
+ await _optionalChain([mcpReq, 'optionalAccess', _42 => _42.notify, 'optionalCall', _43 => _43(notification)]);
1107
+ };
1108
+ const requestedLevel = _optionalChain([mcpReq, 'optionalAccess', _44 => _44.envelope, 'optionalAccess', _45 => _45[_server.LOG_LEVEL_META_KEY]]);
1029
1109
  const emit = (level, message, data) => {
1030
1110
  if (!requestedLevel || LOG_LEVELS.indexOf(level) < LOG_LEVELS.indexOf(requestedLevel)) {
1031
1111
  return;
1032
1112
  }
1033
- void _optionalChain([mcpReq, 'optionalAccess', _32 => _32.notify, 'optionalCall', _33 => _33({
1113
+ void notify({
1034
1114
  method: "notifications/message",
1035
1115
  params: { data: { context: data, message }, level }
1036
- }), 'optionalAccess', _34 => _34.catch, 'call', _35 => _35(() => {
1037
- })]);
1116
+ }).catch(() => {
1117
+ });
1038
1118
  };
1039
- const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _36 => _36.signal]), timeoutSignal);
1040
1119
  return {
1041
1120
  context: {
1042
1121
  auth,
@@ -1045,12 +1124,12 @@ var ViteMCP = class {
1045
1124
  requestedSchema: params.requestedSchema
1046
1125
  }),
1047
1126
  input: (key, schema) => _server.acceptedContent.call(void 0,
1048
- _optionalChain([mcpReq, 'optionalAccess', _37 => _37.inputResponses]),
1127
+ _optionalChain([mcpReq, 'optionalAccess', _46 => _46.inputResponses]),
1049
1128
  key,
1050
1129
  schema
1051
1130
  ),
1052
1131
  inputRequired: (inputRequests, requestState) => _server.inputRequired.call(void 0, { inputRequests, requestState }),
1053
- inputResponses: _optionalChain([mcpReq, 'optionalAccess', _38 => _38.inputResponses]),
1132
+ inputResponses: _optionalChain([mcpReq, 'optionalAccess', _47 => _47.inputResponses]),
1054
1133
  log: {
1055
1134
  debug: (m, d) => emit("debug", m, d),
1056
1135
  error: (m, d) => emit("error", m, d),
@@ -1058,11 +1137,11 @@ var ViteMCP = class {
1058
1137
  warn: (m, d) => emit("warning", m, d)
1059
1138
  },
1060
1139
  reportProgress: async (progress) => {
1061
- const progressToken = _optionalChain([mcpReq, 'optionalAccess', _39 => _39._meta, 'optionalAccess', _40 => _40.progressToken]);
1140
+ const progressToken = _optionalChain([mcpReq, 'optionalAccess', _48 => _48._meta, 'optionalAccess', _49 => _49.progressToken]);
1062
1141
  if (progressToken === void 0) {
1063
1142
  return;
1064
1143
  }
1065
- await _optionalChain([mcpReq, 'optionalAccess', _41 => _41.notify, 'optionalCall', _42 => _42({
1144
+ await notify({
1066
1145
  method: "notifications/progress",
1067
1146
  params: {
1068
1147
  message: progress.message,
@@ -1070,15 +1149,18 @@ var ViteMCP = class {
1070
1149
  progressToken,
1071
1150
  total: progress.total
1072
1151
  }
1073
- })]);
1152
+ });
1074
1153
  },
1075
- requestId: _optionalChain([mcpReq, 'optionalAccess', _43 => _43.id]),
1154
+ requestId: _optionalChain([mcpReq, 'optionalAccess', _50 => _50.id]),
1076
1155
  // The SDK exposes this as an accessor; call it so callers get the
1077
1156
  // value.
1078
- requestState: _optionalChain([mcpReq, 'optionalAccess', _44 => _44.requestState, 'optionalCall', _45 => _45()]),
1157
+ requestState: _optionalChain([mcpReq, 'optionalAccess', _51 => _51.requestState, 'optionalCall', _52 => _52()]),
1079
1158
  signal: scope.signal
1080
1159
  },
1081
- release: scope.release
1160
+ release: () => {
1161
+ settled = true;
1162
+ scope.release();
1163
+ }
1082
1164
  };
1083
1165
  }
1084
1166
  /**
@@ -1087,7 +1169,7 @@ var ViteMCP = class {
1087
1169
  * no addressee on a stateless transport.
1088
1170
  */
1089
1171
  #notifyListChanged(kind) {
1090
- const notifier = _optionalChain([this, 'access', _46 => _46.#handler, 'optionalAccess', _47 => _47.notify]);
1172
+ const notifier = _optionalChain([this, 'access', _53 => _53.#handler, 'optionalAccess', _54 => _54.notify]);
1091
1173
  if (!notifier) {
1092
1174
  return;
1093
1175
  }
@@ -1135,7 +1217,7 @@ var ViteMCP = class {
1135
1217
  // Authentication has already run in the route below, which is the only
1136
1218
  // place that can turn a refusal into an HTTP status. What reaches here
1137
1219
  // is either an authenticated session or a deliberately anonymous one.
1138
- async ({ era }) => this.#buildServer(_optionalChain([this, 'access', _48 => _48.#authStore, 'access', _49 => _49.getStore, 'call', _50 => _50(), 'optionalAccess', _51 => _51.auth]), {
1220
+ async ({ era }) => this.#buildServer(_optionalChain([this, 'access', _55 => _55.#authStore, 'access', _56 => _56.getStore, 'call', _57 => _57(), 'optionalAccess', _58 => _58.auth]), {
1139
1221
  era,
1140
1222
  // A 2025-era client reads `resources.subscribe` as a promise of
1141
1223
  // `resources/subscribe`, which is not served.
@@ -1156,7 +1238,7 @@ var ViteMCP = class {
1156
1238
  provider.getOAuthConfig(),
1157
1239
  _nullishCoalesce(config.endpoint, () => ( "/mcp"))
1158
1240
  ))));
1159
- if (_optionalChain([oauth, 'optionalAccess', _52 => _52.enabled]) !== false && (_nullishCoalesce(_nullishCoalesce(_optionalChain([oauth, 'optionalAccess', _53 => _53.proxy]), () => ( _optionalChain([oauth, 'optionalAccess', _54 => _54.authorizationServer]))), () => ( _optionalChain([oauth, 'optionalAccess', _55 => _55.protectedResource]))))) {
1241
+ if (_optionalChain([oauth, 'optionalAccess', _59 => _59.enabled]) !== false && (_nullishCoalesce(_nullishCoalesce(_optionalChain([oauth, 'optionalAccess', _60 => _60.proxy]), () => ( _optionalChain([oauth, 'optionalAccess', _61 => _61.authorizationServer]))), () => ( _optionalChain([oauth, 'optionalAccess', _62 => _62.protectedResource]))))) {
1160
1242
  this.#honoApp.route(
1161
1243
  "/",
1162
1244
  createOAuthRouter({
@@ -1170,10 +1252,10 @@ var ViteMCP = class {
1170
1252
  this.#protectedResource = oauth.protectedResource;
1171
1253
  }
1172
1254
  const health = this.#options.health;
1173
- if (_optionalChain([health, 'optionalAccess', _56 => _56.enabled]) !== false) {
1255
+ if (_optionalChain([health, 'optionalAccess', _63 => _63.enabled]) !== false) {
1174
1256
  this.#honoApp.get(
1175
- _nullishCoalesce(_optionalChain([health, 'optionalAccess', _57 => _57.path]), () => ( "/health")),
1176
- (c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess', _58 => _58.message]), () => ( "ok")), _nullishCoalesce(_optionalChain([health, 'optionalAccess', _59 => _59.status]), () => ( 200)))
1257
+ _nullishCoalesce(_optionalChain([health, 'optionalAccess', _64 => _64.path]), () => ( "/health")),
1258
+ (c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess', _65 => _65.message]), () => ( "ok")), _nullishCoalesce(_optionalChain([health, 'optionalAccess', _66 => _66.status]), () => ( 200)))
1177
1259
  );
1178
1260
  }
1179
1261
  const endpoint = `${_nullishCoalesce(config.basePath, () => ( ""))}${_nullishCoalesce(config.endpoint, () => ( "/mcp"))}`;
@@ -1210,11 +1292,11 @@ var ViteMCP = class {
1210
1292
  "Content-Type": "application/json"
1211
1293
  });
1212
1294
  req.resume();
1213
- res.once("finish", () => _optionalChain([res, 'access', _60 => _60.socket, 'optionalAccess', _61 => _61.end, 'call', _62 => _62()]));
1295
+ res.once("finish", () => _optionalChain([res, 'access', _67 => _67.socket, 'optionalAccess', _68 => _68.end, 'call', _69 => _69()]));
1214
1296
  res.end(
1215
1297
  JSON.stringify({
1216
1298
  error: "invalid_request",
1217
- error_description: `Request body exceeds ${_chunkZVA6Y7EOcjs.formatBytes.call(void 0, maxBodySize)}`
1299
+ error_description: `Request body exceeds ${_chunkDURXYPPRcjs.formatBytes.call(void 0, maxBodySize)}`
1218
1300
  })
1219
1301
  );
1220
1302
  return;
@@ -1289,7 +1371,7 @@ var ViteMCP = class {
1289
1371
  */
1290
1372
  async #toSdkSchema(schema, label, io) {
1291
1373
  try {
1292
- return await _chunkZVA6Y7EOcjs.toSdkSchema.call(void 0, schema, io, convertToJsonSchema);
1374
+ return await _chunkDURXYPPRcjs.toSdkSchema.call(void 0, schema, io, convertToJsonSchema);
1293
1375
  } catch (error) {
1294
1376
  throw new UnexpectedStateError(
1295
1377
  `${label} is not a supported Standard Schema: ${error instanceof Error ? error.message : String(error)}`,
@@ -1330,7 +1412,7 @@ var withEndpointAsResource = (config, endpoint) => ({
1330
1412
  ...config,
1331
1413
  protectedResource: {
1332
1414
  ...config.protectedResource,
1333
- resource: `${_chunkNSHLX6PZcjs.withoutTrailingSlash.call(void 0, config.protectedResource.resource)}${endpoint}`
1415
+ resource: `${_chunkNLFL6ISLcjs.withoutTrailingSlash.call(void 0, config.protectedResource.resource)}${endpoint}`
1334
1416
  }
1335
1417
  });
1336
1418
  var nodeToWebRequest = (req, body, secure, signal) => {
@@ -1426,36 +1508,49 @@ var readCappedNodeBody = async (req, maxBytes) => {
1426
1508
  }
1427
1509
  return Buffer.concat(chunks);
1428
1510
  };
1429
- var convertToJsonSchema = async (schema, io) => schema["~standard"].vendor === "valibot" ? _chunkZVA6Y7EOcjs.valibotToJsonSchema.call(void 0, schema, io) : _xsschema.toJsonSchema.call(void 0, schema);
1511
+ var convertToJsonSchema = async (schema, io) => schema["~standard"].vendor === "valibot" ? _chunkDURXYPPRcjs.valibotToJsonSchema.call(void 0, schema, io) : _xsschema.toJsonSchema.call(void 0, schema);
1430
1512
  var assertStandardSchema = (schema, toolName, field) => {
1431
1513
  if (schema === void 0) {
1432
1514
  return;
1433
1515
  }
1434
- const standard = _optionalChain([schema, 'optionalAccess', _63 => _63["~standard"]]);
1435
- if (typeof _optionalChain([standard, 'optionalAccess', _64 => _64.validate]) !== "function") {
1516
+ const standard = _optionalChain([schema, 'optionalAccess', _70 => _70["~standard"]]);
1517
+ if (typeof _optionalChain([standard, 'optionalAccess', _71 => _71.validate]) !== "function") {
1436
1518
  throw new UnexpectedStateError(
1437
1519
  `Tool '${toolName}' ${field} must implement Standard Schema. If you are using Zod, upgrade to version 3.24 or later.`,
1438
1520
  { toolName }
1439
1521
  );
1440
1522
  }
1441
1523
  };
1524
+ var matchesOutputSchema = async (schema, value) => {
1525
+ if (!schema) {
1526
+ return true;
1527
+ }
1528
+ try {
1529
+ const result = await schema["~standard"].validate(
1530
+ value
1531
+ );
1532
+ return !result.issues;
1533
+ } catch (e7) {
1534
+ return false;
1535
+ }
1536
+ };
1442
1537
  var promptArgsSchema = (prompt) => {
1443
1538
  const args = prompt.arguments;
1444
- if (!_optionalChain([args, 'optionalAccess', _65 => _65.length])) {
1539
+ if (!_optionalChain([args, 'optionalAccess', _72 => _72.length])) {
1445
1540
  return void 0;
1446
1541
  }
1447
1542
  const shape = {};
1448
1543
  for (const arg of args) {
1449
1544
  const explicitCompleter = _nullishCoalesce(arg.complete, () => ( (prompt.complete ? (value) => prompt.complete(arg.name, value) : void 0)));
1450
1545
  const enumValues = arg.enum;
1451
- const completer = _nullishCoalesce(explicitCompleter, () => ( (_optionalChain([enumValues, 'optionalAccess', _66 => _66.length]) ? async (value) => ({
1546
+ const completer = _nullishCoalesce(explicitCompleter, () => ( (_optionalChain([enumValues, 'optionalAccess', _73 => _73.length]) ? async (value) => ({
1452
1547
  // An empty value is how an editor asks for the whole set before the
1453
1548
  // user has typed anything; filtering it would answer with nothing.
1454
1549
  values: value ? enumValues.filter(
1455
1550
  (option) => option.toLowerCase().includes(value.toLowerCase())
1456
1551
  ) : [...enumValues]
1457
1552
  }) : void 0)));
1458
- const valueSchema = _optionalChain([enumValues, 'optionalAccess', _67 => _67.length]) ? _zod.z.enum(enumValues) : _zod.z.string();
1553
+ const valueSchema = _optionalChain([enumValues, 'optionalAccess', _74 => _74.length]) ? _zod.z.enum(enumValues) : _zod.z.string();
1459
1554
  const described = arg.description ? valueSchema.describe(arg.description) : valueSchema;
1460
1555
  const base = completer ? _server.completable.call(void 0,
1461
1556
  described,
@@ -1463,7 +1558,7 @@ var promptArgsSchema = (prompt) => {
1463
1558
  ) : described;
1464
1559
  shape[arg.name] = arg.required ? base : base.optional();
1465
1560
  }
1466
- return _chunkZVA6Y7EOcjs.ownKeysOnly.call(void 0, _zod.z.object(shape));
1561
+ return _chunkDURXYPPRcjs.ownKeysOnly.call(void 0, _zod.z.object(shape));
1467
1562
  };
1468
1563
  var isStructuredResult = (value) => {
1469
1564
  if (!Object.hasOwn(value, "structuredContent") || value.structuredContent === void 0) {
@@ -1532,4 +1627,4 @@ var normalizeToolResult = (result, hasOutputSchema) => {
1532
1627
 
1533
1628
 
1534
1629
  exports.cancelResponseBody = cancelResponseBody; exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.delay = _promises5.setTimeout; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.ViteMCPError = ViteMCPError; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.ServerState = ServerState; exports.ViteMCP = ViteMCP;
1535
- //# sourceMappingURL=chunk-IBZFPUBF.cjs.map
1630
+ //# sourceMappingURL=chunk-XU7XBDZI.cjs.map