fastmcp 4.13.1 → 4.14.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 +46 -0
- package/dist/FastMCP.cjs +2 -2
- package/dist/FastMCP.d.cts +32 -1
- package/dist/FastMCP.d.ts +32 -1
- package/dist/FastMCP.js +1 -1
- package/dist/{chunk-O72VCMGV.cjs → chunk-B5WJ5VRV.cjs} +255 -184
- package/dist/chunk-B5WJ5VRV.cjs.map +1 -0
- package/dist/{chunk-3BMGHXXY.js → chunk-SGCRCQNU.js} +225 -154
- package/dist/chunk-SGCRCQNU.js.map +1 -0
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3BMGHXXY.js.map +0 -1
- package/dist/chunk-O72VCMGV.cjs.map +0 -1
|
@@ -355,6 +355,8 @@ function assertToolSchemas(tool) {
|
|
|
355
355
|
assertStandardSchema(tool.name, "outputSchema", tool.outputSchema);
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
|
+
var STREAM_KEEPALIVE_LOGGER = "fastmcp-keepalive";
|
|
359
|
+
var STREAM_KEEPALIVE_DEFAULT_INTERVAL_MS = 2e4;
|
|
358
360
|
var TextContentZodSchema = _zod.z.object({
|
|
359
361
|
/**
|
|
360
362
|
* The text content of the message.
|
|
@@ -421,10 +423,23 @@ var CompletionZodSchema = _zod.z.object({
|
|
|
421
423
|
*/
|
|
422
424
|
total: _zod.z.optional(_zod.z.number().int()),
|
|
423
425
|
/**
|
|
424
|
-
* An array of completion values.
|
|
426
|
+
* An array of completion values. The MCP spec caps this at 100 items; values
|
|
427
|
+
* beyond the cap are trimmed by `capCompletionValues` (which sets `hasMore`)
|
|
428
|
+
* rather than rejected, so the schema itself does not enforce the limit.
|
|
425
429
|
*/
|
|
426
|
-
values: _zod.z.array(_zod.z.string())
|
|
430
|
+
values: _zod.z.array(_zod.z.string())
|
|
427
431
|
});
|
|
432
|
+
var COMPLETION_VALUES_LIMIT = 100;
|
|
433
|
+
var capCompletionValues = (completion) => {
|
|
434
|
+
if (completion.values.length <= COMPLETION_VALUES_LIMIT) {
|
|
435
|
+
return completion;
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
...completion,
|
|
439
|
+
hasMore: true,
|
|
440
|
+
values: completion.values.slice(0, COMPLETION_VALUES_LIMIT)
|
|
441
|
+
};
|
|
442
|
+
};
|
|
428
443
|
var FastMCPSessionEventEmitterBase = _events.EventEmitter;
|
|
429
444
|
var ServerState = /* @__PURE__ */ ((ServerState2) => {
|
|
430
445
|
ServerState2["Error"] = "error";
|
|
@@ -483,6 +498,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
483
498
|
* instance — so capabilities can never be inferred here.
|
|
484
499
|
*/
|
|
485
500
|
#stateless;
|
|
501
|
+
#streamKeepaliveConfig;
|
|
486
502
|
/**
|
|
487
503
|
* Resource URIs the connected client has subscribed to via
|
|
488
504
|
* `resources/subscribe`. Used to scope `notifications/resources/updated`
|
|
@@ -503,6 +519,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
503
519
|
roots,
|
|
504
520
|
sessionId,
|
|
505
521
|
stateless = false,
|
|
522
|
+
streamKeepalive,
|
|
506
523
|
tools,
|
|
507
524
|
transportType,
|
|
508
525
|
utils,
|
|
@@ -516,6 +533,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
516
533
|
this.#rootsConfig = roots;
|
|
517
534
|
this.#sessionId = sessionId;
|
|
518
535
|
this.#stateless = stateless;
|
|
536
|
+
this.#streamKeepaliveConfig = streamKeepalive;
|
|
519
537
|
this.#needsEventLoopFlush = transportType === "httpStream";
|
|
520
538
|
if (tools.length) {
|
|
521
539
|
this.#capabilities.tools = {};
|
|
@@ -843,6 +861,44 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
843
861
|
logLevel: pingConfig.logLevel || "debug"
|
|
844
862
|
};
|
|
845
863
|
}
|
|
864
|
+
/**
|
|
865
|
+
* Periodically writes to the response stream of an in-flight tool call, so an
|
|
866
|
+
* idle-connection timeout (proxy, load balancer) does not close it while a
|
|
867
|
+
* long-running tool produces no output of its own.
|
|
868
|
+
*
|
|
869
|
+
* The notification is related to the tool call, so it travels on that
|
|
870
|
+
* request's own stream, which is the only server-to-client route that exists
|
|
871
|
+
* when running stateless.
|
|
872
|
+
*
|
|
873
|
+
* @returns a function that stops the keepalive.
|
|
874
|
+
*/
|
|
875
|
+
#startStreamKeepalive(extra, toolName) {
|
|
876
|
+
const config = this.#streamKeepaliveConfig;
|
|
877
|
+
if (!_optionalChain([config, 'optionalAccess', _21 => _21.enabled])) {
|
|
878
|
+
return () => {
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
const intervalMs = config.intervalMs && config.intervalMs > 0 ? config.intervalMs : STREAM_KEEPALIVE_DEFAULT_INTERVAL_MS;
|
|
882
|
+
const timer = setInterval(() => {
|
|
883
|
+
extra.sendNotification({
|
|
884
|
+
method: "notifications/message",
|
|
885
|
+
params: {
|
|
886
|
+
data: { message: `keepalive while '${toolName}' is running` },
|
|
887
|
+
level: _nullishCoalesce(config.logLevel, () => ( "debug")),
|
|
888
|
+
logger: STREAM_KEEPALIVE_LOGGER
|
|
889
|
+
}
|
|
890
|
+
}).catch((error) => {
|
|
891
|
+
this.#logger.debug(
|
|
892
|
+
`[FastMCP debug] stream keepalive for '${toolName}' failed:`,
|
|
893
|
+
error instanceof Error ? error.message : String(error)
|
|
894
|
+
);
|
|
895
|
+
});
|
|
896
|
+
}, intervalMs);
|
|
897
|
+
_optionalChain([timer, 'access', _22 => _22.unref, 'optionalCall', _23 => _23()]);
|
|
898
|
+
const stop = () => clearInterval(timer);
|
|
899
|
+
_optionalChain([extra, 'access', _24 => _24.signal, 'optionalAccess', _25 => _25.addEventListener, 'call', _26 => _26("abort", stop, { once: true })]);
|
|
900
|
+
return stop;
|
|
901
|
+
}
|
|
846
902
|
async #validateStructuredContent(tool, value, toolName) {
|
|
847
903
|
if (!tool.outputSchema) {
|
|
848
904
|
return value;
|
|
@@ -936,11 +992,13 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
936
992
|
request
|
|
937
993
|
});
|
|
938
994
|
}
|
|
939
|
-
const completion =
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
995
|
+
const completion = capCompletionValues(
|
|
996
|
+
CompletionZodSchema.parse(
|
|
997
|
+
await prompt.complete(
|
|
998
|
+
request.params.argument.name,
|
|
999
|
+
request.params.argument.value,
|
|
1000
|
+
this.#auth
|
|
1001
|
+
)
|
|
944
1002
|
)
|
|
945
1003
|
);
|
|
946
1004
|
return {
|
|
@@ -968,11 +1026,13 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
968
1026
|
}
|
|
969
1027
|
);
|
|
970
1028
|
}
|
|
971
|
-
const completion =
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1029
|
+
const completion = capCompletionValues(
|
|
1030
|
+
CompletionZodSchema.parse(
|
|
1031
|
+
await resource.complete(
|
|
1032
|
+
request.params.argument.name,
|
|
1033
|
+
request.params.argument.value,
|
|
1034
|
+
this.#auth
|
|
1035
|
+
)
|
|
976
1036
|
)
|
|
977
1037
|
);
|
|
978
1038
|
return {
|
|
@@ -1037,7 +1097,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1037
1097
|
result = await prompt.load(
|
|
1038
1098
|
args,
|
|
1039
1099
|
this.#auth,
|
|
1040
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
1100
|
+
this.#createLoadContext(_optionalChain([request, 'access', _27 => _27.params, 'optionalAccess', _28 => _28._meta]))
|
|
1041
1101
|
);
|
|
1042
1102
|
} catch (error) {
|
|
1043
1103
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1102,7 +1162,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1102
1162
|
const result = await resourceTemplate.load(
|
|
1103
1163
|
match,
|
|
1104
1164
|
this.#auth,
|
|
1105
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
1165
|
+
this.#createLoadContext(_optionalChain([request, 'access', _29 => _29.params, 'optionalAccess', _30 => _30._meta]))
|
|
1106
1166
|
);
|
|
1107
1167
|
const resources = Array.isArray(result) ? result : [result];
|
|
1108
1168
|
return {
|
|
@@ -1127,7 +1187,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1127
1187
|
try {
|
|
1128
1188
|
maybeArrayResult = await resource.load(
|
|
1129
1189
|
this.#auth,
|
|
1130
|
-
this.#createLoadContext(_optionalChain([request, 'access',
|
|
1190
|
+
this.#createLoadContext(_optionalChain([request, 'access', _31 => _31.params, 'optionalAccess', _32 => _32._meta]))
|
|
1131
1191
|
);
|
|
1132
1192
|
} catch (error) {
|
|
1133
1193
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1190,7 +1250,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1190
1250
|
);
|
|
1191
1251
|
}
|
|
1192
1252
|
setupRootsHandlers() {
|
|
1193
|
-
if (_optionalChain([this, 'access',
|
|
1253
|
+
if (_optionalChain([this, 'access', _33 => _33.#rootsConfig, 'optionalAccess', _34 => _34.enabled]) === false) {
|
|
1194
1254
|
this.#logger.debug(
|
|
1195
1255
|
"[FastMCP debug] roots capability explicitly disabled via config"
|
|
1196
1256
|
);
|
|
@@ -1260,169 +1320,178 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1260
1320
|
tools: cachedToolsList
|
|
1261
1321
|
};
|
|
1262
1322
|
});
|
|
1263
|
-
this.#server.setRequestHandler(
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
`Unknown tool: ${request.params.name}`
|
|
1269
|
-
);
|
|
1270
|
-
}
|
|
1271
|
-
let args = void 0;
|
|
1272
|
-
if (tool.parameters) {
|
|
1273
|
-
const parsed = await tool.parameters["~standard"].validate(
|
|
1274
|
-
request.params.arguments
|
|
1275
|
-
);
|
|
1276
|
-
if (parsed.issues) {
|
|
1277
|
-
const friendlyErrors = this.#formatSchemaIssues(parsed.issues);
|
|
1323
|
+
this.#server.setRequestHandler(
|
|
1324
|
+
_typesjs.CallToolRequestSchema,
|
|
1325
|
+
async (request, extra) => {
|
|
1326
|
+
const tool = toolsMap.get(request.params.name);
|
|
1327
|
+
if (!tool) {
|
|
1278
1328
|
throw new (0, _typesjs.McpError)(
|
|
1279
|
-
_typesjs.ErrorCode.
|
|
1280
|
-
`
|
|
1329
|
+
_typesjs.ErrorCode.MethodNotFound,
|
|
1330
|
+
`Unknown tool: ${request.params.name}`
|
|
1281
1331
|
);
|
|
1282
1332
|
}
|
|
1283
|
-
args =
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1333
|
+
let args = void 0;
|
|
1334
|
+
if (tool.parameters) {
|
|
1335
|
+
const parsed = await tool.parameters["~standard"].validate(
|
|
1336
|
+
request.params.arguments
|
|
1337
|
+
);
|
|
1338
|
+
if (parsed.issues) {
|
|
1339
|
+
const friendlyErrors = this.#formatSchemaIssues(parsed.issues);
|
|
1340
|
+
throw new (0, _typesjs.McpError)(
|
|
1341
|
+
_typesjs.ErrorCode.InvalidParams,
|
|
1342
|
+
`Tool '${request.params.name}' parameter validation failed: ${friendlyErrors}. Please check the parameter types and values according to the tool's schema.`
|
|
1343
|
+
);
|
|
1291
1344
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1345
|
+
args = parsed.value;
|
|
1346
|
+
}
|
|
1347
|
+
const progressToken = _optionalChain([request, 'access', _35 => _35.params, 'optionalAccess', _36 => _36._meta, 'optionalAccess', _37 => _37.progressToken]);
|
|
1348
|
+
let result;
|
|
1349
|
+
try {
|
|
1350
|
+
const reportProgress = async (progress) => {
|
|
1351
|
+
if (progressToken === void 0) {
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
try {
|
|
1355
|
+
await this.#server.notification({
|
|
1356
|
+
method: "notifications/progress",
|
|
1357
|
+
params: {
|
|
1358
|
+
...progress,
|
|
1359
|
+
progressToken
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
if (this.#needsEventLoopFlush) {
|
|
1363
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1298
1364
|
}
|
|
1299
|
-
})
|
|
1300
|
-
|
|
1301
|
-
|
|
1365
|
+
} catch (progressError) {
|
|
1366
|
+
this.#logger.warn(
|
|
1367
|
+
`[FastMCP warning] Failed to report progress for tool '${request.params.name}':`,
|
|
1368
|
+
progressError instanceof Error ? progressError.message : String(progressError)
|
|
1369
|
+
);
|
|
1302
1370
|
}
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
content: contentArray,
|
|
1318
|
-
toolName: request.params.name
|
|
1371
|
+
};
|
|
1372
|
+
const log = this.#createLog();
|
|
1373
|
+
const streamContent = async (content) => {
|
|
1374
|
+
const contentArray = Array.isArray(content) ? content : [content];
|
|
1375
|
+
try {
|
|
1376
|
+
await this.#server.notification({
|
|
1377
|
+
method: "notifications/tool/streamContent",
|
|
1378
|
+
params: {
|
|
1379
|
+
content: contentArray,
|
|
1380
|
+
toolName: request.params.name
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
if (this.#needsEventLoopFlush) {
|
|
1384
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1319
1385
|
}
|
|
1320
|
-
})
|
|
1321
|
-
|
|
1322
|
-
|
|
1386
|
+
} catch (streamError) {
|
|
1387
|
+
this.#logger.warn(
|
|
1388
|
+
`[FastMCP warning] Failed to stream content for tool '${request.params.name}':`,
|
|
1389
|
+
streamError instanceof Error ? streamError.message : String(streamError)
|
|
1390
|
+
);
|
|
1323
1391
|
}
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1392
|
+
};
|
|
1393
|
+
if (this.#onToolCall) {
|
|
1394
|
+
await this.#onToolCall({
|
|
1395
|
+
arguments: _nullishCoalesce(args, () => ( {})),
|
|
1396
|
+
toolName: request.params.name
|
|
1397
|
+
});
|
|
1329
1398
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
)
|
|
1399
|
+
const executeToolPromise = Promise.resolve(
|
|
1400
|
+
tool.execute(args, {
|
|
1401
|
+
client: {
|
|
1402
|
+
version: this.#server.getClientVersion()
|
|
1403
|
+
},
|
|
1404
|
+
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
1405
|
+
log,
|
|
1406
|
+
reportProgress,
|
|
1407
|
+
requestId: typeof _optionalChain([request, 'access', _38 => _38.params, 'optionalAccess', _39 => _39._meta, 'optionalAccess', _40 => _40.requestId]) === "string" ? request.params._meta.requestId : void 0,
|
|
1408
|
+
session: this.#auth,
|
|
1409
|
+
sessionId: this.#sessionId,
|
|
1410
|
+
streamContent
|
|
1411
|
+
})
|
|
1412
|
+
);
|
|
1413
|
+
const stopStreamKeepalive = this.#startStreamKeepalive(
|
|
1414
|
+
extra,
|
|
1415
|
+
request.params.name
|
|
1416
|
+
);
|
|
1417
|
+
const maybeStringResult = await (tool.timeoutMs ? Promise.race([
|
|
1418
|
+
executeToolPromise,
|
|
1419
|
+
new Promise((_, reject) => {
|
|
1420
|
+
const timeoutId = setTimeout(() => {
|
|
1421
|
+
reject(
|
|
1422
|
+
new UserError(
|
|
1423
|
+
`Tool '${request.params.name}' timed out after ${tool.timeoutMs}ms. Consider increasing timeoutMs or optimizing the tool implementation.`
|
|
1424
|
+
)
|
|
1425
|
+
);
|
|
1426
|
+
}, tool.timeoutMs);
|
|
1427
|
+
executeToolPromise.then(
|
|
1428
|
+
() => clearTimeout(timeoutId),
|
|
1429
|
+
() => clearTimeout(timeoutId)
|
|
1357
1430
|
);
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
})
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
})
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1431
|
+
})
|
|
1432
|
+
]) : executeToolPromise).finally(stopStreamKeepalive);
|
|
1433
|
+
await _promises3.setTimeout.call(void 0, 1);
|
|
1434
|
+
if (maybeStringResult === void 0 || maybeStringResult === null) {
|
|
1435
|
+
result = ContentResultZodSchema.parse({
|
|
1436
|
+
content: []
|
|
1437
|
+
});
|
|
1438
|
+
} else if (typeof maybeStringResult === "string") {
|
|
1439
|
+
result = ContentResultZodSchema.parse({
|
|
1440
|
+
content: [{ text: maybeStringResult, type: "text" }]
|
|
1441
|
+
});
|
|
1442
|
+
} else if ("type" in maybeStringResult) {
|
|
1443
|
+
result = ContentResultZodSchema.parse({
|
|
1444
|
+
content: [maybeStringResult]
|
|
1445
|
+
});
|
|
1446
|
+
} else if ("content" in maybeStringResult) {
|
|
1447
|
+
result = ContentResultZodSchema.parse(maybeStringResult);
|
|
1448
|
+
if (result.structuredContent !== void 0 && tool.outputSchema) {
|
|
1449
|
+
result.structuredContent = await this.#validateStructuredContent(
|
|
1450
|
+
tool,
|
|
1451
|
+
result.structuredContent,
|
|
1452
|
+
request.params.name
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
} else if (tool.outputSchema) {
|
|
1456
|
+
const structuredContent = await this.#validateStructuredContent(
|
|
1382
1457
|
tool,
|
|
1383
|
-
|
|
1458
|
+
maybeStringResult,
|
|
1384
1459
|
request.params.name
|
|
1385
1460
|
);
|
|
1461
|
+
result = ContentResultZodSchema.parse({
|
|
1462
|
+
content: [
|
|
1463
|
+
{
|
|
1464
|
+
text: JSON.stringify(structuredContent),
|
|
1465
|
+
type: "text"
|
|
1466
|
+
}
|
|
1467
|
+
],
|
|
1468
|
+
structuredContent
|
|
1469
|
+
});
|
|
1470
|
+
} else {
|
|
1471
|
+
result = ContentResultZodSchema.parse(maybeStringResult);
|
|
1386
1472
|
}
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
if (error instanceof UserError) {
|
|
1475
|
+
return {
|
|
1476
|
+
content: [{ text: error.message, type: "text" }],
|
|
1477
|
+
isError: true,
|
|
1478
|
+
...error.extras ? { structuredContent: error.extras } : {}
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1482
|
+
return {
|
|
1394
1483
|
content: [
|
|
1395
1484
|
{
|
|
1396
|
-
text:
|
|
1485
|
+
text: `Tool '${request.params.name}' execution failed: ${errorMessage}`,
|
|
1397
1486
|
type: "text"
|
|
1398
1487
|
}
|
|
1399
1488
|
],
|
|
1400
|
-
|
|
1401
|
-
});
|
|
1402
|
-
} else {
|
|
1403
|
-
result = ContentResultZodSchema.parse(maybeStringResult);
|
|
1404
|
-
}
|
|
1405
|
-
} catch (error) {
|
|
1406
|
-
if (error instanceof UserError) {
|
|
1407
|
-
return {
|
|
1408
|
-
content: [{ text: error.message, type: "text" }],
|
|
1409
|
-
isError: true,
|
|
1410
|
-
...error.extras ? { structuredContent: error.extras } : {}
|
|
1489
|
+
isError: true
|
|
1411
1490
|
};
|
|
1412
1491
|
}
|
|
1413
|
-
|
|
1414
|
-
return {
|
|
1415
|
-
content: [
|
|
1416
|
-
{
|
|
1417
|
-
text: `Tool '${request.params.name}' execution failed: ${errorMessage}`,
|
|
1418
|
-
type: "text"
|
|
1419
|
-
}
|
|
1420
|
-
],
|
|
1421
|
-
isError: true
|
|
1422
|
-
};
|
|
1492
|
+
return result;
|
|
1423
1493
|
}
|
|
1424
|
-
|
|
1425
|
-
});
|
|
1494
|
+
);
|
|
1426
1495
|
}
|
|
1427
1496
|
};
|
|
1428
1497
|
function camelToSnakeCase(str) {
|
|
@@ -1451,7 +1520,7 @@ function normalizePath(path) {
|
|
|
1451
1520
|
return path.startsWith("/") ? path : `/${path}`;
|
|
1452
1521
|
}
|
|
1453
1522
|
function parseBasicAuthHeader(authHeader) {
|
|
1454
|
-
const basicMatch = _optionalChain([authHeader, 'optionalAccess',
|
|
1523
|
+
const basicMatch = _optionalChain([authHeader, 'optionalAccess', _41 => _41.match, 'call', _42 => _42(/^Basic\s+(.+)$/)]);
|
|
1455
1524
|
if (!basicMatch) return null;
|
|
1456
1525
|
try {
|
|
1457
1526
|
const credentials = Buffer.from(basicMatch[1], "base64").toString("utf-8");
|
|
@@ -1863,6 +1932,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1863
1932
|
resources: this.#resources,
|
|
1864
1933
|
resourcesTemplates: this.#resourcesTemplates,
|
|
1865
1934
|
roots: this.#options.roots,
|
|
1935
|
+
streamKeepalive: this.#options.streamKeepalive,
|
|
1866
1936
|
tools: this.#tools,
|
|
1867
1937
|
transportType: "stdio",
|
|
1868
1938
|
utils: this.#options.utils,
|
|
@@ -1932,7 +2002,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1932
2002
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
1933
2003
|
eventStore: httpConfig.eventStore,
|
|
1934
2004
|
host: httpConfig.host,
|
|
1935
|
-
..._optionalChain([this, 'access',
|
|
2005
|
+
..._optionalChain([this, 'access', _43 => _43.#options, 'access', _44 => _44.oauth, 'optionalAccess', _45 => _45.enabled]) && _optionalChain([this, 'access', _46 => _46.#options, 'access', _47 => _47.oauth, 'access', _48 => _48.protectedResource, 'optionalAccess', _49 => _49.resource]) ? {
|
|
1936
2006
|
oauth: {
|
|
1937
2007
|
protectedResource: {
|
|
1938
2008
|
resource: this.#options.oauth.protectedResource.resource
|
|
@@ -1981,7 +2051,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
1981
2051
|
enableJsonResponse: httpConfig.enableJsonResponse,
|
|
1982
2052
|
eventStore: httpConfig.eventStore,
|
|
1983
2053
|
host: httpConfig.host,
|
|
1984
|
-
..._optionalChain([this, 'access',
|
|
2054
|
+
..._optionalChain([this, 'access', _50 => _50.#options, 'access', _51 => _51.oauth, 'optionalAccess', _52 => _52.enabled]) && _optionalChain([this, 'access', _53 => _53.#options, 'access', _54 => _54.oauth, 'access', _55 => _55.protectedResource, 'optionalAccess', _56 => _56.resource]) ? {
|
|
1985
2055
|
oauth: {
|
|
1986
2056
|
protectedResource: {
|
|
1987
2057
|
resource: this.#options.oauth.protectedResource.resource
|
|
@@ -2062,6 +2132,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2062
2132
|
roots: this.#options.roots,
|
|
2063
2133
|
sessionId,
|
|
2064
2134
|
stateless,
|
|
2135
|
+
streamKeepalive: this.#options.streamKeepalive,
|
|
2065
2136
|
tools: allowedTools,
|
|
2066
2137
|
transportType: "httpStream",
|
|
2067
2138
|
utils: this.#options.utils,
|
|
@@ -2083,7 +2154,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2083
2154
|
*/
|
|
2084
2155
|
#createUnauthorizedResponse(message) {
|
|
2085
2156
|
const oauth = this.#options.oauth;
|
|
2086
|
-
const resource = _optionalChain([oauth, 'optionalAccess',
|
|
2157
|
+
const resource = _optionalChain([oauth, 'optionalAccess', _57 => _57.enabled]) ? _optionalChain([oauth, 'access', _58 => _58.protectedResource, 'optionalAccess', _59 => _59.resource]) : void 0;
|
|
2087
2158
|
const wwwAuthenticateParts = [
|
|
2088
2159
|
'error="invalid_token"',
|
|
2089
2160
|
`error_description="${message.replace(/"/g, '\\"')}"`
|
|
@@ -2195,7 +2266,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2195
2266
|
}
|
|
2196
2267
|
}
|
|
2197
2268
|
const oauthConfig = this.#options.oauth;
|
|
2198
|
-
if (_optionalChain([oauthConfig, 'optionalAccess',
|
|
2269
|
+
if (_optionalChain([oauthConfig, 'optionalAccess', _60 => _60.enabled]) && req.method === "GET") {
|
|
2199
2270
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2200
2271
|
const authorizationServerMetadataPath = joinPaths(
|
|
2201
2272
|
"",
|
|
@@ -2229,8 +2300,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2229
2300
|
}
|
|
2230
2301
|
}
|
|
2231
2302
|
}
|
|
2232
|
-
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess',
|
|
2233
|
-
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess',
|
|
2303
|
+
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _61 => _61.proxy]);
|
|
2304
|
+
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _62 => _62.enabled])) {
|
|
2234
2305
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2235
2306
|
const oauthPath = basePathRelativePath;
|
|
2236
2307
|
try {
|
|
@@ -2283,7 +2354,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2283
2354
|
const statusCode = error.statusCode || 400;
|
|
2284
2355
|
res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
|
|
2285
2356
|
JSON.stringify(
|
|
2286
|
-
_optionalChain([error, 'access',
|
|
2357
|
+
_optionalChain([error, 'access', _63 => _63.toJSON, 'optionalCall', _64 => _64()]) || {
|
|
2287
2358
|
error: "invalid_request"
|
|
2288
2359
|
}
|
|
2289
2360
|
)
|
|
@@ -2310,7 +2381,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2310
2381
|
} catch (error) {
|
|
2311
2382
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2312
2383
|
JSON.stringify(
|
|
2313
|
-
_optionalChain([error, 'access',
|
|
2384
|
+
_optionalChain([error, 'access', _65 => _65.toJSON, 'optionalCall', _66 => _66()]) || {
|
|
2314
2385
|
error: "invalid_request"
|
|
2315
2386
|
}
|
|
2316
2387
|
)
|
|
@@ -2332,7 +2403,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2332
2403
|
} catch (error) {
|
|
2333
2404
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2334
2405
|
JSON.stringify(
|
|
2335
|
-
_optionalChain([error, 'access',
|
|
2406
|
+
_optionalChain([error, 'access', _67 => _67.toJSON, 'optionalCall', _68 => _68()]) || {
|
|
2336
2407
|
error: "server_error"
|
|
2337
2408
|
}
|
|
2338
2409
|
)
|
|
@@ -2401,7 +2472,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2401
2472
|
} catch (error) {
|
|
2402
2473
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2403
2474
|
JSON.stringify(
|
|
2404
|
-
_optionalChain([error, 'access',
|
|
2475
|
+
_optionalChain([error, 'access', _69 => _69.toJSON, 'optionalCall', _70 => _70()]) || {
|
|
2405
2476
|
error: "server_error"
|
|
2406
2477
|
}
|
|
2407
2478
|
)
|
|
@@ -2459,8 +2530,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2459
2530
|
const basicAuth = parseBasicAuthHeader(
|
|
2460
2531
|
req.headers.authorization
|
|
2461
2532
|
);
|
|
2462
|
-
const clientId = _optionalChain([basicAuth, 'optionalAccess',
|
|
2463
|
-
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess',
|
|
2533
|
+
const clientId = _optionalChain([basicAuth, 'optionalAccess', _71 => _71.clientId]) || params.get("client_id") || "";
|
|
2534
|
+
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _72 => _72.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
|
|
2464
2535
|
let response;
|
|
2465
2536
|
if (grantType === "authorization_code") {
|
|
2466
2537
|
response = await oauthProxy.exchangeAuthorizationCode({
|
|
@@ -2490,7 +2561,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2490
2561
|
const statusCode = error.statusCode || 400;
|
|
2491
2562
|
res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
|
|
2492
2563
|
JSON.stringify(
|
|
2493
|
-
_optionalChain([error, 'access',
|
|
2564
|
+
_optionalChain([error, 'access', _73 => _73.toJSON, 'optionalCall', _74 => _74()]) || {
|
|
2494
2565
|
error: "invalid_request"
|
|
2495
2566
|
}
|
|
2496
2567
|
)
|
|
@@ -2561,23 +2632,23 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2561
2632
|
const envBasePath = process.env.FASTMCP_BASE_PATH;
|
|
2562
2633
|
const envStateless = process.env.FASTMCP_STATELESS;
|
|
2563
2634
|
const envHost = process.env.FASTMCP_HOST;
|
|
2564
|
-
const transportType = _optionalChain([overrides, 'optionalAccess',
|
|
2635
|
+
const transportType = _optionalChain([overrides, 'optionalAccess', _75 => _75.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
|
|
2565
2636
|
if (transportType === "httpStream") {
|
|
2566
2637
|
const port = parseInt(
|
|
2567
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2638
|
+
_optionalChain([overrides, 'optionalAccess', _76 => _76.httpStream, 'optionalAccess', _77 => _77.port, 'optionalAccess', _78 => _78.toString, 'call', _79 => _79()]) || portArg || envPort || "8080"
|
|
2568
2639
|
);
|
|
2569
|
-
const host = _optionalChain([overrides, 'optionalAccess',
|
|
2570
|
-
const endpoint = _optionalChain([overrides, 'optionalAccess',
|
|
2640
|
+
const host = _optionalChain([overrides, 'optionalAccess', _80 => _80.httpStream, 'optionalAccess', _81 => _81.host]) || hostArg || envHost || "localhost";
|
|
2641
|
+
const endpoint = _optionalChain([overrides, 'optionalAccess', _82 => _82.httpStream, 'optionalAccess', _83 => _83.endpoint]) || endpointArg || envEndpoint || "/mcp";
|
|
2571
2642
|
const basePath = normalizeBasePath(
|
|
2572
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
2643
|
+
_optionalChain([overrides, 'optionalAccess', _84 => _84.httpStream, 'optionalAccess', _85 => _85.basePath]) || basePathArg || envBasePath
|
|
2573
2644
|
);
|
|
2574
|
-
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess',
|
|
2575
|
-
const stateless = _optionalChain([overrides, 'optionalAccess',
|
|
2576
|
-
const cors = _optionalChain([overrides, 'optionalAccess',
|
|
2577
|
-
const eventStore = _optionalChain([overrides, 'optionalAccess',
|
|
2578
|
-
const sslCa = _optionalChain([overrides, 'optionalAccess',
|
|
2579
|
-
const sslCert = _optionalChain([overrides, 'optionalAccess',
|
|
2580
|
-
const sslKey = _optionalChain([overrides, 'optionalAccess',
|
|
2645
|
+
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _86 => _86.httpStream, 'optionalAccess', _87 => _87.enableJsonResponse]) || false;
|
|
2646
|
+
const stateless = _optionalChain([overrides, 'optionalAccess', _88 => _88.httpStream, 'optionalAccess', _89 => _89.stateless]) || statelessArg === "true" || envStateless === "true" || false;
|
|
2647
|
+
const cors = _optionalChain([overrides, 'optionalAccess', _90 => _90.httpStream, 'optionalAccess', _91 => _91.cors]);
|
|
2648
|
+
const eventStore = _optionalChain([overrides, 'optionalAccess', _92 => _92.httpStream, 'optionalAccess', _93 => _93.eventStore]);
|
|
2649
|
+
const sslCa = _optionalChain([overrides, 'optionalAccess', _94 => _94.httpStream, 'optionalAccess', _95 => _95.sslCa]);
|
|
2650
|
+
const sslCert = _optionalChain([overrides, 'optionalAccess', _96 => _96.httpStream, 'optionalAccess', _97 => _97.sslCert]);
|
|
2651
|
+
const sslKey = _optionalChain([overrides, 'optionalAccess', _98 => _98.httpStream, 'optionalAccess', _99 => _99.sslKey]);
|
|
2581
2652
|
return {
|
|
2582
2653
|
httpStream: {
|
|
2583
2654
|
basePath,
|
|
@@ -2676,4 +2747,4 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2676
2747
|
|
|
2677
2748
|
|
|
2678
2749
|
exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.FastMCPError = FastMCPError; exports.SessionError = SessionError; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ServerState = ServerState; exports.FastMCPSession = FastMCPSession; exports.FastMCP = FastMCP;
|
|
2679
|
-
//# sourceMappingURL=chunk-
|
|
2750
|
+
//# sourceMappingURL=chunk-B5WJ5VRV.cjs.map
|