fastmcp 4.21.2 → 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.
- package/README.md +12 -2
- 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-C4idKF29.d.cts → OAuthProvider-BcDb5bOz.d.cts} +8 -1
- package/dist/{OAuthProvider-C4idKF29.d.ts → OAuthProvider-BcDb5bOz.d.ts} +8 -1
- 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/{chunk-C5VOVQPC.cjs → chunk-RN2Z26T4.cjs} +118 -16
- package/dist/chunk-RN2Z26T4.cjs.map +1 -0
- package/dist/{chunk-QMRS4ZLD.js → chunk-XFUILY54.js} +115 -13
- package/dist/chunk-XFUILY54.js.map +1 -0
- package/dist/{chunk-AR3LVWUF.js → chunk-XPKMA7DH.js} +22 -1
- package/dist/chunk-XPKMA7DH.js.map +1 -0
- package/dist/{chunk-GTPK7A57.cjs → chunk-YOBCXNFP.cjs} +22 -1
- package/dist/chunk-YOBCXNFP.cjs.map +1 -0
- package/dist/edge/index.cjs +15 -12
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.js +7 -4
- 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 +165 -149
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +5 -3
- package/dist/openapi/index.d.ts +5 -3
- package/dist/openapi/index.js +155 -139
- package/dist/openapi/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-AR3LVWUF.js.map +0 -1
- package/dist/chunk-C5VOVQPC.cjs.map +0 -1
- package/dist/chunk-GTPK7A57.cjs.map +0 -1
- package/dist/chunk-QMRS4ZLD.js.map +0 -1
package/dist/openapi/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
FastMCP,
|
|
3
3
|
UserError,
|
|
4
4
|
jsonSchemaAdapter
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-XFUILY54.js";
|
|
6
|
+
import "../chunk-XPKMA7DH.js";
|
|
7
7
|
import "../chunk-UMDUIBFW.js";
|
|
8
8
|
|
|
9
9
|
// src/openapi/loadSpec.ts
|
|
@@ -91,7 +91,13 @@ async function executeRequest(options) {
|
|
|
91
91
|
pathParams[mapping.name] = String(value);
|
|
92
92
|
break;
|
|
93
93
|
case "query":
|
|
94
|
-
appendQueryValue(
|
|
94
|
+
appendQueryValue(
|
|
95
|
+
query,
|
|
96
|
+
mapping.name,
|
|
97
|
+
mapping.style,
|
|
98
|
+
value,
|
|
99
|
+
mapping.explode
|
|
100
|
+
);
|
|
95
101
|
break;
|
|
96
102
|
}
|
|
97
103
|
}
|
|
@@ -185,7 +191,7 @@ function appendBracketPairs(params, key, value) {
|
|
|
185
191
|
}
|
|
186
192
|
params.append(key, String(value));
|
|
187
193
|
}
|
|
188
|
-
function appendQueryValue(query, name, style, value) {
|
|
194
|
+
function appendQueryValue(query, name, style, value, explode) {
|
|
189
195
|
if (style === "deepObject") {
|
|
190
196
|
appendBracketPairs(query, name, value);
|
|
191
197
|
return;
|
|
@@ -196,6 +202,10 @@ function appendQueryValue(query, name, style, value) {
|
|
|
196
202
|
query.append(name, items.map(String).join(separator));
|
|
197
203
|
return;
|
|
198
204
|
}
|
|
205
|
+
if ((style === void 0 || style === "form") && explode === false && Array.isArray(value) && value.length > 0) {
|
|
206
|
+
query.append(name, value.map(String).join(","));
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
199
209
|
for (const item of Array.isArray(value) ? value : [value]) {
|
|
200
210
|
query.append(name, String(item));
|
|
201
211
|
}
|
|
@@ -221,123 +231,6 @@ async function resolveHeaders(headers) {
|
|
|
221
231
|
return typeof headers === "function" ? await headers() : { ...headers };
|
|
222
232
|
}
|
|
223
233
|
|
|
224
|
-
// src/openapi/resourceMapping.ts
|
|
225
|
-
function buildResourceMapping(route, name, parameterMap, requiredKeys) {
|
|
226
|
-
const entries = Object.entries(parameterMap);
|
|
227
|
-
if (entries.length === 0) {
|
|
228
|
-
return { kind: "resource", uri: `openapi://${name}${route.path}` };
|
|
229
|
-
}
|
|
230
|
-
const required = new Set(requiredKeys ?? []);
|
|
231
|
-
const args = [];
|
|
232
|
-
const queryKeys = [];
|
|
233
|
-
let path = route.path;
|
|
234
|
-
for (const [flatKey, mapping] of entries) {
|
|
235
|
-
if (mapping.in === "path") {
|
|
236
|
-
if (flatKey !== mapping.name) {
|
|
237
|
-
path = path.replaceAll(`{${mapping.name}}`, `{${flatKey}}`);
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
queryKeys.push(flatKey);
|
|
241
|
-
}
|
|
242
|
-
args.push({ name: flatKey, required: required.has(flatKey) });
|
|
243
|
-
}
|
|
244
|
-
const uriTemplate = `openapi://${name}${path}` + (queryKeys.length > 0 ? `{?${queryKeys.join(",")}}` : "");
|
|
245
|
-
return { args, kind: "template", uriTemplate };
|
|
246
|
-
}
|
|
247
|
-
function isEligibleForResource(route) {
|
|
248
|
-
return route.parameters.every((param) => {
|
|
249
|
-
if (param.in === "header" || param.in === "cookie") {
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
return param.schema?.type !== "array";
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/openapi/routes.ts
|
|
257
|
-
var HTTP_METHODS = ["get", "put", "post", "delete", "patch"];
|
|
258
|
-
function extractRoutes(document) {
|
|
259
|
-
const routes = [];
|
|
260
|
-
for (const [path, rawPathItem] of Object.entries(document.paths ?? {})) {
|
|
261
|
-
const pathItem = resolvePathItem(document, rawPathItem);
|
|
262
|
-
const pathLevelParams = (pathItem.parameters ?? []).map(
|
|
263
|
-
(param) => resolveRef(document, param)
|
|
264
|
-
);
|
|
265
|
-
for (const method of HTTP_METHODS) {
|
|
266
|
-
const operation = pathItem[method];
|
|
267
|
-
if (!operation) {
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
const operationParams = (operation.parameters ?? []).map(
|
|
271
|
-
(param) => resolveRef(document, param)
|
|
272
|
-
);
|
|
273
|
-
routes.push({
|
|
274
|
-
deprecated: operation.deprecated ?? false,
|
|
275
|
-
method,
|
|
276
|
-
operationId: operation.operationId,
|
|
277
|
-
parameters: mergeParameters(pathLevelParams, operationParams),
|
|
278
|
-
path,
|
|
279
|
-
requestBody: operation.requestBody ? resolveRef(document, operation.requestBody) : void 0,
|
|
280
|
-
responses: resolveResponses(document, operation.responses),
|
|
281
|
-
servers: [operation.servers, pathItem.servers, document.servers].find(
|
|
282
|
-
(servers) => servers?.length
|
|
283
|
-
),
|
|
284
|
-
summary: operation.summary,
|
|
285
|
-
tags: operation.tags ?? []
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return routes;
|
|
290
|
-
}
|
|
291
|
-
function mergeParameters(pathLevel, operationLevel) {
|
|
292
|
-
const overridden = new Set(
|
|
293
|
-
operationLevel.map((param) => `${param.in}:${param.name}`)
|
|
294
|
-
);
|
|
295
|
-
return [
|
|
296
|
-
...pathLevel.filter(
|
|
297
|
-
(param) => !overridden.has(`${param.in}:${param.name}`)
|
|
298
|
-
),
|
|
299
|
-
...operationLevel
|
|
300
|
-
];
|
|
301
|
-
}
|
|
302
|
-
function resolvePathItem(document, pathItem) {
|
|
303
|
-
const visited = /* @__PURE__ */ new Set();
|
|
304
|
-
let resolved = pathItem;
|
|
305
|
-
while (resolved.$ref && !visited.has(resolved.$ref)) {
|
|
306
|
-
visited.add(resolved.$ref);
|
|
307
|
-
const { $ref, ...siblings } = resolved;
|
|
308
|
-
resolved = { ...resolveRef(document, { $ref }), ...siblings };
|
|
309
|
-
}
|
|
310
|
-
return resolved;
|
|
311
|
-
}
|
|
312
|
-
function resolveRef(document, value) {
|
|
313
|
-
if (!value || typeof value !== "object" || !("$ref" in value)) {
|
|
314
|
-
return value;
|
|
315
|
-
}
|
|
316
|
-
const pointer = value.$ref;
|
|
317
|
-
if (!pointer.startsWith("#/")) {
|
|
318
|
-
throw new Error(`Unexpected external $ref after bundling: ${pointer}`);
|
|
319
|
-
}
|
|
320
|
-
const segments = pointer.slice(2).split("/").map(
|
|
321
|
-
(segment) => decodeURIComponent(segment.replaceAll("~1", "/").replaceAll("~0", "~"))
|
|
322
|
-
);
|
|
323
|
-
let node = document;
|
|
324
|
-
for (const segment of segments) {
|
|
325
|
-
node = node?.[segment];
|
|
326
|
-
}
|
|
327
|
-
return node;
|
|
328
|
-
}
|
|
329
|
-
function resolveResponses(document, rawResponses) {
|
|
330
|
-
if (!rawResponses) {
|
|
331
|
-
return void 0;
|
|
332
|
-
}
|
|
333
|
-
return Object.fromEntries(
|
|
334
|
-
Object.entries(rawResponses).map(([code, response]) => [
|
|
335
|
-
code,
|
|
336
|
-
resolveRef(document, response)
|
|
337
|
-
])
|
|
338
|
-
);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
234
|
// src/openapi/schemas.ts
|
|
342
235
|
var SCHEMA_MAP_KEYS = /* @__PURE__ */ new Set([
|
|
343
236
|
"$defs",
|
|
@@ -374,7 +267,12 @@ function buildFlatSchema(route, sharedDefs) {
|
|
|
374
267
|
properties[key] = rewriteComponentRefs(
|
|
375
268
|
param.schema ?? { type: "string" }
|
|
376
269
|
);
|
|
377
|
-
parameterMap[key] = {
|
|
270
|
+
parameterMap[key] = {
|
|
271
|
+
explode: param.explode,
|
|
272
|
+
in: param.in,
|
|
273
|
+
name,
|
|
274
|
+
style: param.style
|
|
275
|
+
};
|
|
378
276
|
if (param.in === "path" || param.required) {
|
|
379
277
|
required.push(key);
|
|
380
278
|
}
|
|
@@ -441,6 +339,22 @@ function buildOutputSchema(route, sharedDefs) {
|
|
|
441
339
|
} : {}
|
|
442
340
|
};
|
|
443
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 : sharedDefs?.[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
|
+
}
|
|
444
358
|
function rewriteComponentRefs(value, stripExamples = false) {
|
|
445
359
|
return rewriteNode(value, "schema", stripExamples);
|
|
446
360
|
}
|
|
@@ -569,22 +483,6 @@ function normalizeNullable(schema) {
|
|
|
569
483
|
}
|
|
570
484
|
return rest;
|
|
571
485
|
}
|
|
572
|
-
function resolveComponentRef(schema, sharedDefs) {
|
|
573
|
-
const seen = /* @__PURE__ */ new Set();
|
|
574
|
-
let current = schema;
|
|
575
|
-
let ref = current.$ref;
|
|
576
|
-
while (typeof ref === "string") {
|
|
577
|
-
const name = componentSchemaName(ref);
|
|
578
|
-
const target = name === void 0 ? void 0 : sharedDefs?.[name];
|
|
579
|
-
if (name === void 0 || target === void 0 || seen.has(name)) {
|
|
580
|
-
break;
|
|
581
|
-
}
|
|
582
|
-
seen.add(name);
|
|
583
|
-
current = target;
|
|
584
|
-
ref = current.$ref;
|
|
585
|
-
}
|
|
586
|
-
return current;
|
|
587
|
-
}
|
|
588
486
|
function rewriteNode(value, mode, stripExamples = false) {
|
|
589
487
|
if (mode === "data") {
|
|
590
488
|
return value;
|
|
@@ -610,6 +508,124 @@ function rewriteNode(value, mode, stripExamples = false) {
|
|
|
610
508
|
return mode === "schemaMap" ? rewritten : normalizeExclusiveBounds(normalizeNullable(rewritten));
|
|
611
509
|
}
|
|
612
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(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(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(document.paths ?? {})) {
|
|
549
|
+
const pathItem = resolvePathItem(document, rawPathItem);
|
|
550
|
+
const pathLevelParams = (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 = (operation.parameters ?? []).map(
|
|
559
|
+
(param) => resolveRef(document, param)
|
|
560
|
+
);
|
|
561
|
+
routes.push({
|
|
562
|
+
deprecated: 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) => servers?.length
|
|
571
|
+
),
|
|
572
|
+
summary: operation.summary,
|
|
573
|
+
tags: 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 = node?.[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
|
+
|
|
613
629
|
// src/openapi/selection.ts
|
|
614
630
|
var DEFAULT_MAX_OPERATIONS = 40;
|
|
615
631
|
var METHOD_PRIORITY = {
|
|
@@ -689,7 +705,7 @@ async function fromOpenAPI(options) {
|
|
|
689
705
|
route,
|
|
690
706
|
servers: route.servers
|
|
691
707
|
};
|
|
692
|
-
if (options.resources && route.method === "get" && isEligibleForResource(route)) {
|
|
708
|
+
if (options.resources && route.method === "get" && isEligibleForResource(route, sharedDefs)) {
|
|
693
709
|
registerResource(
|
|
694
710
|
server,
|
|
695
711
|
route,
|