fastmcp 4.29.0 → 4.29.2

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
- var _chunk5EEESM57cjs = require('../chunk-5EEESM57.cjs');
5
- require('../chunk-UHJQUSUX.cjs');
4
+ var _chunkTN6CWWVWcjs = require('../chunk-TN6CWWVW.cjs');
5
+ require('../chunk-XP4NENWX.cjs');
6
6
  require('../chunk-FBDPX4H2.cjs');
7
7
 
8
8
  // src/examples/custom-routes.ts
@@ -12,7 +12,7 @@ var users = /* @__PURE__ */ new Map([
12
12
  ["2", { email: "bob@example.com", id: "2", name: "Bob" }]
13
13
  ]);
14
14
  var requestCount = 0;
15
- var server = new (0, _chunk5EEESM57cjs.FastMCP)({
15
+ var server = new (0, _chunkTN6CWWVWcjs.FastMCP)({
16
16
  // Simple authentication - in production, use proper tokens/JWTs
17
17
  authenticate: async (req) => {
18
18
  const authHeader = req.headers.authorization;
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  FastMCP
4
- } from "../chunk-VN5SZ6IE.js";
5
- import "../chunk-RWPENEKV.js";
4
+ } from "../chunk-T7EFBHCA.js";
5
+ import "../chunk-PA3GWZUK.js";
6
6
  import "../chunk-JCKJRUCE.js";
7
7
 
8
8
  // src/examples/custom-routes.ts
@@ -2,8 +2,8 @@
2
2
 
3
3
 
4
4
 
5
- var _chunk5EEESM57cjs = require('../chunk-5EEESM57.cjs');
6
- require('../chunk-UHJQUSUX.cjs');
5
+ var _chunkTN6CWWVWcjs = require('../chunk-TN6CWWVW.cjs');
6
+ require('../chunk-XP4NENWX.cjs');
7
7
  require('../chunk-FBDPX4H2.cjs');
8
8
 
9
9
  // src/openapi/loadSpec.ts
@@ -65,11 +65,11 @@ function buildFlatSchema(route, sharedDefs) {
65
65
  for (const param of occurrences) {
66
66
  const base = collides ? `${name}__${param.in}` : name;
67
67
  const key = collides ? allocateAlias(base) : name;
68
- properties[key] = rewriteComponentRefs(
69
- _nullishCoalesce(param.schema, () => ( { type: "string" }))
70
- );
68
+ const input = parameterInput(param);
69
+ properties[key] = rewriteComponentRefs(input.schema);
71
70
  parameterMap[key] = {
72
71
  allowReserved: param.allowReserved,
72
+ ...input.encoding ? { encoding: input.encoding } : {},
73
73
  explode: param.explode,
74
74
  in: param.in,
75
75
  name,
@@ -352,6 +352,13 @@ function omitReadOnlyRequired(value, mode) {
352
352
  }
353
353
  return node;
354
354
  }
355
+ function parameterInput(param) {
356
+ const json = param.schema === void 0 ? findMediaType(param.content, "application/json") : void 0;
357
+ if (!json) {
358
+ return { schema: _nullishCoalesce(param.schema, () => ( { type: "string" })) };
359
+ }
360
+ return { encoding: "json", schema: _nullishCoalesce(json.schema, () => ( {})) };
361
+ }
355
362
  function rewriteNode(value, mode, stripExamples = false) {
356
363
  if (mode === "data") {
357
364
  return value;
@@ -625,7 +632,7 @@ function assertNoSubstitutedDotSegments(route, resolvedPath) {
625
632
  const templateSegments = new Set(route.path.split("/"));
626
633
  for (const segment of resolvedPath.split("/")) {
627
634
  if ((segment === "." || segment === "..") && !templateSegments.has(segment)) {
628
- throw new (0, _chunk5EEESM57cjs.UserError)(
635
+ throw new (0, _chunkTN6CWWVWcjs.UserError)(
629
636
  `${route.method.toUpperCase()} ${route.path}: path parameter values must not produce a "${segment}" path segment.`
630
637
  );
631
638
  }
@@ -638,7 +645,7 @@ function encodeCookieValue(mapping, value) {
638
645
  return encodePathComponent(text);
639
646
  }
640
647
  if (/[;,]/.test(text)) {
641
- throw new (0, _chunk5EEESM57cjs.UserError)(
648
+ throw new (0, _chunkTN6CWWVWcjs.UserError)(
642
649
  `Cookie parameter "${mapping.name}" uses style "cookie" and its value contains ";" or ","`
643
650
  );
644
651
  }
@@ -698,7 +705,7 @@ async function fetchResponse(options) {
698
705
  if (!mapping || value === void 0) {
699
706
  continue;
700
707
  }
701
- if (value === null && (mapping.in === "query" || mapping.in === "header" || mapping.in === "cookie")) {
708
+ if (value === null && mapping.encoding !== "json" && (mapping.in === "query" || mapping.in === "header" || mapping.in === "cookie")) {
702
709
  continue;
703
710
  }
704
711
  switch (mapping.in) {
@@ -706,7 +713,8 @@ async function fetchResponse(options) {
706
713
  bodyProps[mapping.name] = value;
707
714
  break;
708
715
  case "cookie": {
709
- const pair = `${mapping.name}=${encodeCookieValue(mapping, value)}`;
716
+ const encoded = mapping.encoding === "json" ? encodePathComponent(JSON.stringify(value)) : encodeCookieValue(mapping, value);
717
+ const pair = `${mapping.name}=${encoded}`;
710
718
  const existing = headers.get("cookie");
711
719
  headers.set("cookie", existing ? `${existing}; ${pair}` : pair);
712
720
  break;
@@ -714,18 +722,19 @@ async function fetchResponse(options) {
714
722
  case "header":
715
723
  headers.set(
716
724
  mapping.name,
717
- serializeHeaderValue(value, mapping.style, mapping.explode)
725
+ mapping.encoding === "json" ? JSON.stringify(value) : serializeHeaderValue(value, mapping.style, mapping.explode)
718
726
  );
719
727
  break;
720
728
  case "path":
721
- pathParams[mapping.name] = encodePathValue(
722
- value,
723
- mapping.style,
724
- mapping.explode
725
- );
729
+ pathParams[mapping.name] = mapping.encoding === "json" ? encodePathComponent(JSON.stringify(value)) : encodePathValue(value, mapping.style, mapping.explode);
726
730
  break;
727
731
  case "query": {
728
732
  const query = new URLSearchParams();
733
+ if (mapping.encoding === "json") {
734
+ query.append(mapping.name, JSON.stringify(value));
735
+ queryParts.push(serializeQuery(query, false));
736
+ break;
737
+ }
729
738
  appendQueryValue(
730
739
  query,
731
740
  mapping.name,
@@ -771,7 +780,7 @@ async function fetchResponse(options) {
771
780
  });
772
781
  if (!response.ok) {
773
782
  const text = await response.text();
774
- throw new (0, _chunk5EEESM57cjs.UserError)(
783
+ throw new (0, _chunkTN6CWWVWcjs.UserError)(
775
784
  `${options.route.method.toUpperCase()} ${path} failed with ${response.status}: ${text.slice(0, 2e3)}`
776
785
  );
777
786
  }
@@ -860,6 +869,9 @@ function isEligibleForResource(route, sharedDefs) {
860
869
  if (param.in === "header" || param.in === "cookie") {
861
870
  return false;
862
871
  }
872
+ if (param.content && param.schema === void 0) {
873
+ return false;
874
+ }
863
875
  return !hasStructuredType(_nullishCoalesce(param.schema, () => ( {})), sharedDefs);
864
876
  });
865
877
  }
@@ -1031,7 +1043,7 @@ async function fromOpenAPI(options) {
1031
1043
  const selected = selectRoutes(routes, options);
1032
1044
  const names = generateNames(selected, options.mcpNames);
1033
1045
  const sharedDefs = buildSharedDefs(document);
1034
- const server = _nullishCoalesce(options.server, () => ( new (0, _chunk5EEESM57cjs.FastMCP)({
1046
+ const server = _nullishCoalesce(options.server, () => ( new (0, _chunkTN6CWWVWcjs.FastMCP)({
1035
1047
  name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _45 => _45.info, 'optionalAccess', _46 => _46.title]))), () => ( "OpenAPI Server")),
1036
1048
  version: _nullishCoalesce(options.version, () => ( "1.0.0"))
1037
1049
  })));
@@ -1077,7 +1089,7 @@ async function fromOpenAPI(options) {
1077
1089
  continue;
1078
1090
  }
1079
1091
  const outputSchemaJson = buildOutputSchema(route, sharedDefs);
1080
- const outputSchema = outputSchemaJson ? _chunk5EEESM57cjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
1092
+ const outputSchema = outputSchemaJson ? _chunkTN6CWWVWcjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
1081
1093
  server.addTool({
1082
1094
  description: _nullishCoalesce(route.summary, () => ( `${route.method.toUpperCase()} ${route.path}`)),
1083
1095
  execute: async (args, context) => {
@@ -1092,7 +1104,7 @@ async function fromOpenAPI(options) {
1092
1104
  return resolveToolResult(result, outputSchema);
1093
1105
  },
1094
1106
  name,
1095
- parameters: _chunk5EEESM57cjs.jsonSchemaAdapter.call(void 0, flatSchema),
1107
+ parameters: _chunkTN6CWWVWcjs.jsonSchemaAdapter.call(void 0, flatSchema),
1096
1108
  ...outputSchema ? { outputSchema } : {}
1097
1109
  });
1098
1110
  }