fastmcp 4.29.2 → 4.30.1

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.
@@ -2,8 +2,8 @@ import {
2
2
  FastMCP,
3
3
  UserError,
4
4
  jsonSchemaAdapter
5
- } from "../chunk-T7EFBHCA.js";
6
- import "../chunk-PA3GWZUK.js";
5
+ } from "../chunk-5KA6SOWT.js";
6
+ import "../chunk-XPTUOWUT.js";
7
7
  import "../chunk-JCKJRUCE.js";
8
8
 
9
9
  // src/openapi/loadSpec.ts
@@ -84,9 +84,10 @@ function buildFlatSchema(route, sharedDefs) {
84
84
  const requiredBodyKeys = [];
85
85
  for (const [name, { required: isRequired, schema }] of bodyProperties) {
86
86
  const key = name === "__proto__" ? allocateAlias(`${name}__body`) : name;
87
- properties[key] = omitReadOnlyRequired(
87
+ properties[key] = omitRequiredByAnnotation(
88
88
  rewriteComponentRefs(schema),
89
- "schema"
89
+ "schema",
90
+ "readOnly"
90
91
  );
91
92
  parameterMap[key] = { in: "body", name };
92
93
  bodyKeys.push(key);
@@ -109,7 +110,11 @@ function buildFlatSchema(route, sharedDefs) {
109
110
  }
110
111
  const usedDefs = sharedDefs && filterReferencedDefs(properties, sharedDefs);
111
112
  if (usedDefs) {
112
- flatSchema.$defs = omitReadOnlyRequired(usedDefs, "schemaMap");
113
+ flatSchema.$defs = omitRequiredByAnnotation(
114
+ usedDefs,
115
+ "schemaMap",
116
+ "readOnly"
117
+ );
113
118
  }
114
119
  return {
115
120
  bodyEncoding,
@@ -161,12 +166,17 @@ function buildOutputSchema(route, sharedDefs) {
161
166
  if (usedDefs && Object.keys(usedDefs).length > MAX_OUTPUT_SCHEMA_DEFS) {
162
167
  return void 0;
163
168
  }
164
- return {
169
+ const outputSchema = {
165
170
  ...normalized,
166
171
  ...usedDefs ? {
167
172
  $defs: rewriteNode(usedDefs, "schemaMap", true)
168
173
  } : {}
169
174
  };
175
+ return omitRequiredByAnnotation(
176
+ outputSchema,
177
+ "schema",
178
+ "writeOnly"
179
+ );
170
180
  }
171
181
  function resolveComponentRef(schema, sharedDefs) {
172
182
  const seen = /* @__PURE__ */ new Set();
@@ -323,29 +333,32 @@ function normalizeNullable(schema) {
323
333
  }
324
334
  return rest;
325
335
  }
326
- function omitReadOnlyRequired(value, mode) {
336
+ function omitRequiredByAnnotation(value, mode, annotation) {
327
337
  if (mode === "data" || !value || typeof value !== "object") {
328
338
  return value;
329
339
  }
330
340
  if (Array.isArray(value)) {
331
- return value.map((item) => omitReadOnlyRequired(item, "schema"));
341
+ return value.map(
342
+ (item) => omitRequiredByAnnotation(item, "schema", annotation)
343
+ );
332
344
  }
333
345
  const node = Object.fromEntries(
334
346
  Object.entries(value).map(([key, child]) => [
335
347
  key,
336
- omitReadOnlyRequired(
348
+ omitRequiredByAnnotation(
337
349
  child,
338
- mode === "schemaMap" ? "schema" : childMode(key)
350
+ mode === "schemaMap" ? "schema" : childMode(key),
351
+ annotation
339
352
  )
340
353
  ])
341
354
  );
342
355
  const { properties, required } = node;
343
356
  if (mode === "schema" && Array.isArray(required) && properties && typeof properties === "object") {
344
- const writable = required.filter(
345
- (name) => !(typeof name === "string" && Object.hasOwn(properties, name) && properties[name]?.readOnly === true)
357
+ const remaining = required.filter(
358
+ (name) => !(typeof name === "string" && Object.hasOwn(properties, name) && properties[name]?.[annotation] === true)
346
359
  );
347
- if (writable.length > 0) {
348
- node.required = writable;
360
+ if (remaining.length > 0) {
361
+ node.required = remaining;
349
362
  } else {
350
363
  delete node.required;
351
364
  }
@@ -672,7 +685,13 @@ function encodePathComponent(value) {
672
685
  (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`
673
686
  );
674
687
  }
675
- function encodePathValue(value, style, explode) {
688
+ function encodePathValue(name, value, style, explode) {
689
+ if (style === "label" || style === "matrix") {
690
+ const prefixed = encodePrefixedPathValue(name, value, style, explode);
691
+ if (prefixed !== void 0) {
692
+ return prefixed;
693
+ }
694
+ }
676
695
  if ((style === void 0 || style === "simple") && Array.isArray(value) && value.every((item) => item === null || typeof item !== "object")) {
677
696
  return value.map((item) => encodePathComponent(String(item))).join(",");
678
697
  }
@@ -688,6 +707,51 @@ function encodePathValue(value, style, explode) {
688
707
  }
689
708
  return encodeURIComponent(String(value));
690
709
  }
710
+ function encodePrefixedPathValue(name, value, style, explode) {
711
+ const isFlat = (item) => item === null || typeof item !== "object";
712
+ const encodedName = encodePathComponent(name);
713
+ const named = (key, encoded) => encoded === "" ? key : `${key}=${encoded}`;
714
+ if (value === null) {
715
+ return void 0;
716
+ }
717
+ if (typeof value !== "object") {
718
+ const encoded = encodePathComponent(String(value));
719
+ return style === "label" ? `.${encoded}` : `;${named(encodedName, encoded)}`;
720
+ }
721
+ let items;
722
+ let pairs;
723
+ if (Array.isArray(value)) {
724
+ if (!value.every(isFlat)) {
725
+ return void 0;
726
+ }
727
+ items = value.map((item) => encodePathComponent(String(item)));
728
+ } else {
729
+ const entries = Object.entries(value);
730
+ if (!entries.every(([, item]) => isFlat(item))) {
731
+ return void 0;
732
+ }
733
+ pairs = entries.map(([key, item]) => [
734
+ encodePathComponent(key),
735
+ encodePathComponent(String(item))
736
+ ]);
737
+ items = pairs.flat();
738
+ }
739
+ if (items.length === 0) {
740
+ return "";
741
+ }
742
+ if (explode !== true) {
743
+ const joined = items.join(",");
744
+ return style === "label" ? `.${joined}` : `;${encodedName}=${joined}`;
745
+ }
746
+ if (pairs) {
747
+ return pairs.map(
748
+ ([key, encoded]) => style === "label" ? `.${key}=${encoded}` : `;${named(key, encoded)}`
749
+ ).join("");
750
+ }
751
+ return items.map(
752
+ (encoded) => style === "label" ? `.${encoded}` : `;${named(encodedName, encoded)}`
753
+ ).join("");
754
+ }
691
755
  async function fetchResponse(options) {
692
756
  const baseUrl = resolveBaseUrl(
693
757
  options.servers,
@@ -726,7 +790,12 @@ async function fetchResponse(options) {
726
790
  );
727
791
  break;
728
792
  case "path":
729
- pathParams[mapping.name] = mapping.encoding === "json" ? encodePathComponent(JSON.stringify(value)) : encodePathValue(value, mapping.style, mapping.explode);
793
+ pathParams[mapping.name] = mapping.encoding === "json" ? encodePathComponent(JSON.stringify(value)) : encodePathValue(
794
+ mapping.name,
795
+ value,
796
+ mapping.style,
797
+ mapping.explode
798
+ );
730
799
  break;
731
800
  case "query": {
732
801
  const query = new URLSearchParams();