fastmcp 4.24.5 → 4.25.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 (37) hide show
  1. package/dist/FastMCP.cjs +3 -3
  2. package/dist/FastMCP.d.cts +2 -2
  3. package/dist/FastMCP.d.ts +2 -2
  4. package/dist/FastMCP.js +2 -2
  5. package/dist/{OAuthProvider-84BWWDBF.d.cts → OAuthProvider-BGtNEdC3.d.cts} +14 -0
  6. package/dist/{OAuthProvider-84BWWDBF.d.ts → OAuthProvider-BGtNEdC3.d.ts} +14 -0
  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/bin/fastmcp.cjs +1 -0
  12. package/dist/bin/fastmcp.cjs.map +1 -1
  13. package/dist/bin/fastmcp.js +1 -0
  14. package/dist/bin/fastmcp.js.map +1 -1
  15. package/dist/{chunk-P56ABHAK.cjs → chunk-AJE7ERFM.cjs} +5 -5
  16. package/dist/{chunk-P56ABHAK.cjs.map → chunk-AJE7ERFM.cjs.map} +1 -1
  17. package/dist/{chunk-BV4PWTT6.cjs → chunk-B7IXBMHV.cjs} +32 -1
  18. package/dist/chunk-B7IXBMHV.cjs.map +1 -0
  19. package/dist/{chunk-CAQLTSJ5.js → chunk-JFHOYU3S.js} +32 -1
  20. package/dist/chunk-JFHOYU3S.js.map +1 -0
  21. package/dist/{chunk-UYV7MFKA.js → chunk-PU3JOW7T.js} +2 -2
  22. package/dist/edge/index.cjs +6 -6
  23. package/dist/edge/index.cjs.map +1 -1
  24. package/dist/edge/index.js +6 -6
  25. package/dist/edge/index.js.map +1 -1
  26. package/dist/examples/custom-routes.cjs +3 -3
  27. package/dist/examples/custom-routes.js +2 -2
  28. package/dist/openapi/index.cjs +48 -34
  29. package/dist/openapi/index.cjs.map +1 -1
  30. package/dist/openapi/index.d.cts +8 -3
  31. package/dist/openapi/index.d.ts +8 -3
  32. package/dist/openapi/index.js +26 -12
  33. package/dist/openapi/index.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/chunk-BV4PWTT6.cjs.map +0 -1
  36. package/dist/chunk-CAQLTSJ5.js.map +0 -1
  37. /package/dist/{chunk-UYV7MFKA.js.map → chunk-PU3JOW7T.js.map} +0 -0
@@ -2,8 +2,8 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkP56ABHAKcjs = require('../chunk-P56ABHAK.cjs');
6
- require('../chunk-BV4PWTT6.cjs');
5
+ var _chunkAJE7ERFMcjs = require('../chunk-AJE7ERFM.cjs');
6
+ require('../chunk-B7IXBMHV.cjs');
7
7
  require('../chunk-6TDYSPLC.cjs');
8
8
 
9
9
  // src/openapi/loadSpec.ts
@@ -80,20 +80,30 @@ function buildFlatSchema(route, sharedDefs) {
80
80
  }
81
81
  }
82
82
  }
83
+ const bodyKeys = [];
84
+ const requiredBodyKeys = [];
83
85
  for (const [name, { required: isRequired, schema }] of bodyProperties) {
84
86
  const key = name === "__proto__" ? allocateAlias(`${name}__body`) : name;
85
87
  properties[key] = rewriteComponentRefs(schema);
86
88
  parameterMap[key] = { in: "body", name };
89
+ bodyKeys.push(key);
87
90
  if (isRequired) {
88
- required.push(key);
91
+ requiredBodyKeys.push(key);
89
92
  }
90
93
  }
94
+ if (_optionalChain([route, 'access', _ => _.requestBody, 'optionalAccess', _2 => _2.required])) {
95
+ required.push(...requiredBodyKeys);
96
+ }
91
97
  const flatSchema = {
92
98
  additionalProperties: false,
93
99
  properties,
94
100
  type: "object",
95
101
  ...required.length > 0 ? { required } : {}
96
102
  };
103
+ if (!_optionalChain([route, 'access', _3 => _3.requestBody, 'optionalAccess', _4 => _4.required]) && requiredBodyKeys.length > 0) {
104
+ flatSchema.if = { anyOf: bodyKeys.map((key) => ({ required: [key] })) };
105
+ flatSchema.then = { required: requiredBodyKeys };
106
+ }
97
107
  const usedDefs = sharedDefs && filterReferencedDefs(properties, sharedDefs);
98
108
  if (usedDefs) {
99
109
  flatSchema.$defs = usedDefs;
@@ -107,7 +117,7 @@ function buildFlatSchema(route, sharedDefs) {
107
117
  };
108
118
  }
109
119
  function buildSharedDefs(document) {
110
- const schemas = _optionalChain([document, 'access', _ => _.components, 'optionalAccess', _2 => _2.schemas]);
120
+ const schemas = _optionalChain([document, 'access', _5 => _5.components, 'optionalAccess', _6 => _6.schemas]);
111
121
  if (!schemas || Object.keys(schemas).length === 0) {
112
122
  return void 0;
113
123
  }
@@ -119,10 +129,10 @@ function buildOutputSchema(route, sharedDefs) {
119
129
  const successEntry = Object.entries(_nullishCoalesce(route.responses, () => ( {}))).find(
120
130
  ([code]) => SUCCESS_STATUS_PATTERN.test(code)
121
131
  );
122
- const declaredSchema = _optionalChain([findMediaType, 'call', _3 => _3(
123
- _optionalChain([successEntry, 'optionalAccess', _4 => _4[1], 'access', _5 => _5.content]),
132
+ const declaredSchema = _optionalChain([findMediaType, 'call', _7 => _7(
133
+ _optionalChain([successEntry, 'optionalAccess', _8 => _8[1], 'access', _9 => _9.content]),
124
134
  "application/json"
125
- ), 'optionalAccess', _6 => _6.schema]);
135
+ ), 'optionalAccess', _10 => _10.schema]);
126
136
  if (!declaredSchema) {
127
137
  return void 0;
128
138
  }
@@ -151,7 +161,7 @@ function resolveComponentRef(schema, sharedDefs) {
151
161
  let ref = current.$ref;
152
162
  while (typeof ref === "string") {
153
163
  const name = componentSchemaName(ref);
154
- const target = name === void 0 ? void 0 : _optionalChain([sharedDefs, 'optionalAccess', _7 => _7[name]]);
164
+ const target = name === void 0 ? void 0 : _optionalChain([sharedDefs, 'optionalAccess', _11 => _11[name]]);
155
165
  if (name === void 0 || target === void 0 || seen.has(name)) {
156
166
  break;
157
167
  }
@@ -180,7 +190,7 @@ function componentSchemaName(ref) {
180
190
  }
181
191
  function extractBodyProperties(requestBody, sharedDefs) {
182
192
  const properties = /* @__PURE__ */ new Map();
183
- const content = _optionalChain([requestBody, 'optionalAccess', _8 => _8.content]);
193
+ const content = _optionalChain([requestBody, 'optionalAccess', _12 => _12.content]);
184
194
  if (!content) {
185
195
  return { properties };
186
196
  }
@@ -191,7 +201,7 @@ function extractBodyProperties(requestBody, sharedDefs) {
191
201
  return contentTypes.length > 0 ? { properties, unsupportedBodyContentType: contentTypes[0] } : { properties };
192
202
  }
193
203
  const bodyEncoding = json === void 0 ? "form" : "json";
194
- const declaredSchema = bodyEncoding === "json" ? _optionalChain([json, 'optionalAccess', _9 => _9.schema]) : _optionalChain([form, 'optionalAccess', _10 => _10.schema]);
204
+ const declaredSchema = bodyEncoding === "json" ? _optionalChain([json, 'optionalAccess', _13 => _13.schema]) : _optionalChain([form, 'optionalAccess', _14 => _14.schema]);
195
205
  if (!declaredSchema) {
196
206
  return { bodyEncoding, properties };
197
207
  }
@@ -216,7 +226,7 @@ function extractBodyProperties(requestBody, sharedDefs) {
216
226
  };
217
227
  }
218
228
  properties.set("body", {
219
- required: _nullishCoalesce(_optionalChain([requestBody, 'optionalAccess', _11 => _11.required]), () => ( false)),
229
+ required: _nullishCoalesce(_optionalChain([requestBody, 'optionalAccess', _15 => _15.required]), () => ( false)),
220
230
  schema
221
231
  });
222
232
  return { bodyEncoding, properties, wholeBodyKey: "body" };
@@ -329,7 +339,7 @@ async function loadSpec(spec) {
329
339
  const document = await _swaggerparser2.default.bundle(
330
340
  spec
331
341
  );
332
- if (!_optionalChain([document, 'access', _12 => _12.openapi, 'optionalAccess', _13 => _13.startsWith, 'call', _14 => _14("3.")])) {
342
+ if (!_optionalChain([document, 'access', _16 => _16.openapi, 'optionalAccess', _17 => _17.startsWith, 'call', _18 => _18("3.")])) {
333
343
  throw new Error(
334
344
  `fromOpenAPI only supports OpenAPI 3.x documents (found ${_nullishCoalesce(_nullishCoalesce(document.openapi, () => ( document.swagger)), () => ( "an unrecognized version"))}). Swagger 2.0 is not supported.`
335
345
  );
@@ -472,7 +482,9 @@ async function executeRequest(options) {
472
482
  );
473
483
  const pathParams = /* @__PURE__ */ Object.create(null);
474
484
  const queryParts = [];
475
- const headers = new Headers(await resolveHeaders(options.headers));
485
+ const headers = new Headers(
486
+ await resolveHeaders(options.headers, options.context)
487
+ );
476
488
  const bodyProps = /* @__PURE__ */ Object.create(null);
477
489
  for (const [key, value] of Object.entries(options.args)) {
478
490
  const mapping = options.parameterMap[key];
@@ -523,7 +535,7 @@ async function executeRequest(options) {
523
535
  const url = new URL(baseUrl.replace(/\/$/, "") + path);
524
536
  url.search = queryParts.join("&");
525
537
  let body;
526
- const requiredJsonBody = options.bodyEncoding === "json" && _optionalChain([options, 'access', _15 => _15.route, 'access', _16 => _16.requestBody, 'optionalAccess', _17 => _17.required]) === true && !options.wholeBodyKey;
538
+ const requiredJsonBody = options.bodyEncoding === "json" && _optionalChain([options, 'access', _19 => _19.route, 'access', _20 => _20.requestBody, 'optionalAccess', _21 => _21.required]) === true && !options.wholeBodyKey;
527
539
  if (Object.keys(bodyProps).length > 0 || requiredJsonBody) {
528
540
  const payload = options.wholeBodyKey ? bodyProps[options.wholeBodyKey] : bodyProps;
529
541
  if (options.bodyEncoding === "form") {
@@ -546,12 +558,12 @@ async function executeRequest(options) {
546
558
  });
547
559
  const text = await response.text();
548
560
  if (!response.ok) {
549
- throw new (0, _chunkP56ABHAKcjs.UserError)(
561
+ throw new (0, _chunkAJE7ERFMcjs.UserError)(
550
562
  `${options.route.method.toUpperCase()} ${path} failed with ${response.status}: ${text.slice(0, 2e3)}`
551
563
  );
552
564
  }
553
- const mediaType = _optionalChain([response, 'access', _18 => _18.headers, 'access', _19 => _19.get, 'call', _20 => _20("content-type"), 'optionalAccess', _21 => _21.split, 'call', _22 => _22(";"), 'access', _23 => _23[0]]);
554
- if (_optionalChain([mediaType, 'optionalAccess', _24 => _24.toLowerCase, 'call', _25 => _25(), 'access', _26 => _26.includes, 'call', _27 => _27("json")])) {
565
+ const mediaType = _optionalChain([response, 'access', _22 => _22.headers, 'access', _23 => _23.get, 'call', _24 => _24("content-type"), 'optionalAccess', _25 => _25.split, 'call', _26 => _26(";"), 'access', _27 => _27[0]]);
566
+ if (_optionalChain([mediaType, 'optionalAccess', _28 => _28.toLowerCase, 'call', _29 => _29(), 'access', _30 => _30.includes, 'call', _31 => _31("json")])) {
555
567
  try {
556
568
  const json = JSON.parse(text);
557
569
  return { json, text: JSON.stringify(json, null, 2) };
@@ -565,7 +577,7 @@ function resolveBaseUrl(servers, origin, overrideUrl) {
565
577
  if (overrideUrl) {
566
578
  return overrideUrl.replace(/\/$/, "");
567
579
  }
568
- const server = _optionalChain([servers, 'optionalAccess', _28 => _28[0]]);
580
+ const server = _optionalChain([servers, 'optionalAccess', _32 => _32[0]]);
569
581
  if (!server) {
570
582
  throw new Error(
571
583
  "The OpenAPI document has no `servers` entry. Pass `baseUrl` to fromOpenAPI() explicitly."
@@ -648,7 +660,7 @@ function assertNoSubstitutedDotSegments(route, resolvedPath) {
648
660
  const templateSegments = new Set(route.path.split("/"));
649
661
  for (const segment of resolvedPath.split("/")) {
650
662
  if ((segment === "." || segment === "..") && !templateSegments.has(segment)) {
651
- throw new (0, _chunkP56ABHAKcjs.UserError)(
663
+ throw new (0, _chunkAJE7ERFMcjs.UserError)(
652
664
  `${route.method.toUpperCase()} ${route.path}: path parameter values must not produce a "${segment}" path segment.`
653
665
  );
654
666
  }
@@ -661,7 +673,7 @@ function encodeCookieValue(mapping, value) {
661
673
  return encodePathComponent(text);
662
674
  }
663
675
  if (/[;,]/.test(text)) {
664
- throw new (0, _chunkP56ABHAKcjs.UserError)(
676
+ throw new (0, _chunkAJE7ERFMcjs.UserError)(
665
677
  `Cookie parameter "${mapping.name}" uses style "cookie" and its value contains ";" or ","`
666
678
  );
667
679
  }
@@ -704,11 +716,11 @@ function encodePathValue(value, style, explode) {
704
716
  }
705
717
  return encodeURIComponent(String(value));
706
718
  }
707
- async function resolveHeaders(headers) {
719
+ async function resolveHeaders(headers, context) {
708
720
  if (!headers) {
709
721
  return {};
710
722
  }
711
- return typeof headers === "function" ? await headers() : { ...headers };
723
+ return typeof headers === "function" ? await headers(context) : { ...headers };
712
724
  }
713
725
  function serializeQuery(query, allowReserved) {
714
726
  const encoded = query.toString();
@@ -785,7 +797,7 @@ function extractRoutes(document) {
785
797
  requestBody: operation.requestBody ? resolveRef(document, operation.requestBody) : void 0,
786
798
  responses: resolveResponses(document, operation.responses),
787
799
  servers: [operation.servers, pathItem.servers, document.servers].find(
788
- (servers) => _optionalChain([servers, 'optionalAccess', _29 => _29.length])
800
+ (servers) => _optionalChain([servers, 'optionalAccess', _33 => _33.length])
789
801
  ),
790
802
  summary: operation.summary,
791
803
  tags: _nullishCoalesce(operation.tags, () => ( []))
@@ -836,7 +848,7 @@ function resolveRef(document, value) {
836
848
  );
837
849
  let node = document;
838
850
  for (const segment of segments) {
839
- node = _optionalChain([node, 'optionalAccess', _30 => _30[segment]]);
851
+ node = _optionalChain([node, 'optionalAccess', _34 => _34[segment]]);
840
852
  }
841
853
  return node;
842
854
  }
@@ -905,8 +917,8 @@ async function fromOpenAPI(options) {
905
917
  const selected = selectRoutes(routes, options);
906
918
  const names = generateNames(selected, options.mcpNames);
907
919
  const sharedDefs = buildSharedDefs(document);
908
- const server = _nullishCoalesce(options.server, () => ( new (0, _chunkP56ABHAKcjs.FastMCP)({
909
- name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _31 => _31.info, 'optionalAccess', _32 => _32.title]))), () => ( "OpenAPI Server")),
920
+ const server = _nullishCoalesce(options.server, () => ( new (0, _chunkAJE7ERFMcjs.FastMCP)({
921
+ name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _35 => _35.info, 'optionalAccess', _36 => _36.title]))), () => ( "OpenAPI Server")),
910
922
  version: _nullishCoalesce(options.version, () => ( "1.0.0"))
911
923
  })));
912
924
  const skippedOperations = [];
@@ -951,21 +963,22 @@ async function fromOpenAPI(options) {
951
963
  continue;
952
964
  }
953
965
  const outputSchemaJson = buildOutputSchema(route, sharedDefs);
954
- const outputSchema = outputSchemaJson ? _chunkP56ABHAKcjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
966
+ const outputSchema = outputSchemaJson ? _chunkAJE7ERFMcjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
955
967
  server.addTool({
956
968
  description: _nullishCoalesce(route.summary, () => ( `${route.method.toUpperCase()} ${route.path}`)),
957
- execute: async (args, { signal }) => {
969
+ execute: async (args, context) => {
958
970
  const result = await executeRequest({
959
971
  ...execOptions,
960
972
  args,
961
973
  bodyEncoding,
962
- signal,
974
+ context,
975
+ signal: context.signal,
963
976
  wholeBodyKey
964
977
  });
965
978
  return resolveToolResult(result, outputSchema);
966
979
  },
967
980
  name,
968
- parameters: _chunkP56ABHAKcjs.jsonSchemaAdapter.call(void 0, flatSchema),
981
+ parameters: _chunkAJE7ERFMcjs.jsonSchemaAdapter.call(void 0, flatSchema),
969
982
  ...outputSchema ? { outputSchema } : {}
970
983
  });
971
984
  }
@@ -984,8 +997,8 @@ function registerResource(server, route, name, parameterMap, requiredKeys, execO
984
997
  if (mapping.kind === "resource") {
985
998
  server.addResource({
986
999
  description,
987
- load: async () => wrapAsResourceResult(
988
- await executeRequest({ ...execOptions, args: {} })
1000
+ load: async (_auth, context) => wrapAsResourceResult(
1001
+ await executeRequest({ ...execOptions, args: {}, context })
989
1002
  ),
990
1003
  name,
991
1004
  uri: mapping.uri
@@ -995,10 +1008,11 @@ function registerResource(server, route, name, parameterMap, requiredKeys, execO
995
1008
  server.addResourceTemplate({
996
1009
  arguments: mapping.args,
997
1010
  description,
998
- load: async (args) => wrapAsResourceResult(
1011
+ load: async (args, _auth, context) => wrapAsResourceResult(
999
1012
  await executeRequest({
1000
1013
  ...execOptions,
1001
- args
1014
+ args,
1015
+ context
1002
1016
  })
1003
1017
  ),
1004
1018
  name,