fastmcp 4.22.0 → 4.22.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,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkV4JBWBT4cjs = require('../chunk-V4JBWBT4.cjs');
5
+ var _chunkRN2Z26T4cjs = require('../chunk-RN2Z26T4.cjs');
6
6
  require('../chunk-YOBCXNFP.cjs');
7
7
  require('../chunk-O22SYZMC.cjs');
8
8
 
@@ -129,7 +129,7 @@ async function executeRequest(options) {
129
129
  });
130
130
  const text = await response.text();
131
131
  if (!response.ok) {
132
- throw new (0, _chunkV4JBWBT4cjs.UserError)(
132
+ throw new (0, _chunkRN2Z26T4cjs.UserError)(
133
133
  `${options.route.method.toUpperCase()} ${path} failed with ${response.status}: ${text.slice(0, 2e3)}`
134
134
  );
135
135
  }
@@ -231,123 +231,6 @@ async function resolveHeaders(headers) {
231
231
  return typeof headers === "function" ? await headers() : { ...headers };
232
232
  }
233
233
 
234
- // src/openapi/resourceMapping.ts
235
- function buildResourceMapping(route, name, parameterMap, requiredKeys) {
236
- const entries = Object.entries(parameterMap);
237
- if (entries.length === 0) {
238
- return { kind: "resource", uri: `openapi://${name}${route.path}` };
239
- }
240
- const required = new Set(_nullishCoalesce(requiredKeys, () => ( [])));
241
- const args = [];
242
- const queryKeys = [];
243
- let path = route.path;
244
- for (const [flatKey, mapping] of entries) {
245
- if (mapping.in === "path") {
246
- if (flatKey !== mapping.name) {
247
- path = path.replaceAll(`{${mapping.name}}`, `{${flatKey}}`);
248
- }
249
- } else {
250
- queryKeys.push(flatKey);
251
- }
252
- args.push({ name: flatKey, required: required.has(flatKey) });
253
- }
254
- const uriTemplate = `openapi://${name}${path}` + (queryKeys.length > 0 ? `{?${queryKeys.join(",")}}` : "");
255
- return { args, kind: "template", uriTemplate };
256
- }
257
- function isEligibleForResource(route) {
258
- return route.parameters.every((param) => {
259
- if (param.in === "header" || param.in === "cookie") {
260
- return false;
261
- }
262
- return _optionalChain([param, 'access', _11 => _11.schema, 'optionalAccess', _12 => _12.type]) !== "array";
263
- });
264
- }
265
-
266
- // src/openapi/routes.ts
267
- var HTTP_METHODS = ["get", "put", "post", "delete", "patch"];
268
- function extractRoutes(document) {
269
- const routes = [];
270
- for (const [path, rawPathItem] of Object.entries(_nullishCoalesce(document.paths, () => ( {})))) {
271
- const pathItem = resolvePathItem(document, rawPathItem);
272
- const pathLevelParams = (_nullishCoalesce(pathItem.parameters, () => ( []))).map(
273
- (param) => resolveRef(document, param)
274
- );
275
- for (const method of HTTP_METHODS) {
276
- const operation = pathItem[method];
277
- if (!operation) {
278
- continue;
279
- }
280
- const operationParams = (_nullishCoalesce(operation.parameters, () => ( []))).map(
281
- (param) => resolveRef(document, param)
282
- );
283
- routes.push({
284
- deprecated: _nullishCoalesce(operation.deprecated, () => ( false)),
285
- method,
286
- operationId: operation.operationId,
287
- parameters: mergeParameters(pathLevelParams, operationParams),
288
- path,
289
- requestBody: operation.requestBody ? resolveRef(document, operation.requestBody) : void 0,
290
- responses: resolveResponses(document, operation.responses),
291
- servers: [operation.servers, pathItem.servers, document.servers].find(
292
- (servers) => _optionalChain([servers, 'optionalAccess', _13 => _13.length])
293
- ),
294
- summary: operation.summary,
295
- tags: _nullishCoalesce(operation.tags, () => ( []))
296
- });
297
- }
298
- }
299
- return routes;
300
- }
301
- function mergeParameters(pathLevel, operationLevel) {
302
- const overridden = new Set(
303
- operationLevel.map((param) => `${param.in}:${param.name}`)
304
- );
305
- return [
306
- ...pathLevel.filter(
307
- (param) => !overridden.has(`${param.in}:${param.name}`)
308
- ),
309
- ...operationLevel
310
- ];
311
- }
312
- function resolvePathItem(document, pathItem) {
313
- const visited = /* @__PURE__ */ new Set();
314
- let resolved = pathItem;
315
- while (resolved.$ref && !visited.has(resolved.$ref)) {
316
- visited.add(resolved.$ref);
317
- const { $ref, ...siblings } = resolved;
318
- resolved = { ...resolveRef(document, { $ref }), ...siblings };
319
- }
320
- return resolved;
321
- }
322
- function resolveRef(document, value) {
323
- if (!value || typeof value !== "object" || !("$ref" in value)) {
324
- return value;
325
- }
326
- const pointer = value.$ref;
327
- if (!pointer.startsWith("#/")) {
328
- throw new Error(`Unexpected external $ref after bundling: ${pointer}`);
329
- }
330
- const segments = pointer.slice(2).split("/").map(
331
- (segment) => decodeURIComponent(segment.replaceAll("~1", "/").replaceAll("~0", "~"))
332
- );
333
- let node = document;
334
- for (const segment of segments) {
335
- node = _optionalChain([node, 'optionalAccess', _14 => _14[segment]]);
336
- }
337
- return node;
338
- }
339
- function resolveResponses(document, rawResponses) {
340
- if (!rawResponses) {
341
- return void 0;
342
- }
343
- return Object.fromEntries(
344
- Object.entries(rawResponses).map(([code, response]) => [
345
- code,
346
- resolveRef(document, response)
347
- ])
348
- );
349
- }
350
-
351
234
  // src/openapi/schemas.ts
352
235
  var SCHEMA_MAP_KEYS = /* @__PURE__ */ new Set([
353
236
  "$defs",
@@ -421,7 +304,7 @@ function buildFlatSchema(route, sharedDefs) {
421
304
  };
422
305
  }
423
306
  function buildSharedDefs(document) {
424
- const schemas = _optionalChain([document, 'access', _15 => _15.components, 'optionalAccess', _16 => _16.schemas]);
307
+ const schemas = _optionalChain([document, 'access', _11 => _11.components, 'optionalAccess', _12 => _12.schemas]);
425
308
  if (!schemas || Object.keys(schemas).length === 0) {
426
309
  return void 0;
427
310
  }
@@ -433,7 +316,7 @@ function buildOutputSchema(route, sharedDefs) {
433
316
  const successEntry = Object.entries(_nullishCoalesce(route.responses, () => ( {}))).find(
434
317
  ([code]) => SUCCESS_STATUS_PATTERN.test(code)
435
318
  );
436
- const declaredSchema = _optionalChain([successEntry, 'optionalAccess', _17 => _17[1], 'access', _18 => _18.content, 'optionalAccess', _19 => _19["application/json"], 'optionalAccess', _20 => _20.schema]);
319
+ const declaredSchema = _optionalChain([successEntry, 'optionalAccess', _13 => _13[1], 'access', _14 => _14.content, 'optionalAccess', _15 => _15["application/json"], 'optionalAccess', _16 => _16.schema]);
437
320
  if (!declaredSchema) {
438
321
  return void 0;
439
322
  }
@@ -456,6 +339,22 @@ function buildOutputSchema(route, sharedDefs) {
456
339
  } : {}
457
340
  };
458
341
  }
342
+ function resolveComponentRef(schema, sharedDefs) {
343
+ const seen = /* @__PURE__ */ new Set();
344
+ let current = schema;
345
+ let ref = current.$ref;
346
+ while (typeof ref === "string") {
347
+ const name = componentSchemaName(ref);
348
+ const target = name === void 0 ? void 0 : _optionalChain([sharedDefs, 'optionalAccess', _17 => _17[name]]);
349
+ if (name === void 0 || target === void 0 || seen.has(name)) {
350
+ break;
351
+ }
352
+ seen.add(name);
353
+ current = target;
354
+ ref = current.$ref;
355
+ }
356
+ return current;
357
+ }
459
358
  function rewriteComponentRefs(value, stripExamples = false) {
460
359
  return rewriteNode(value, "schema", stripExamples);
461
360
  }
@@ -475,7 +374,7 @@ function componentSchemaName(ref) {
475
374
  }
476
375
  function extractBodyProperties(requestBody, sharedDefs) {
477
376
  const properties = /* @__PURE__ */ new Map();
478
- const content = _optionalChain([requestBody, 'optionalAccess', _21 => _21.content]);
377
+ const content = _optionalChain([requestBody, 'optionalAccess', _18 => _18.content]);
479
378
  if (!content) {
480
379
  return { properties };
481
380
  }
@@ -486,7 +385,7 @@ function extractBodyProperties(requestBody, sharedDefs) {
486
385
  return contentTypes.length > 0 ? { properties, unsupportedBodyContentType: contentTypes[0] } : { properties };
487
386
  }
488
387
  const bodyEncoding = hasJson ? "json" : "form";
489
- const declaredSchema = hasJson ? _optionalChain([content, 'access', _22 => _22["application/json"], 'optionalAccess', _23 => _23.schema]) : _optionalChain([content, 'access', _24 => _24["application/x-www-form-urlencoded"], 'optionalAccess', _25 => _25.schema]);
388
+ const declaredSchema = hasJson ? _optionalChain([content, 'access', _19 => _19["application/json"], 'optionalAccess', _20 => _20.schema]) : _optionalChain([content, 'access', _21 => _21["application/x-www-form-urlencoded"], 'optionalAccess', _22 => _22.schema]);
490
389
  if (!declaredSchema) {
491
390
  return { bodyEncoding, properties };
492
391
  }
@@ -511,7 +410,7 @@ function extractBodyProperties(requestBody, sharedDefs) {
511
410
  };
512
411
  }
513
412
  properties.set("body", {
514
- required: _nullishCoalesce(_optionalChain([requestBody, 'optionalAccess', _26 => _26.required]), () => ( false)),
413
+ required: _nullishCoalesce(_optionalChain([requestBody, 'optionalAccess', _23 => _23.required]), () => ( false)),
515
414
  schema
516
415
  });
517
416
  return { bodyEncoding, properties, wholeBodyKey: "body" };
@@ -584,22 +483,6 @@ function normalizeNullable(schema) {
584
483
  }
585
484
  return rest;
586
485
  }
587
- function resolveComponentRef(schema, sharedDefs) {
588
- const seen = /* @__PURE__ */ new Set();
589
- let current = schema;
590
- let ref = current.$ref;
591
- while (typeof ref === "string") {
592
- const name = componentSchemaName(ref);
593
- const target = name === void 0 ? void 0 : _optionalChain([sharedDefs, 'optionalAccess', _27 => _27[name]]);
594
- if (name === void 0 || target === void 0 || seen.has(name)) {
595
- break;
596
- }
597
- seen.add(name);
598
- current = target;
599
- ref = current.$ref;
600
- }
601
- return current;
602
- }
603
486
  function rewriteNode(value, mode, stripExamples = false) {
604
487
  if (mode === "data") {
605
488
  return value;
@@ -625,6 +508,124 @@ function rewriteNode(value, mode, stripExamples = false) {
625
508
  return mode === "schemaMap" ? rewritten : normalizeExclusiveBounds(normalizeNullable(rewritten));
626
509
  }
627
510
 
511
+ // src/openapi/resourceMapping.ts
512
+ function buildResourceMapping(route, name, parameterMap, requiredKeys) {
513
+ const entries = Object.entries(parameterMap);
514
+ if (entries.length === 0) {
515
+ return { kind: "resource", uri: `openapi://${name}${route.path}` };
516
+ }
517
+ const required = new Set(_nullishCoalesce(requiredKeys, () => ( [])));
518
+ const args = [];
519
+ const queryKeys = [];
520
+ let path = route.path;
521
+ for (const [flatKey, mapping] of entries) {
522
+ if (mapping.in === "path") {
523
+ if (flatKey !== mapping.name) {
524
+ path = path.replaceAll(`{${mapping.name}}`, `{${flatKey}}`);
525
+ }
526
+ } else {
527
+ queryKeys.push(flatKey);
528
+ }
529
+ args.push({ name: flatKey, required: required.has(flatKey) });
530
+ }
531
+ const uriTemplate = `openapi://${name}${path}` + (queryKeys.length > 0 ? `{?${queryKeys.join(",")}}` : "");
532
+ return { args, kind: "template", uriTemplate };
533
+ }
534
+ function isEligibleForResource(route, sharedDefs) {
535
+ return route.parameters.every((param) => {
536
+ if (param.in === "header" || param.in === "cookie") {
537
+ return false;
538
+ }
539
+ const type = resolveComponentRef(_nullishCoalesce(param.schema, () => ( {})), sharedDefs).type;
540
+ return type !== "array" && (!Array.isArray(type) || !type.includes("array"));
541
+ });
542
+ }
543
+
544
+ // src/openapi/routes.ts
545
+ var HTTP_METHODS = ["get", "put", "post", "delete", "patch"];
546
+ function extractRoutes(document) {
547
+ const routes = [];
548
+ for (const [path, rawPathItem] of Object.entries(_nullishCoalesce(document.paths, () => ( {})))) {
549
+ const pathItem = resolvePathItem(document, rawPathItem);
550
+ const pathLevelParams = (_nullishCoalesce(pathItem.parameters, () => ( []))).map(
551
+ (param) => resolveRef(document, param)
552
+ );
553
+ for (const method of HTTP_METHODS) {
554
+ const operation = pathItem[method];
555
+ if (!operation) {
556
+ continue;
557
+ }
558
+ const operationParams = (_nullishCoalesce(operation.parameters, () => ( []))).map(
559
+ (param) => resolveRef(document, param)
560
+ );
561
+ routes.push({
562
+ deprecated: _nullishCoalesce(operation.deprecated, () => ( false)),
563
+ method,
564
+ operationId: operation.operationId,
565
+ parameters: mergeParameters(pathLevelParams, operationParams),
566
+ path,
567
+ requestBody: operation.requestBody ? resolveRef(document, operation.requestBody) : void 0,
568
+ responses: resolveResponses(document, operation.responses),
569
+ servers: [operation.servers, pathItem.servers, document.servers].find(
570
+ (servers) => _optionalChain([servers, 'optionalAccess', _24 => _24.length])
571
+ ),
572
+ summary: operation.summary,
573
+ tags: _nullishCoalesce(operation.tags, () => ( []))
574
+ });
575
+ }
576
+ }
577
+ return routes;
578
+ }
579
+ function mergeParameters(pathLevel, operationLevel) {
580
+ const overridden = new Set(
581
+ operationLevel.map((param) => `${param.in}:${param.name}`)
582
+ );
583
+ return [
584
+ ...pathLevel.filter(
585
+ (param) => !overridden.has(`${param.in}:${param.name}`)
586
+ ),
587
+ ...operationLevel
588
+ ];
589
+ }
590
+ function resolvePathItem(document, pathItem) {
591
+ const visited = /* @__PURE__ */ new Set();
592
+ let resolved = pathItem;
593
+ while (resolved.$ref && !visited.has(resolved.$ref)) {
594
+ visited.add(resolved.$ref);
595
+ const { $ref, ...siblings } = resolved;
596
+ resolved = { ...resolveRef(document, { $ref }), ...siblings };
597
+ }
598
+ return resolved;
599
+ }
600
+ function resolveRef(document, value) {
601
+ if (!value || typeof value !== "object" || !("$ref" in value)) {
602
+ return value;
603
+ }
604
+ const pointer = value.$ref;
605
+ if (!pointer.startsWith("#/")) {
606
+ throw new Error(`Unexpected external $ref after bundling: ${pointer}`);
607
+ }
608
+ const segments = pointer.slice(2).split("/").map(
609
+ (segment) => decodeURIComponent(segment.replaceAll("~1", "/").replaceAll("~0", "~"))
610
+ );
611
+ let node = document;
612
+ for (const segment of segments) {
613
+ node = _optionalChain([node, 'optionalAccess', _25 => _25[segment]]);
614
+ }
615
+ return node;
616
+ }
617
+ function resolveResponses(document, rawResponses) {
618
+ if (!rawResponses) {
619
+ return void 0;
620
+ }
621
+ return Object.fromEntries(
622
+ Object.entries(rawResponses).map(([code, response]) => [
623
+ code,
624
+ resolveRef(document, response)
625
+ ])
626
+ );
627
+ }
628
+
628
629
  // src/openapi/selection.ts
629
630
  var DEFAULT_MAX_OPERATIONS = 40;
630
631
  var METHOD_PRIORITY = {
@@ -678,8 +679,8 @@ async function fromOpenAPI(options) {
678
679
  const selected = selectRoutes(routes, options);
679
680
  const names = generateNames(selected, options.mcpNames);
680
681
  const sharedDefs = buildSharedDefs(document);
681
- const server = _nullishCoalesce(options.server, () => ( new (0, _chunkV4JBWBT4cjs.FastMCP)({
682
- name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _28 => _28.info, 'optionalAccess', _29 => _29.title]))), () => ( "OpenAPI Server")),
682
+ const server = _nullishCoalesce(options.server, () => ( new (0, _chunkRN2Z26T4cjs.FastMCP)({
683
+ name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _26 => _26.info, 'optionalAccess', _27 => _27.title]))), () => ( "OpenAPI Server")),
683
684
  version: _nullishCoalesce(options.version, () => ( "1.0.0"))
684
685
  })));
685
686
  const skippedOperations = [];
@@ -704,7 +705,7 @@ async function fromOpenAPI(options) {
704
705
  route,
705
706
  servers: route.servers
706
707
  };
707
- if (options.resources && route.method === "get" && isEligibleForResource(route)) {
708
+ if (options.resources && route.method === "get" && isEligibleForResource(route, sharedDefs)) {
708
709
  registerResource(
709
710
  server,
710
711
  route,
@@ -724,7 +725,7 @@ async function fromOpenAPI(options) {
724
725
  continue;
725
726
  }
726
727
  const outputSchemaJson = buildOutputSchema(route, sharedDefs);
727
- const outputSchema = outputSchemaJson ? _chunkV4JBWBT4cjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
728
+ const outputSchema = outputSchemaJson ? _chunkRN2Z26T4cjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
728
729
  server.addTool({
729
730
  description: _nullishCoalesce(route.summary, () => ( `${route.method.toUpperCase()} ${route.path}`)),
730
731
  execute: async (args) => {
@@ -737,7 +738,7 @@ async function fromOpenAPI(options) {
737
738
  return resolveToolResult(result, outputSchema);
738
739
  },
739
740
  name,
740
- parameters: _chunkV4JBWBT4cjs.jsonSchemaAdapter.call(void 0, flatSchema),
741
+ parameters: _chunkRN2Z26T4cjs.jsonSchemaAdapter.call(void 0, flatSchema),
741
742
  ...outputSchema ? { outputSchema } : {}
742
743
  });
743
744
  }