@vitemcp/server 1.9.12 → 1.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,18 +3,19 @@
3
3
 
4
4
 
5
5
 
6
- var _chunk7T5D57AMcjs = require('../chunk-7T5D57AM.cjs');
7
- require('../chunk-2X4JCSQQ.cjs');
6
+ var _chunk7MAOWIMRcjs = require('../chunk-7MAOWIMR.cjs');
7
+ require('../chunk-T7EJGNI3.cjs');
8
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)) {
@@ -274,7 +287,7 @@ var buildBody = (binding, values, headers) => {
274
287
  var buildPath = (route, values) => {
275
288
  const unfilled = [...route.path.matchAll(/\{([^{}]*)\}/g)].filter(([, name]) => !values.has(name)).map(([placeholder]) => placeholder);
276
289
  if (unfilled.length > 0) {
277
- throw new (0, _chunk7T5D57AMcjs.UserError)(
290
+ throw new (0, _chunk7MAOWIMRcjs.UserError)(
278
291
  `${route.method.toUpperCase()} ${route.path} cannot be called: the OpenAPI document declares no path parameter for ${unfilled.join(", ")}.`
279
292
  );
280
293
  }
@@ -285,7 +298,7 @@ var buildPath = (route, values) => {
285
298
  const written = new Set(route.path.split("/").filter(isDotSegment));
286
299
  const introduced = path.split("/").find((segment) => isDotSegment(segment) && !written.has(segment));
287
300
  if (introduced !== void 0) {
288
- throw new (0, _chunk7T5D57AMcjs.UserError)(
301
+ throw new (0, _chunk7MAOWIMRcjs.UserError)(
289
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.`
290
303
  );
291
304
  }
@@ -303,7 +316,7 @@ var readResponse = async (response, options) => {
303
316
  const mediaType = contentType.split(";")[0].trim().toLowerCase();
304
317
  const label = `${route.method.toUpperCase()} ${route.path}`;
305
318
  if (!response.ok) {
306
- throw new (0, _chunk7T5D57AMcjs.UserError)(
319
+ throw new (0, _chunk7MAOWIMRcjs.UserError)(
307
320
  `${label} failed with ${response.status} ${response.statusText}: ${truncate(
308
321
  await response.text(),
309
322
  2e3
@@ -315,7 +328,7 @@ var readResponse = async (response, options) => {
315
328
  if (bytes.byteLength <= MAX_INLINE_MEDIA_BYTES) {
316
329
  return mediaType.startsWith("image/") ? { data: toBase64(bytes), mimeType: mediaType, type: "image" } : { data: toBase64(bytes), mimeType: mediaType, type: "audio" };
317
330
  }
318
- throw new (0, _chunk7T5D57AMcjs.UserError)(
331
+ throw new (0, _chunk7MAOWIMRcjs.UserError)(
319
332
  `${label} returned ${bytes.byteLength} bytes of ${contentType}, too large to return inline.`
320
333
  );
321
334
  }
@@ -325,7 +338,7 @@ var readResponse = async (response, options) => {
325
338
  return { structuredContent: parsed };
326
339
  }
327
340
  if (binding.outputSchema) {
328
- throw new (0, _chunk7T5D57AMcjs.UserError)(
341
+ throw new (0, _chunk7MAOWIMRcjs.UserError)(
329
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.`
330
343
  );
331
344
  }
@@ -347,7 +360,7 @@ var setHeader = (headers, name, value) => {
347
360
  try {
348
361
  headers.set(name, value);
349
362
  } catch (e2) {
350
- throw new (0, _chunk7T5D57AMcjs.UserError)(
363
+ throw new (0, _chunk7MAOWIMRcjs.UserError)(
351
364
  `"${name}" is not a valid header name, or the value given for it is not a valid header value.`
352
365
  );
353
366
  }
@@ -454,7 +467,7 @@ var readSpecText = async (spec) => {
454
467
  headers: { accept: "application/json, text/yaml, */*" }
455
468
  });
456
469
  if (!response.ok) {
457
- await _chunk7T5D57AMcjs.cancelResponseBody.call(void 0, response);
470
+ await _chunk7MAOWIMRcjs.cancelResponseBody.call(void 0, response);
458
471
  throw new Error(
459
472
  `Failed to fetch the OpenAPI document from ${spec}: ${response.status} ${response.statusText}`
460
473
  );
@@ -732,6 +745,41 @@ var collectDefinitions = (schema, definitions) => {
732
745
  [...referenced].sort().map((name) => [name, definitions[name]])
733
746
  );
734
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
+ };
735
783
  var normalizeKeywords = (schema) => {
736
784
  if (!("nullable" in schema) && !("required" in schema) && typeof schema.exclusiveMaximum !== "boolean" && typeof schema.exclusiveMinimum !== "boolean") {
737
785
  return schema;
@@ -773,7 +821,7 @@ var readPointer2 = (root, pointer) => {
773
821
  }
774
822
  let node = root;
775
823
  for (const segment of pointer.split("/").slice(1)) {
776
- node = _optionalChain([node, 'optionalAccess', _11 => _11[decodeSegment2(segment)]]);
824
+ node = _optionalChain([node, 'optionalAccess', _13 => _13[decodeSegment2(segment)]]);
777
825
  }
778
826
  return node;
779
827
  };
@@ -830,7 +878,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
830
878
  const requiredOnceSent = [];
831
879
  for (const [name, property] of body.properties) {
832
880
  const key = name === "__proto__" ? claimKey(`${name}__body`) : name;
833
- properties[key] = property.schema;
881
+ properties[key] = schemaFor(property.schema, "request");
834
882
  parameters[key] = { kind: "body", name };
835
883
  bodyKeys.push(key);
836
884
  if (property.required) {
@@ -849,7 +897,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
849
897
  }
850
898
  const definitions = collectDefinitions(properties, normalizer.definitions);
851
899
  if (definitions) {
852
- inputSchema.$defs = definitions;
900
+ inputSchema.$defs = definitionsFor(definitions, "request");
853
901
  }
854
902
  return {
855
903
  bodyEncoding: body.encoding,
@@ -863,7 +911,7 @@ var buildToolBinding = (route, normalizer, withOutputSchema) => {
863
911
  };
864
912
  var describeBody = (route, normalizer) => {
865
913
  const properties = /* @__PURE__ */ new Map();
866
- 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]);
867
915
  if (!content || Object.keys(content).length === 0) {
868
916
  return { properties };
869
917
  }
@@ -876,8 +924,8 @@ var describeBody = (route, normalizer) => {
876
924
  }
877
925
  const kind = encodingKindFor(contentType);
878
926
  const encoding = { contentType, kind };
879
- const required = _nullishCoalesce(_optionalChain([route, 'access', _14 => _14.requestBody, 'optionalAccess', _15 => _15.required]), () => ( false));
880
- 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]);
881
929
  const schema = rawSchema ? normalizer.normalize(rawSchema) : void 0;
882
930
  if (kind === "text") {
883
931
  properties.set("body", { required, schema: _nullishCoalesce(schema, () => ( { type: "string" })) });
@@ -890,7 +938,8 @@ var describeBody = (route, normalizer) => {
890
938
  if (object && Object.keys(object.properties).length > 0) {
891
939
  for (const [name, property] of Object.entries(object.properties)) {
892
940
  properties.set(name, {
893
- required: object.required.has(name),
941
+ // The server's to fill in; see `schemaFor`.
942
+ required: object.required.has(name) && property.readOnly !== true,
894
943
  schema: property
895
944
  });
896
945
  }
@@ -901,27 +950,42 @@ var describeBody = (route, normalizer) => {
901
950
  };
902
951
  var MAX_OUTPUT_SCHEMA_DEFINITIONS = 100;
903
952
  var buildOutputSchema = (route, normalizer) => {
904
- const status = Object.keys(route.responses).filter((code) => /^2\d\d$/.test(code)).sort()[0];
905
- const content = status ? _optionalChain([route, 'access', _18 => _18.responses, 'access', _19 => _19[status], 'optionalAccess', _20 => _20.content]) : void 0;
906
- const contentType = content && findJsonContentType(Object.keys(content));
907
- const raw = contentType ? _optionalChain([content, 'optionalAccess', _21 => _21[contentType], 'optionalAccess', _22 => _22.schema]) : void 0;
908
- if (!raw) {
909
- 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);
910
967
  }
911
- const schema = normalizer.normalize(raw);
912
- if (!resolvesToObject(schema, normalizer.definitions)) {
968
+ if (alternatives.size === 0) {
913
969
  return void 0;
914
970
  }
971
+ const [first, ...others] = alternatives.values();
972
+ const schema = others.length === 0 ? first : { anyOf: [first, ...others] };
915
973
  const definitions = collectDefinitions(schema, normalizer.definitions);
916
974
  if (definitions && Object.keys(definitions).length > MAX_OUTPUT_SCHEMA_DEFINITIONS) {
917
975
  return void 0;
918
976
  }
919
977
  return {
920
- ...schema,
978
+ ...schemaFor(schema, "response"),
921
979
  type: "object",
922
- ...definitions ? { $defs: definitions } : {}
980
+ ...definitions ? { $defs: definitionsFor(definitions, "response") } : {}
923
981
  };
924
982
  };
983
+ var definitionsFor = (definitions, direction) => Object.fromEntries(
984
+ Object.entries(definitions).map(([name, definition]) => [
985
+ name,
986
+ schemaFor(definition, direction)
987
+ ])
988
+ );
925
989
  var describeParameter = (parameter, normalizer) => {
926
990
  const schema = normalizer.normalize(_nullishCoalesce(parameter.schema, () => ( { type: "string" })));
927
991
  const description = [
@@ -1042,10 +1106,10 @@ var fromOpenAPI = async (options) => {
1042
1106
  const selected = selectRoutes(extractRoutes(document), options);
1043
1107
  const names = generateToolNames(selected, options.toolNames);
1044
1108
  const normalizer = createSchemaNormalizer(document);
1045
- const server = _nullishCoalesce(options.server, () => ( new (0, _chunk7T5D57AMcjs.ViteMCP)({
1046
- description: _optionalChain([document, 'access', _23 => _23.info, 'optionalAccess', _24 => _24.description]),
1047
- name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _25 => _25.info, 'optionalAccess', _26 => _26.title]))), () => ( "OpenAPI")),
1048
- version: _nullishCoalesce(options.version, () => ( semanticVersion(_optionalChain([document, 'access', _27 => _27.info, 'optionalAccess', _28 => _28.version]))))
1109
+ const server = _nullishCoalesce(options.server, () => ( new (0, _chunk7MAOWIMRcjs.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]))))
1049
1113
  })));
1050
1114
  for (const route of selected) {
1051
1115
  const name = names.get(route);
@@ -1081,8 +1145,8 @@ var fromOpenAPI = async (options) => {
1081
1145
  route
1082
1146
  }),
1083
1147
  name,
1084
- outputSchema: binding.outputSchema ? _chunk7T5D57AMcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1085
- parameters: _chunk7T5D57AMcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1148
+ outputSchema: binding.outputSchema ? _chunk7MAOWIMRcjs.jsonSchemaAdapter.call(void 0, binding.outputSchema) : void 0,
1149
+ parameters: _chunk7MAOWIMRcjs.jsonSchemaAdapter.call(void 0, binding.inputSchema),
1086
1150
  timeoutMs: options.timeoutMs
1087
1151
  });
1088
1152
  }