fastmcp 4.24.5 → 4.25.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.d.cts +2 -2
- package/dist/FastMCP.d.ts +2 -2
- package/dist/FastMCP.js +2 -2
- package/dist/{OAuthProvider-84BWWDBF.d.cts → OAuthProvider-CPC9zG96.d.cts} +16 -0
- package/dist/{OAuthProvider-84BWWDBF.d.ts → OAuthProvider-CPC9zG96.d.ts} +16 -0
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/bin/fastmcp.cjs +1 -0
- package/dist/bin/fastmcp.cjs.map +1 -1
- package/dist/bin/fastmcp.js +1 -0
- package/dist/bin/fastmcp.js.map +1 -1
- package/dist/{chunk-CAQLTSJ5.js → chunk-3VYVXSBB.js} +42 -7
- package/dist/chunk-3VYVXSBB.js.map +1 -0
- package/dist/{chunk-BV4PWTT6.cjs → chunk-AKHG27NY.cjs} +42 -7
- package/dist/chunk-AKHG27NY.cjs.map +1 -0
- package/dist/{chunk-UYV7MFKA.js → chunk-SQSE766U.js} +39 -15
- package/dist/chunk-SQSE766U.js.map +1 -0
- package/dist/{chunk-P56ABHAK.cjs → chunk-VWHJYU4V.cjs} +42 -18
- package/dist/chunk-VWHJYU4V.cjs.map +1 -0
- package/dist/edge/index.cjs +6 -6
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.js +6 -6
- package/dist/edge/index.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 +51 -34
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +8 -3
- package/dist/openapi/index.d.ts +8 -3
- package/dist/openapi/index.js +29 -12
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-BV4PWTT6.cjs.map +0 -1
- package/dist/chunk-CAQLTSJ5.js.map +0 -1
- package/dist/chunk-P56ABHAK.cjs.map +0 -1
- package/dist/chunk-UYV7MFKA.js.map +0 -1
package/dist/openapi/index.cjs
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
require('../chunk-
|
|
5
|
+
var _chunkVWHJYU4Vcjs = require('../chunk-VWHJYU4V.cjs');
|
|
6
|
+
require('../chunk-AKHG27NY.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
|
-
|
|
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',
|
|
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',
|
|
123
|
-
_optionalChain([successEntry, 'optionalAccess',
|
|
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',
|
|
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',
|
|
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',
|
|
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',
|
|
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',
|
|
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',
|
|
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,13 +482,18 @@ async function executeRequest(options) {
|
|
|
472
482
|
);
|
|
473
483
|
const pathParams = /* @__PURE__ */ Object.create(null);
|
|
474
484
|
const queryParts = [];
|
|
475
|
-
const headers = new 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];
|
|
479
491
|
if (!mapping || value === void 0) {
|
|
480
492
|
continue;
|
|
481
493
|
}
|
|
494
|
+
if (value === null && (mapping.in === "query" || mapping.in === "header" || mapping.in === "cookie")) {
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
482
497
|
switch (mapping.in) {
|
|
483
498
|
case "body":
|
|
484
499
|
bodyProps[mapping.name] = value;
|
|
@@ -523,7 +538,7 @@ async function executeRequest(options) {
|
|
|
523
538
|
const url = new URL(baseUrl.replace(/\/$/, "") + path);
|
|
524
539
|
url.search = queryParts.join("&");
|
|
525
540
|
let body;
|
|
526
|
-
const requiredJsonBody = options.bodyEncoding === "json" && _optionalChain([options, 'access',
|
|
541
|
+
const requiredJsonBody = options.bodyEncoding === "json" && _optionalChain([options, 'access', _19 => _19.route, 'access', _20 => _20.requestBody, 'optionalAccess', _21 => _21.required]) === true && !options.wholeBodyKey;
|
|
527
542
|
if (Object.keys(bodyProps).length > 0 || requiredJsonBody) {
|
|
528
543
|
const payload = options.wholeBodyKey ? bodyProps[options.wholeBodyKey] : bodyProps;
|
|
529
544
|
if (options.bodyEncoding === "form") {
|
|
@@ -546,12 +561,12 @@ async function executeRequest(options) {
|
|
|
546
561
|
});
|
|
547
562
|
const text = await response.text();
|
|
548
563
|
if (!response.ok) {
|
|
549
|
-
throw new (0,
|
|
564
|
+
throw new (0, _chunkVWHJYU4Vcjs.UserError)(
|
|
550
565
|
`${options.route.method.toUpperCase()} ${path} failed with ${response.status}: ${text.slice(0, 2e3)}`
|
|
551
566
|
);
|
|
552
567
|
}
|
|
553
|
-
const mediaType = _optionalChain([response, 'access',
|
|
554
|
-
if (_optionalChain([mediaType, 'optionalAccess',
|
|
568
|
+
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]]);
|
|
569
|
+
if (_optionalChain([mediaType, 'optionalAccess', _28 => _28.toLowerCase, 'call', _29 => _29(), 'access', _30 => _30.includes, 'call', _31 => _31("json")])) {
|
|
555
570
|
try {
|
|
556
571
|
const json = JSON.parse(text);
|
|
557
572
|
return { json, text: JSON.stringify(json, null, 2) };
|
|
@@ -565,7 +580,7 @@ function resolveBaseUrl(servers, origin, overrideUrl) {
|
|
|
565
580
|
if (overrideUrl) {
|
|
566
581
|
return overrideUrl.replace(/\/$/, "");
|
|
567
582
|
}
|
|
568
|
-
const server = _optionalChain([servers, 'optionalAccess',
|
|
583
|
+
const server = _optionalChain([servers, 'optionalAccess', _32 => _32[0]]);
|
|
569
584
|
if (!server) {
|
|
570
585
|
throw new Error(
|
|
571
586
|
"The OpenAPI document has no `servers` entry. Pass `baseUrl` to fromOpenAPI() explicitly."
|
|
@@ -648,7 +663,7 @@ function assertNoSubstitutedDotSegments(route, resolvedPath) {
|
|
|
648
663
|
const templateSegments = new Set(route.path.split("/"));
|
|
649
664
|
for (const segment of resolvedPath.split("/")) {
|
|
650
665
|
if ((segment === "." || segment === "..") && !templateSegments.has(segment)) {
|
|
651
|
-
throw new (0,
|
|
666
|
+
throw new (0, _chunkVWHJYU4Vcjs.UserError)(
|
|
652
667
|
`${route.method.toUpperCase()} ${route.path}: path parameter values must not produce a "${segment}" path segment.`
|
|
653
668
|
);
|
|
654
669
|
}
|
|
@@ -661,7 +676,7 @@ function encodeCookieValue(mapping, value) {
|
|
|
661
676
|
return encodePathComponent(text);
|
|
662
677
|
}
|
|
663
678
|
if (/[;,]/.test(text)) {
|
|
664
|
-
throw new (0,
|
|
679
|
+
throw new (0, _chunkVWHJYU4Vcjs.UserError)(
|
|
665
680
|
`Cookie parameter "${mapping.name}" uses style "cookie" and its value contains ";" or ","`
|
|
666
681
|
);
|
|
667
682
|
}
|
|
@@ -704,11 +719,11 @@ function encodePathValue(value, style, explode) {
|
|
|
704
719
|
}
|
|
705
720
|
return encodeURIComponent(String(value));
|
|
706
721
|
}
|
|
707
|
-
async function resolveHeaders(headers) {
|
|
722
|
+
async function resolveHeaders(headers, context) {
|
|
708
723
|
if (!headers) {
|
|
709
724
|
return {};
|
|
710
725
|
}
|
|
711
|
-
return typeof headers === "function" ? await headers() : { ...headers };
|
|
726
|
+
return typeof headers === "function" ? await headers(context) : { ...headers };
|
|
712
727
|
}
|
|
713
728
|
function serializeQuery(query, allowReserved) {
|
|
714
729
|
const encoded = query.toString();
|
|
@@ -785,7 +800,7 @@ function extractRoutes(document) {
|
|
|
785
800
|
requestBody: operation.requestBody ? resolveRef(document, operation.requestBody) : void 0,
|
|
786
801
|
responses: resolveResponses(document, operation.responses),
|
|
787
802
|
servers: [operation.servers, pathItem.servers, document.servers].find(
|
|
788
|
-
(servers) => _optionalChain([servers, 'optionalAccess',
|
|
803
|
+
(servers) => _optionalChain([servers, 'optionalAccess', _33 => _33.length])
|
|
789
804
|
),
|
|
790
805
|
summary: operation.summary,
|
|
791
806
|
tags: _nullishCoalesce(operation.tags, () => ( []))
|
|
@@ -836,7 +851,7 @@ function resolveRef(document, value) {
|
|
|
836
851
|
);
|
|
837
852
|
let node = document;
|
|
838
853
|
for (const segment of segments) {
|
|
839
|
-
node = _optionalChain([node, 'optionalAccess',
|
|
854
|
+
node = _optionalChain([node, 'optionalAccess', _34 => _34[segment]]);
|
|
840
855
|
}
|
|
841
856
|
return node;
|
|
842
857
|
}
|
|
@@ -905,8 +920,8 @@ async function fromOpenAPI(options) {
|
|
|
905
920
|
const selected = selectRoutes(routes, options);
|
|
906
921
|
const names = generateNames(selected, options.mcpNames);
|
|
907
922
|
const sharedDefs = buildSharedDefs(document);
|
|
908
|
-
const server = _nullishCoalesce(options.server, () => ( new (0,
|
|
909
|
-
name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access',
|
|
923
|
+
const server = _nullishCoalesce(options.server, () => ( new (0, _chunkVWHJYU4Vcjs.FastMCP)({
|
|
924
|
+
name: _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([document, 'access', _35 => _35.info, 'optionalAccess', _36 => _36.title]))), () => ( "OpenAPI Server")),
|
|
910
925
|
version: _nullishCoalesce(options.version, () => ( "1.0.0"))
|
|
911
926
|
})));
|
|
912
927
|
const skippedOperations = [];
|
|
@@ -951,21 +966,22 @@ async function fromOpenAPI(options) {
|
|
|
951
966
|
continue;
|
|
952
967
|
}
|
|
953
968
|
const outputSchemaJson = buildOutputSchema(route, sharedDefs);
|
|
954
|
-
const outputSchema = outputSchemaJson ?
|
|
969
|
+
const outputSchema = outputSchemaJson ? _chunkVWHJYU4Vcjs.jsonSchemaAdapter.call(void 0, outputSchemaJson) : void 0;
|
|
955
970
|
server.addTool({
|
|
956
971
|
description: _nullishCoalesce(route.summary, () => ( `${route.method.toUpperCase()} ${route.path}`)),
|
|
957
|
-
execute: async (args,
|
|
972
|
+
execute: async (args, context) => {
|
|
958
973
|
const result = await executeRequest({
|
|
959
974
|
...execOptions,
|
|
960
975
|
args,
|
|
961
976
|
bodyEncoding,
|
|
962
|
-
|
|
977
|
+
context,
|
|
978
|
+
signal: context.signal,
|
|
963
979
|
wholeBodyKey
|
|
964
980
|
});
|
|
965
981
|
return resolveToolResult(result, outputSchema);
|
|
966
982
|
},
|
|
967
983
|
name,
|
|
968
|
-
parameters:
|
|
984
|
+
parameters: _chunkVWHJYU4Vcjs.jsonSchemaAdapter.call(void 0, flatSchema),
|
|
969
985
|
...outputSchema ? { outputSchema } : {}
|
|
970
986
|
});
|
|
971
987
|
}
|
|
@@ -984,8 +1000,8 @@ function registerResource(server, route, name, parameterMap, requiredKeys, execO
|
|
|
984
1000
|
if (mapping.kind === "resource") {
|
|
985
1001
|
server.addResource({
|
|
986
1002
|
description,
|
|
987
|
-
load: async () => wrapAsResourceResult(
|
|
988
|
-
await executeRequest({ ...execOptions, args: {} })
|
|
1003
|
+
load: async (_auth, context) => wrapAsResourceResult(
|
|
1004
|
+
await executeRequest({ ...execOptions, args: {}, context })
|
|
989
1005
|
),
|
|
990
1006
|
name,
|
|
991
1007
|
uri: mapping.uri
|
|
@@ -995,10 +1011,11 @@ function registerResource(server, route, name, parameterMap, requiredKeys, execO
|
|
|
995
1011
|
server.addResourceTemplate({
|
|
996
1012
|
arguments: mapping.args,
|
|
997
1013
|
description,
|
|
998
|
-
load: async (args) => wrapAsResourceResult(
|
|
1014
|
+
load: async (args, _auth, context) => wrapAsResourceResult(
|
|
999
1015
|
await executeRequest({
|
|
1000
1016
|
...execOptions,
|
|
1001
|
-
args
|
|
1017
|
+
args,
|
|
1018
|
+
context
|
|
1002
1019
|
})
|
|
1003
1020
|
),
|
|
1004
1021
|
name,
|