fastmcp 4.26.2 → 4.28.0

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 (45) hide show
  1. package/dist/FastMCP.cjs +4 -4
  2. package/dist/FastMCP.d.cts +2 -2
  3. package/dist/FastMCP.d.ts +2 -2
  4. package/dist/FastMCP.js +3 -3
  5. package/dist/{OAuthProvider-B7VDZGyx.d.cts → OAuthProvider-BnQsqcsL.d.cts} +13 -3
  6. package/dist/{OAuthProvider-B7VDZGyx.d.ts → OAuthProvider-BnQsqcsL.d.ts} +13 -3
  7. package/dist/auth/index.cjs +2 -2
  8. package/dist/auth/index.d.cts +2 -2
  9. package/dist/auth/index.d.ts +2 -2
  10. package/dist/auth/index.js +1 -1
  11. package/dist/chunk-2NZFMD6I.cjs +120 -0
  12. package/dist/chunk-2NZFMD6I.cjs.map +1 -0
  13. package/dist/{chunk-W6P57SNV.js → chunk-4ZSNKIR3.js} +37 -5
  14. package/dist/chunk-4ZSNKIR3.js.map +1 -0
  15. package/dist/{chunk-UULT6NOS.cjs → chunk-AAPHX5IG.cjs} +28 -13
  16. package/dist/chunk-AAPHX5IG.cjs.map +1 -0
  17. package/dist/chunk-AM3HVK4Z.js +120 -0
  18. package/dist/chunk-AM3HVK4Z.js.map +1 -0
  19. package/dist/{chunk-ASOZUCE2.js → chunk-EI3KPYSZ.js} +22 -7
  20. package/dist/chunk-EI3KPYSZ.js.map +1 -0
  21. package/dist/{chunk-HVKGDRTL.cjs → chunk-VVAKRLCY.cjs} +37 -5
  22. package/dist/chunk-VVAKRLCY.cjs.map +1 -0
  23. package/dist/edge/index.cjs +61 -43
  24. package/dist/edge/index.cjs.map +1 -1
  25. package/dist/edge/index.d.cts +0 -6
  26. package/dist/edge/index.d.ts +0 -6
  27. package/dist/edge/index.js +59 -41
  28. package/dist/edge/index.js.map +1 -1
  29. package/dist/examples/custom-routes.cjs +4 -4
  30. package/dist/examples/custom-routes.js +3 -3
  31. package/dist/openapi/index.cjs +98 -36
  32. package/dist/openapi/index.cjs.map +1 -1
  33. package/dist/openapi/index.d.cts +4 -4
  34. package/dist/openapi/index.d.ts +4 -4
  35. package/dist/openapi/index.js +88 -26
  36. package/dist/openapi/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunk-6TDYSPLC.cjs +0 -44
  39. package/dist/chunk-6TDYSPLC.cjs.map +0 -1
  40. package/dist/chunk-ASOZUCE2.js.map +0 -1
  41. package/dist/chunk-HVKGDRTL.cjs.map +0 -1
  42. package/dist/chunk-OKKFL2M4.js +0 -44
  43. package/dist/chunk-OKKFL2M4.js.map +0 -1
  44. package/dist/chunk-UULT6NOS.cjs.map +0 -1
  45. package/dist/chunk-W6P57SNV.js.map +0 -1
@@ -2,9 +2,9 @@ import {
2
2
  FastMCP,
3
3
  UserError,
4
4
  jsonSchemaAdapter
5
- } from "../chunk-ASOZUCE2.js";
6
- import "../chunk-W6P57SNV.js";
7
- import "../chunk-OKKFL2M4.js";
5
+ } from "../chunk-EI3KPYSZ.js";
6
+ import "../chunk-4ZSNKIR3.js";
7
+ import "../chunk-AM3HVK4Z.js";
8
8
 
9
9
  // src/openapi/loadSpec.ts
10
10
  import SwaggerParser from "@apidevtools/swagger-parser";
@@ -38,7 +38,7 @@ function buildFlatSchema(route, sharedDefs) {
38
38
  unsupportedBodyContentType,
39
39
  wholeBodyKey
40
40
  } = extractBodyProperties(
41
- route.method === "get" ? void 0 : route.requestBody,
41
+ route.method === "get" || route.method === "head" ? void 0 : route.requestBody,
42
42
  sharedDefs
43
43
  );
44
44
  const properties = /* @__PURE__ */ Object.create(null);
@@ -84,10 +84,13 @@ 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] = rewriteComponentRefs(schema);
87
+ properties[key] = omitReadOnlyRequired(
88
+ rewriteComponentRefs(schema),
89
+ "schema"
90
+ );
88
91
  parameterMap[key] = { in: "body", name };
89
92
  bodyKeys.push(key);
90
- if (isRequired) {
93
+ if (isRequired && schema.readOnly !== true) {
91
94
  requiredBodyKeys.push(key);
92
95
  }
93
96
  }
@@ -106,7 +109,7 @@ function buildFlatSchema(route, sharedDefs) {
106
109
  }
107
110
  const usedDefs = sharedDefs && filterReferencedDefs(properties, sharedDefs);
108
111
  if (usedDefs) {
109
- flatSchema.$defs = usedDefs;
112
+ flatSchema.$defs = omitReadOnlyRequired(usedDefs, "schemaMap");
110
113
  }
111
114
  return {
112
115
  bodyEncoding,
@@ -126,24 +129,34 @@ function buildSharedDefs(document) {
126
129
  var SUCCESS_STATUS_PATTERN = /^2\d\d$/;
127
130
  var MAX_OUTPUT_SCHEMA_DEFS = 50;
128
131
  function buildOutputSchema(route, sharedDefs) {
129
- const successEntry = Object.entries(route.responses ?? {}).find(
132
+ if (route.method === "head") {
133
+ return void 0;
134
+ }
135
+ const successEntries = Object.entries(route.responses ?? {}).filter(
130
136
  ([code]) => SUCCESS_STATUS_PATTERN.test(code)
131
137
  );
132
- const declaredSchema = findMediaType(
133
- successEntry?.[1].content,
134
- "application/json"
135
- )?.schema;
136
- if (!declaredSchema) {
138
+ if (successEntries.length === 0) {
137
139
  return void 0;
138
140
  }
139
- const schema = resolveComponentRef(declaredSchema, sharedDefs);
140
- const rewritten = rewriteComponentRefs(schema, true);
141
- const { type } = rewritten;
142
- const isObjectShaped = type === "object" || Array.isArray(type) && type.includes("object");
143
- if (!isObjectShaped) {
144
- return void 0;
141
+ const schemas = [];
142
+ for (const [, response] of successEntries) {
143
+ const declaredSchema = findMediaType(
144
+ response.content,
145
+ "application/json"
146
+ )?.schema;
147
+ if (!declaredSchema) {
148
+ return void 0;
149
+ }
150
+ const schema = resolveComponentRef(declaredSchema, sharedDefs);
151
+ const rewritten = rewriteComponentRefs(schema, true);
152
+ const { type } = rewritten;
153
+ const isObjectShaped = type === "object" || Array.isArray(type) && type.includes("object");
154
+ if (!isObjectShaped) {
155
+ return void 0;
156
+ }
157
+ schemas.push({ ...rewritten, type: "object" });
145
158
  }
146
- const normalized = { ...rewritten, type: "object" };
159
+ const normalized = schemas.length === 1 ? schemas[0] : { anyOf: schemas, type: "object" };
147
160
  const usedDefs = sharedDefs && filterReferencedDefs(normalized, sharedDefs);
148
161
  if (usedDefs && Object.keys(usedDefs).length > MAX_OUTPUT_SCHEMA_DEFS) {
149
162
  return void 0;
@@ -309,6 +322,35 @@ function normalizeNullable(schema) {
309
322
  }
310
323
  return rest;
311
324
  }
325
+ function omitReadOnlyRequired(value, mode) {
326
+ if (mode === "data" || !value || typeof value !== "object") {
327
+ return value;
328
+ }
329
+ if (Array.isArray(value)) {
330
+ return value.map((item) => omitReadOnlyRequired(item, "schema"));
331
+ }
332
+ const node = Object.fromEntries(
333
+ Object.entries(value).map(([key, child]) => [
334
+ key,
335
+ omitReadOnlyRequired(
336
+ child,
337
+ mode === "schemaMap" ? "schema" : childMode(key)
338
+ )
339
+ ])
340
+ );
341
+ const { properties, required } = node;
342
+ if (mode === "schema" && Array.isArray(required) && properties && typeof properties === "object") {
343
+ const writable = required.filter(
344
+ (name) => !(typeof name === "string" && Object.hasOwn(properties, name) && properties[name]?.readOnly === true)
345
+ );
346
+ if (writable.length > 0) {
347
+ node.required = writable;
348
+ } else {
349
+ delete node.required;
350
+ }
351
+ }
352
+ return node;
353
+ }
312
354
  function rewriteNode(value, mode, stripExamples = false) {
313
355
  if (mode === "data") {
314
356
  return value;
@@ -628,12 +670,13 @@ function appendBracketPairs(params, key, value) {
628
670
  params.append(key, String(value));
629
671
  }
630
672
  function appendQueryValue(query, name, style, value, explode) {
673
+ value = withoutNullMembers(value);
631
674
  if (style === "deepObject") {
632
675
  appendBracketPairs(query, name, value);
633
676
  return;
634
677
  }
635
678
  if (style === "spaceDelimited" || style === "pipeDelimited") {
636
- const items = Array.isArray(value) ? value : [value];
679
+ const items = Array.isArray(value) ? value : value !== null && typeof value === "object" ? Object.entries(value).flat() : [value];
637
680
  const separator = style === "spaceDelimited" ? " " : "|";
638
681
  query.append(name, items.map(String).join(separator));
639
682
  return;
@@ -752,6 +795,17 @@ function serializeQuery(query, allowReserved) {
752
795
  return `${name}=${expanded}`;
753
796
  }).join("&");
754
797
  }
798
+ function withoutNullMembers(value) {
799
+ if (Array.isArray(value)) {
800
+ return value.filter((item) => item !== null).map((item) => withoutNullMembers(item));
801
+ }
802
+ if (value !== null && typeof value === "object") {
803
+ return Object.fromEntries(
804
+ Object.entries(value).filter(([, item]) => item !== null).map(([key, item]) => [key, withoutNullMembers(item)])
805
+ );
806
+ }
807
+ return value;
808
+ }
755
809
 
756
810
  // src/openapi/resourceMapping.ts
757
811
  function buildResourceMapping(route, name, parameterMap, requiredKeys) {
@@ -788,7 +842,14 @@ function isEligibleForResource(route, sharedDefs) {
788
842
  }
789
843
 
790
844
  // src/openapi/routes.ts
791
- var HTTP_METHODS = ["get", "put", "post", "delete", "patch"];
845
+ var HTTP_METHODS = [
846
+ "get",
847
+ "head",
848
+ "put",
849
+ "post",
850
+ "delete",
851
+ "patch"
852
+ ];
792
853
  function extractRoutes(document) {
793
854
  const routes = [];
794
855
  for (const [path, rawPathItem] of Object.entries(document.paths ?? {})) {
@@ -883,11 +944,12 @@ function resolveResponses(document, rawResponses) {
883
944
  // src/openapi/selection.ts
884
945
  var DEFAULT_MAX_OPERATIONS = 40;
885
946
  var METHOD_PRIORITY = {
886
- delete: 4,
947
+ delete: 5,
887
948
  get: 0,
888
- patch: 3,
889
- post: 1,
890
- put: 2
949
+ head: 1,
950
+ patch: 4,
951
+ post: 2,
952
+ put: 3
891
953
  };
892
954
  function selectRoutes(routes, options) {
893
955
  let selected = routes.filter((route) => !route.deprecated);