@vitemcp/server 1.9.11 → 1.9.13

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.
Files changed (36) hide show
  1. package/README.md +15 -11
  2. package/dist/{OAuthProvider-B78zmLtB.d.cts → OAuthProvider-BDDi19HO.d.cts} +15 -3
  3. package/dist/{OAuthProvider-B78zmLtB.d.ts → OAuthProvider-BDDi19HO.d.ts} +15 -3
  4. package/dist/ViteMCP.cjs +4 -4
  5. package/dist/ViteMCP.d.cts +2 -2
  6. package/dist/ViteMCP.d.ts +2 -2
  7. package/dist/ViteMCP.js +3 -3
  8. package/dist/auth/index.cjs +2 -2
  9. package/dist/auth/index.d.cts +7 -2
  10. package/dist/auth/index.d.ts +7 -2
  11. package/dist/auth/index.js +1 -1
  12. package/dist/{chunk-KSEFUQF4.js → chunk-5XM67UD5.js} +35 -6
  13. package/dist/chunk-5XM67UD5.js.map +1 -0
  14. package/dist/{chunk-TYR2KJIV.js → chunk-JMDI672G.js} +44 -9
  15. package/dist/chunk-JMDI672G.js.map +1 -0
  16. package/dist/{chunk-C2VT2NXC.cjs → chunk-NCSND5TI.cjs} +8 -8
  17. package/dist/{chunk-C2VT2NXC.cjs.map → chunk-NCSND5TI.cjs.map} +1 -1
  18. package/dist/{chunk-IAT55CW3.js → chunk-QGWUABBC.js} +3 -3
  19. package/dist/{chunk-DURXYPPR.cjs → chunk-QPVEGWOL.cjs} +44 -9
  20. package/dist/chunk-QPVEGWOL.cjs.map +1 -0
  21. package/dist/{chunk-XGRRYN5Y.cjs → chunk-SKQK3QGJ.cjs} +35 -6
  22. package/dist/chunk-SKQK3QGJ.cjs.map +1 -0
  23. package/dist/edge/index.cjs +5 -5
  24. package/dist/edge/index.js +1 -1
  25. package/dist/openapi/index.cjs +103 -36
  26. package/dist/openapi/index.cjs.map +1 -1
  27. package/dist/openapi/index.d.cts +2 -2
  28. package/dist/openapi/index.d.ts +2 -2
  29. package/dist/openapi/index.js +86 -19
  30. package/dist/openapi/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/chunk-DURXYPPR.cjs.map +0 -1
  33. package/dist/chunk-KSEFUQF4.js.map +0 -1
  34. package/dist/chunk-TYR2KJIV.js.map +0 -1
  35. package/dist/chunk-XGRRYN5Y.cjs.map +0 -1
  36. /package/dist/{chunk-IAT55CW3.js.map → chunk-QGWUABBC.js.map} +0 -0
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkDURXYPPRcjs = require('../chunk-DURXYPPR.cjs');
6
+ var _chunkQPVEGWOLcjs = require('../chunk-QPVEGWOL.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 _chunkDURXYPPRcjs.valibotToJsonSchema.call(void 0, schema, io);
19
+ return _chunkQPVEGWOLcjs.valibotToJsonSchema.call(void 0, schema, io);
20
20
  };
21
21
  var readCappedRequest = async (request, maxBytes) => {
22
22
  if (!request.body) {
@@ -114,7 +114,7 @@ var EdgeViteMCP = class {
114
114
  }
115
115
  if (!capped) {
116
116
  return invalidRequest(
117
- `Request body exceeds ${_chunkDURXYPPRcjs.formatBytes.call(void 0, this.#maxBodySize)}`
117
+ `Request body exceeds ${_chunkQPVEGWOLcjs.formatBytes.call(void 0, this.#maxBodySize)}`
118
118
  );
119
119
  }
120
120
  this.#handler ??= _server.createMcpHandler.call(void 0, () => this.#buildServer());
@@ -179,7 +179,7 @@ var EdgeViteMCP = class {
179
179
  for (const arg of _nullishCoalesce(prompt.arguments, () => ( []))) {
180
180
  shape[arg.name] = arg.required ? _zod.z.string() : _zod.z.string().optional();
181
181
  }
182
- const argsSchema = _optionalChain([prompt, 'access', _ => _.arguments, 'optionalAccess', _2 => _2.length]) ? _chunkDURXYPPRcjs.ownKeysOnly.call(void 0, _zod.z.object(shape)) : void 0;
182
+ const argsSchema = _optionalChain([prompt, 'access', _ => _.arguments, 'optionalAccess', _2 => _2.length]) ? _chunkQPVEGWOLcjs.ownKeysOnly.call(void 0, _zod.z.object(shape)) : void 0;
183
183
  const load = async (args) => {
184
184
  const text = await prompt.load(_nullishCoalesce(args, () => ( {})));
185
185
  return {
@@ -209,7 +209,7 @@ var EdgeViteMCP = class {
209
209
  #sdkSchemaFor(tool) {
210
210
  let schema = this.#toolSchemas.get(tool);
211
211
  if (!schema) {
212
- schema = _chunkDURXYPPRcjs.toSdkSchema.call(void 0, tool.parameters, "input", convertToJsonSchema).then(
212
+ schema = _chunkQPVEGWOLcjs.toSdkSchema.call(void 0, tool.parameters, "input", convertToJsonSchema).then(
213
213
  (inputSchema) => ({ inputSchema }),
214
214
  (error) => {
215
215
  this.#logger.error(
@@ -3,7 +3,7 @@ import {
3
3
  ownKeysOnly,
4
4
  toSdkSchema,
5
5
  valibotToJsonSchema
6
- } from "../chunk-TYR2KJIV.js";
6
+ } from "../chunk-JMDI672G.js";
7
7
 
8
8
  // src/edge/index.ts
9
9
  import { createMcpHandler, McpServer } from "@modelcontextprotocol/server";
@@ -3,18 +3,19 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkC2VT2NXCcjs = require('../chunk-C2VT2NXC.cjs');
7
- require('../chunk-XGRRYN5Y.cjs');
8
- require('../chunk-DURXYPPR.cjs');
6
+ var _chunkNCSND5TIcjs = require('../chunk-NCSND5TI.cjs');
7
+ require('../chunk-SKQK3QGJ.cjs');
8
+ require('../chunk-QPVEGWOL.cjs');
9
9
 
10
10
  // src/openapi/parameters.ts
11
- var appendQueryParameter = (query, parameter, value) => {
11
+ var appendQueryParameter = (query, parameter, given) => {
12
12
  const style = _nullishCoalesce(parameter.style, () => ( "form"));
13
13
  const explode = _nullishCoalesce(parameter.explode, () => ( style === "form"));
14
14
  const name = parameter.name;
15
- if (value === null || value === void 0) {
15
+ if (given === null || given === void 0) {
16
16
  return;
17
17
  }
18
+ const value = withoutNullMembers(given);
18
19
  if (style === "deepObject") {
19
20
  if (isRecord(value)) {
20
21
  for (const [key, entry] of Object.entries(value)) {
@@ -74,8 +75,9 @@ var serializePathParameter = (parameter, value) => {
74
75
  }
75
76
  return body;
76
77
  };
77
- var serializeSimpleParameter = (parameter, value) => {
78
+ var serializeSimpleParameter = (parameter, given) => {
78
79
  const explode = _nullishCoalesce(parameter.explode, () => ( false));
80
+ const value = withoutNullMembers(given);
79
81
  if (Array.isArray(value)) {
80
82
  return value.map(stringify).join(",");
81
83
  }
@@ -95,6 +97,17 @@ var DELIMITERS = {
95
97
  spaceDelimited: " "
96
98
  };
97
99
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
100
+ var withoutNullMembers = (value) => {
101
+ if (Array.isArray(value)) {
102
+ return value.filter((entry) => entry !== null);
103
+ }
104
+ if (isRecord(value)) {
105
+ return Object.fromEntries(
106
+ Object.entries(value).filter(([, entry]) => entry !== null)
107
+ );
108
+ }
109
+ return value;
110
+ };
98
111
  var serializeSimple = (value, explode, name, style) => {
99
112
  const encode = (entry) => encodeURIComponent(stringify(entry));
100
113
  if (Array.isArray(value)) {
@@ -141,6 +154,9 @@ var executeRequest = async (options) => {
141
154
  continue;
142
155
  }
143
156
  const { parameter } = binder;
157
+ if (value === null && parameter.in !== "path") {
158
+ continue;
159
+ }
144
160
  switch (parameter.in) {
145
161
  case "cookie":
146
162
  cookies.push(
@@ -271,7 +287,7 @@ var buildBody = (binding, values, headers) => {
271
287
  var buildPath = (route, values) => {
272
288
  const unfilled = [...route.path.matchAll(/\{([^{}]*)\}/g)].filter(([, name]) => !values.has(name)).map(([placeholder]) => placeholder);
273
289
  if (unfilled.length > 0) {
274
- throw new (0, _chunkC2VT2NXCcjs.UserError)(
290
+ throw new (0, _chunkNCSND5TIcjs.UserError)(
275
291
  `${route.method.toUpperCase()} ${route.path} cannot be called: the OpenAPI document declares no path parameter for ${unfilled.join(", ")}.`
276
292
  );
277
293
  }
@@ -282,7 +298,7 @@ var buildPath = (route, values) => {
282
298
  const written = new Set(route.path.split("/").filter(isDotSegment));
283
299
  const introduced = path.split("/").find((segment) => isDotSegment(segment) && !written.has(segment));
284
300
  if (introduced !== void 0) {
285
- throw new (0, _chunkC2VT2NXCcjs.UserError)(
301
+ throw new (0, _chunkNCSND5TIcjs.UserError)(
286
302
  `${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.`
287
303
  );
288
304
  }
@@ -300,7 +316,7 @@ var readResponse = async (response, options) => {
300
316
  const mediaType = contentType.split(";")[0].trim().toLowerCase();
301
317
  const label = `${route.method.toUpperCase()} ${route.path}`;
302
318
  if (!response.ok) {
303
- throw new (0, _chunkC2VT2NXCcjs.UserError)(
319
+ throw new (0, _chunkNCSND5TIcjs.UserError)(
304
320
  `${label} failed with ${response.status} ${response.statusText}: ${truncate(
305
321
  await response.text(),
306
322
  2e3
@@ -312,7 +328,7 @@ var readResponse = async (response, options) => {
312
328
  if (bytes.byteLength <= MAX_INLINE_MEDIA_BYTES) {
313
329
  return mediaType.startsWith("image/") ? { data: toBase64(bytes), mimeType: mediaType, type: "image" } : { data: toBase64(bytes), mimeType: mediaType, type: "audio" };
314
330
  }
315
- throw new (0, _chunkC2VT2NXCcjs.UserError)(
331
+ throw new (0, _chunkNCSND5TIcjs.UserError)(
316
332
  `${label} returned ${bytes.byteLength} bytes of ${contentType}, too large to return inline.`
317
333
  );
318
334
  }
@@ -322,7 +338,7 @@ var readResponse = async (response, options) => {
322
338
  return { structuredContent: parsed };
323
339
  }
324
340
  if (binding.outputSchema) {
325
- throw new (0, _chunkC2VT2NXCcjs.UserError)(
341
+ throw new (0, _chunkNCSND5TIcjs.UserError)(
326
342
  `${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.`
327
343
  );
328
344
  }
@@ -344,7 +360,7 @@ var setHeader = (headers, name, value) => {
344
360
  try {
345
361
  headers.set(name, value);
346
362
  } catch (e2) {
347
- throw new (0, _chunkC2VT2NXCcjs.UserError)(
363
+ throw new (0, _chunkNCSND5TIcjs.UserError)(
348
364
  `"${name}" is not a valid header name, or the value given for it is not a valid header value.`
349
365
  );
350
366
  }
@@ -451,7 +467,7 @@ var readSpecText = async (spec) => {
451
467
  headers: { accept: "application/json, text/yaml, */*" }
452
468
  });
453
469
  if (!response.ok) {
454
- await _chunkC2VT2NXCcjs.cancelResponseBody.call(void 0, response);
470
+ await _chunkNCSND5TIcjs.cancelResponseBody.call(void 0, response);
455
471
  throw new Error(
456
472
  `Failed to fetch the OpenAPI document from ${spec}: ${response.status} ${response.statusText}`
457
473
  );
@@ -729,6 +745,41 @@ var collectDefinitions = (schema, definitions) => {
729
745
  [...referenced].sort().map((name) => [name, definitions[name]])
730
746
  );
731
747
  };
748
+ var schemaFor = (schema, direction) => {
749
+ if (Array.isArray(schema)) {
750
+ return schema.map((entry) => schemaFor(entry, direction));
751
+ }
752
+ if (!schema || typeof schema !== "object") {
753
+ return schema;
754
+ }
755
+ const result = {};
756
+ for (const [key, entry] of Object.entries(schema)) {
757
+ if (VALUE_KEYWORDS.has(key)) {
758
+ result[key] = entry;
759
+ } else if (SCHEMA_MAP_KEYWORDS.has(key) && entry && typeof entry === "object") {
760
+ result[key] = Object.fromEntries(
761
+ Object.entries(entry).map(
762
+ ([name, member]) => [name, schemaFor(member, direction)]
763
+ )
764
+ );
765
+ } else {
766
+ result[key] = schemaFor(entry, direction);
767
+ }
768
+ }
769
+ const { properties, required } = result;
770
+ if (Array.isArray(required) && properties && typeof properties === "object") {
771
+ const otherDirectionOnly = direction === "request" ? "readOnly" : "writeOnly";
772
+ const kept = required.filter(
773
+ (name) => typeof name !== "string" || !Object.hasOwn(properties, name) || _optionalChain([properties, 'access', _11 => _11[name], 'optionalAccess', _12 => _12[otherDirectionOnly]]) !== true
774
+ );
775
+ if (kept.length > 0) {
776
+ result.required = kept;
777
+ } else {
778
+ delete result.required;
779
+ }
780
+ }
781
+ return result;
782
+ };
732
783
  var normalizeKeywords = (schema) => {
733
784
  if (!("nullable" in schema) && !("required" in schema) && typeof schema.exclusiveMaximum !== "boolean" && typeof schema.exclusiveMinimum !== "boolean") {
734
785
  return schema;
@@ -770,7 +821,7 @@ var readPointer2 = (root, pointer) => {
770
821
  }
771
822
  let node = root;
772
823
  for (const segment of pointer.split("/").slice(1)) {
773
- node = _optionalChain([node, 'optionalAccess', _11 => _11[decodeSegment2(segment)]]);
824
+ node = _optionalChain([node, 'optionalAccess', _13 => _13[decodeSegment2(segment)]]);
774
825
  }
775
826
  return node;
776
827
  };
@@ -827,7 +878,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
827
878
  const requiredOnceSent = [];
828
879
  for (const [name, property] of body.properties) {
829
880
  const key = name === "__proto__" ? claimKey(`${name}__body`) : name;
830
- properties[key] = property.schema;
881
+ properties[key] = schemaFor(property.schema, "request");
831
882
  parameters[key] = { kind: "body", name };
832
883
  bodyKeys.push(key);
833
884
  if (property.required) {
@@ -846,7 +897,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
846
897
  }
847
898
  const definitions = collectDefinitions(properties, normalizer.definitions);
848
899
  if (definitions) {
849
- inputSchema.$defs = definitions;
900
+ inputSchema.$defs = definitionsFor(definitions, "request");
850
901
  }
851
902
  return {
852
903
  bodyEncoding: body.encoding,
@@ -860,7 +911,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
860
911
  };
861
912
  var describeBody = (route, normalizer) => {
862
913
  const properties = /* @__PURE__ */ new Map();
863
- const content = route.method === "get" ? void 0 : _optionalChain([route, 'access', _12 => _12.requestBody, 'optionalAccess', _13 => _13.content]);
914
+ const content = route.method === "get" ? void 0 : _optionalChain([route, 'access', _14 => _14.requestBody, 'optionalAccess', _15 => _15.content]);
864
915
  if (!content || Object.keys(content).length === 0) {
865
916
  return { properties };
866
917
  }
@@ -873,8 +924,8 @@ var describeBody = (route, normalizer) => {
873
924
  }
874
925
  const kind = encodingKindFor(contentType);
875
926
  const encoding = { contentType, kind };
876
- const required = _nullishCoalesce(_optionalChain([route, 'access', _14 => _14.requestBody, 'optionalAccess', _15 => _15.required]), () => ( false));
877
- const rawSchema = _optionalChain([content, 'access', _16 => _16[contentType], 'optionalAccess', _17 => _17.schema]);
927
+ const required = _nullishCoalesce(_optionalChain([route, 'access', _16 => _16.requestBody, 'optionalAccess', _17 => _17.required]), () => ( false));
928
+ const rawSchema = _optionalChain([content, 'access', _18 => _18[contentType], 'optionalAccess', _19 => _19.schema]);
878
929
  const schema = rawSchema ? normalizer.normalize(rawSchema) : void 0;
879
930
  if (kind === "text") {
880
931
  properties.set("body", { required, schema: _nullishCoalesce(schema, () => ( { type: "string" })) });
@@ -887,7 +938,8 @@ var describeBody = (route, normalizer) => {
887
938
  if (object && Object.keys(object.properties).length > 0) {
888
939
  for (const [name, property] of Object.entries(object.properties)) {
889
940
  properties.set(name, {
890
- required: object.required.has(name),
941
+ // The server's to fill in; see `schemaFor`.
942
+ required: object.required.has(name) && property.readOnly !== true,
891
943
  schema: property
892
944
  });
893
945
  }
@@ -898,27 +950,42 @@ var describeBody = (route, normalizer) => {
898
950
  };
899
951
  var MAX_OUTPUT_SCHEMA_DEFINITIONS = 100;
900
952
  var buildOutputSchema = (route, normalizer) => {
901
- const status = Object.keys(route.responses).filter((code) => /^2\d\d$/.test(code)).sort()[0];
902
- const content = status ? _optionalChain([route, 'access', _18 => _18.responses, 'access', _19 => _19[status], 'optionalAccess', _20 => _20.content]) : void 0;
903
- const contentType = content && findJsonContentType(Object.keys(content));
904
- const raw = contentType ? _optionalChain([content, 'optionalAccess', _21 => _21[contentType], 'optionalAccess', _22 => _22.schema]) : void 0;
905
- if (!raw) {
906
- return void 0;
953
+ const statuses = Object.keys(route.responses).filter((code) => /^2\d\d$/.test(code)).sort();
954
+ const alternatives = /* @__PURE__ */ new Map();
955
+ for (const status of statuses) {
956
+ const content = _optionalChain([route, 'access', _20 => _20.responses, 'access', _21 => _21[status], 'optionalAccess', _22 => _22.content]);
957
+ const contentType = content && findJsonContentType(Object.keys(content));
958
+ const raw = contentType ? _optionalChain([content, 'optionalAccess', _23 => _23[contentType], 'optionalAccess', _24 => _24.schema]) : void 0;
959
+ if (!raw) {
960
+ return void 0;
961
+ }
962
+ const schema2 = normalizer.normalize(raw);
963
+ if (!resolvesToObject(schema2, normalizer.definitions)) {
964
+ return void 0;
965
+ }
966
+ alternatives.set(JSON.stringify(schema2), schema2);
907
967
  }
908
- const schema = normalizer.normalize(raw);
909
- if (!resolvesToObject(schema, normalizer.definitions)) {
968
+ if (alternatives.size === 0) {
910
969
  return void 0;
911
970
  }
971
+ const [first, ...others] = alternatives.values();
972
+ const schema = others.length === 0 ? first : { anyOf: [first, ...others] };
912
973
  const definitions = collectDefinitions(schema, normalizer.definitions);
913
974
  if (definitions && Object.keys(definitions).length > MAX_OUTPUT_SCHEMA_DEFINITIONS) {
914
975
  return void 0;
915
976
  }
916
977
  return {
917
- ...schema,
978
+ ...schemaFor(schema, "response"),
918
979
  type: "object",
919
- ...definitions ? { $defs: definitions } : {}
980
+ ...definitions ? { $defs: definitionsFor(definitions, "response") } : {}
920
981
  };
921
982
  };
983
+ var definitionsFor = (definitions, direction) => Object.fromEntries(
984
+ Object.entries(definitions).map(([name, definition]) => [
985
+ name,
986
+ schemaFor(definition, direction)
987
+ ])
988
+ );
922
989
  var describeParameter = (parameter, normalizer) => {
923
990
  const schema = normalizer.normalize(_nullishCoalesce(parameter.schema, () => ( { type: "string" })));
924
991
  const description = [
@@ -1039,10 +1106,10 @@ var fromOpenAPI = async (options) => {
1039
1106
  const selected = selectRoutes(extractRoutes(document), options);
1040
1107
  const names = generateToolNames(selected, options.toolNames);
1041
1108
  const normalizer = createSchemaNormalizer(document);
1042
- const server = _nullishCoalesce(options.server, () => ( new (0, _chunkC2VT2NXCcjs.ViteMCP)({
1043
- description: _optionalChain([document, 'access', _23 => _23.info, 'optionalAccess', _24 => _24.description]),
1044
- name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _25 => _25.info, 'optionalAccess', _26 => _26.title]))), () => ( "OpenAPI")),
1045
- version: _nullishCoalesce(options.version, () => ( semanticVersion(_optionalChain([document, 'access', _27 => _27.info, 'optionalAccess', _28 => _28.version]))))
1109
+ const server = _nullishCoalesce(options.server, () => ( new (0, _chunkNCSND5TIcjs.ViteMCP)({
1110
+ description: _optionalChain([document, 'access', _25 => _25.info, 'optionalAccess', _26 => _26.description]),
1111
+ name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _27 => _27.info, 'optionalAccess', _28 => _28.title]))), () => ( "OpenAPI")),
1112
+ version: _nullishCoalesce(options.version, () => ( semanticVersion(_optionalChain([document, 'access', _29 => _29.info, 'optionalAccess', _30 => _30.version]))))
1046
1113
  })));
1047
1114
  for (const route of selected) {
1048
1115
  const name = names.get(route);
@@ -1078,8 +1145,8 @@ var fromOpenAPI = async (options) => {
1078
1145
  route
1079
1146
  }),
1080
1147
  name,
1081
- outputSchema: binding.outputSchema ? _chunkC2VT2NXCcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1082
- parameters: _chunkC2VT2NXCcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1148
+ outputSchema: binding.outputSchema ? _chunkNCSND5TIcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1149
+ parameters: _chunkNCSND5TIcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1083
1150
  timeoutMs: options.timeoutMs
1084
1151
  });
1085
1152
  }