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.
- package/dist/FastMCP.cjs +3 -3
- package/dist/FastMCP.js +2 -2
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +22 -1
- package/dist/auth/index.d.ts +22 -1
- package/dist/auth/index.js +1 -1
- package/dist/{chunk-TN6CWWVW.cjs → chunk-4JEDH2ON.cjs} +5 -5
- package/dist/{chunk-TN6CWWVW.cjs.map → chunk-4JEDH2ON.cjs.map} +1 -1
- package/dist/{chunk-T7EFBHCA.js → chunk-5KA6SOWT.js} +2 -2
- package/dist/{chunk-XP4NENWX.cjs → chunk-CZGQ2WTQ.cjs} +81 -30
- package/dist/chunk-CZGQ2WTQ.cjs.map +1 -0
- package/dist/{chunk-PA3GWZUK.js → chunk-XPTUOWUT.js} +82 -31
- package/dist/{chunk-PA3GWZUK.js.map → chunk-XPTUOWUT.js.map} +1 -1
- package/dist/examples/custom-routes.cjs +3 -3
- package/dist/examples/custom-routes.js +2 -2
- package/dist/openapi/index.cjs +91 -22
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +2 -0
- package/dist/openapi/index.d.ts +2 -0
- package/dist/openapi/index.js +85 -16
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-XP4NENWX.cjs.map +0 -1
- /package/dist/{chunk-T7EFBHCA.js.map → chunk-5KA6SOWT.js.map} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
4
|
+
var _chunk4JEDH2ONcjs = require('../chunk-4JEDH2ON.cjs');
|
|
5
|
+
require('../chunk-CZGQ2WTQ.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,
|
|
15
|
+
var server = new (0, _chunk4JEDH2ONcjs.FastMCP)({
|
|
16
16
|
// Simple authentication - in production, use proper tokens/JWTs
|
|
17
17
|
authenticate: async (req) => {
|
|
18
18
|
const authHeader = req.headers.authorization;
|
package/dist/openapi/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunk4JEDH2ONcjs = require('../chunk-4JEDH2ON.cjs');
|
|
6
|
+
require('../chunk-CZGQ2WTQ.cjs');
|
|
7
7
|
require('../chunk-FBDPX4H2.cjs');
|
|
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] =
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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
|
|
345
|
-
(name) => !(typeof name === "string" && Object.hasOwn(properties, name) && _optionalChain([properties, 'access', _14 => _14[name], 'optionalAccess', _15 => _15
|
|
357
|
+
const remaining = required.filter(
|
|
358
|
+
(name) => !(typeof name === "string" && Object.hasOwn(properties, name) && _optionalChain([properties, 'access', _14 => _14[name], 'optionalAccess', _15 => _15[annotation]]) === true)
|
|
346
359
|
);
|
|
347
|
-
if (
|
|
348
|
-
node.required =
|
|
360
|
+
if (remaining.length > 0) {
|
|
361
|
+
node.required = remaining;
|
|
349
362
|
} else {
|
|
350
363
|
delete node.required;
|
|
351
364
|
}
|
|
@@ -632,7 +645,7 @@ function assertNoSubstitutedDotSegments(route, resolvedPath) {
|
|
|
632
645
|
const templateSegments = new Set(route.path.split("/"));
|
|
633
646
|
for (const segment of resolvedPath.split("/")) {
|
|
634
647
|
if ((segment === "." || segment === "..") && !templateSegments.has(segment)) {
|
|
635
|
-
throw new (0,
|
|
648
|
+
throw new (0, _chunk4JEDH2ONcjs.UserError)(
|
|
636
649
|
`${route.method.toUpperCase()} ${route.path}: path parameter values must not produce a "${segment}" path segment.`
|
|
637
650
|
);
|
|
638
651
|
}
|
|
@@ -645,7 +658,7 @@ function encodeCookieValue(mapping, value) {
|
|
|
645
658
|
return encodePathComponent(text);
|
|
646
659
|
}
|
|
647
660
|
if (/[;,]/.test(text)) {
|
|
648
|
-
throw new (0,
|
|
661
|
+
throw new (0, _chunk4JEDH2ONcjs.UserError)(
|
|
649
662
|
`Cookie parameter "${mapping.name}" uses style "cookie" and its value contains ";" or ","`
|
|
650
663
|
);
|
|
651
664
|
}
|
|
@@ -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(
|
|
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();
|
|
@@ -780,7 +849,7 @@ async function fetchResponse(options) {
|
|
|
780
849
|
});
|
|
781
850
|
if (!response.ok) {
|
|
782
851
|
const text = await response.text();
|
|
783
|
-
throw new (0,
|
|
852
|
+
throw new (0, _chunk4JEDH2ONcjs.UserError)(
|
|
784
853
|
`${options.route.method.toUpperCase()} ${path} failed with ${response.status}: ${text.slice(0, 2e3)}`
|
|
785
854
|
);
|
|
786
855
|
}
|
|
@@ -1043,7 +1112,7 @@ async function fromOpenAPI(options) {
|
|
|
1043
1112
|
const selected = selectRoutes(routes, options);
|
|
1044
1113
|
const names = generateNames(selected, options.mcpNames);
|
|
1045
1114
|
const sharedDefs = buildSharedDefs(document);
|
|
1046
|
-
const server = _nullishCoalesce(options.server, () => ( new (0,
|
|
1115
|
+
const server = _nullishCoalesce(options.server, () => ( new (0, _chunk4JEDH2ONcjs.FastMCP)({
|
|
1047
1116
|
name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _45 => _45.info, 'optionalAccess', _46 => _46.title]))), () => ( "OpenAPI Server")),
|
|
1048
1117
|
version: _nullishCoalesce(options.version, () => ( "1.0.0"))
|
|
1049
1118
|
})));
|
|
@@ -1089,7 +1158,7 @@ async function fromOpenAPI(options) {
|
|
|
1089
1158
|
continue;
|
|
1090
1159
|
}
|
|
1091
1160
|
const outputSchemaJson = buildOutputSchema(route, sharedDefs);
|
|
1092
|
-
const outputSchema = outputSchemaJson ?
|
|
1161
|
+
const outputSchema = outputSchemaJson ? _chunk4JEDH2ONcjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
|
|
1093
1162
|
server.addTool({
|
|
1094
1163
|
description: _nullishCoalesce(route.summary, () => ( `${route.method.toUpperCase()} ${route.path}`)),
|
|
1095
1164
|
execute: async (args, context) => {
|
|
@@ -1104,7 +1173,7 @@ async function fromOpenAPI(options) {
|
|
|
1104
1173
|
return resolveToolResult(result, outputSchema);
|
|
1105
1174
|
},
|
|
1106
1175
|
name,
|
|
1107
|
-
parameters:
|
|
1176
|
+
parameters: _chunk4JEDH2ONcjs.jsonSchemaAdapter.call(void 0, flatSchema),
|
|
1108
1177
|
...outputSchema ? { outputSchema } : {}
|
|
1109
1178
|
});
|
|
1110
1179
|
}
|