fastmcp 4.23.5 → 4.23.6
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 +5 -0
- package/dist/FastMCP.cjs +2 -2
- package/dist/FastMCP.js +1 -1
- package/dist/{chunk-MI6R72UA.cjs → chunk-2PXF6JQB.cjs} +168 -111
- package/dist/chunk-2PXF6JQB.cjs.map +1 -0
- package/dist/{chunk-OUD755CE.js → chunk-5QKBH7JC.js} +127 -70
- package/dist/chunk-5QKBH7JC.js.map +1 -0
- package/dist/edge/index.cjs +3 -0
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.js +3 -0
- package/dist/edge/index.js.map +1 -1
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/dist/openapi/index.cjs +6 -6
- package/dist/openapi/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-MI6R72UA.cjs.map +0 -1
- package/dist/chunk-OUD755CE.js.map +0 -1
|
@@ -225,6 +225,16 @@ function unwrapDefault(value) {
|
|
|
225
225
|
|
|
226
226
|
// src/FastMCP.ts
|
|
227
227
|
var MEDIA_FETCH_TIMEOUT_MS = 3e4;
|
|
228
|
+
var isSvg = (buffer) => {
|
|
229
|
+
let text = buffer.toString("utf8").trimStart();
|
|
230
|
+
const preamble = /^(?:<\?[\s\S]*?\?>|<!--[\s\S]*?-->|<!DOCTYPE\s[^[>]*(?:\[[\s\S]*?\]\s*)?>)/;
|
|
231
|
+
let match = preamble.exec(text);
|
|
232
|
+
while (match) {
|
|
233
|
+
text = text.slice(match[0].length).trimStart();
|
|
234
|
+
match = preamble.exec(text);
|
|
235
|
+
}
|
|
236
|
+
return /^<svg(?:\s|\/?>)/.test(text);
|
|
237
|
+
};
|
|
228
238
|
var imageContent = async (input) => {
|
|
229
239
|
let rawData;
|
|
230
240
|
try {
|
|
@@ -267,16 +277,17 @@ var imageContent = async (input) => {
|
|
|
267
277
|
);
|
|
268
278
|
}
|
|
269
279
|
const { fileTypeFromBuffer } = await Promise.resolve().then(() => _interopRequireWildcard(require("file-type")));
|
|
270
|
-
const
|
|
271
|
-
|
|
280
|
+
const fileType = await fileTypeFromBuffer(rawData);
|
|
281
|
+
const mimeType = (!fileType || fileType.mime === "application/xml") && isSvg(rawData) ? "image/svg+xml" : _optionalChain([fileType, 'optionalAccess', _4 => _4.mime]);
|
|
282
|
+
if (!mimeType || !mimeType.startsWith("image/")) {
|
|
272
283
|
console.warn(
|
|
273
|
-
`Warning: Content may not be a valid image. Detected MIME: ${
|
|
284
|
+
`Warning: Content may not be a valid image. Detected MIME: ${mimeType || "unknown"}`
|
|
274
285
|
);
|
|
275
286
|
}
|
|
276
287
|
const base64Data = rawData.toString("base64");
|
|
277
288
|
return {
|
|
278
289
|
data: base64Data,
|
|
279
|
-
mimeType: _nullishCoalesce(
|
|
290
|
+
mimeType: _nullishCoalesce(mimeType, () => ( "image/png")),
|
|
280
291
|
type: "image"
|
|
281
292
|
};
|
|
282
293
|
} catch (error) {
|
|
@@ -287,8 +298,27 @@ var imageContent = async (input) => {
|
|
|
287
298
|
}
|
|
288
299
|
}
|
|
289
300
|
};
|
|
301
|
+
var AUDIO_CONTAINER_TYPES = /* @__PURE__ */ new Map([
|
|
302
|
+
["video/3gpp", "audio/3gpp"],
|
|
303
|
+
["video/3gpp2", "audio/3gpp2"],
|
|
304
|
+
["video/matroska", "audio/matroska"],
|
|
305
|
+
["video/mp4", "audio/mp4"],
|
|
306
|
+
["video/ogg", "audio/ogg"],
|
|
307
|
+
["video/webm", "audio/webm"]
|
|
308
|
+
]);
|
|
309
|
+
var resolveAudioMimeType = (detected, declared) => {
|
|
310
|
+
if (_optionalChain([detected, 'optionalAccess', _5 => _5.startsWith, 'call', _6 => _6("audio/")])) {
|
|
311
|
+
return detected;
|
|
312
|
+
}
|
|
313
|
+
const declaredMime = _optionalChain([declared, 'optionalAccess', _7 => _7.split, 'call', _8 => _8(";", 1), 'access', _9 => _9[0], 'access', _10 => _10.trim, 'call', _11 => _11(), 'access', _12 => _12.toLowerCase, 'call', _13 => _13()]);
|
|
314
|
+
if (_optionalChain([declaredMime, 'optionalAccess', _14 => _14.startsWith, 'call', _15 => _15("audio/")])) {
|
|
315
|
+
return declaredMime;
|
|
316
|
+
}
|
|
317
|
+
return _nullishCoalesce((detected && AUDIO_CONTAINER_TYPES.get(detected)), () => ( detected));
|
|
318
|
+
};
|
|
290
319
|
var audioContent = async (input) => {
|
|
291
320
|
let rawData;
|
|
321
|
+
let declaredMimeType = null;
|
|
292
322
|
try {
|
|
293
323
|
if ("url" in input) {
|
|
294
324
|
const timeoutMs = _nullishCoalesce(input.timeoutMs, () => ( MEDIA_FETCH_TIMEOUT_MS));
|
|
@@ -302,6 +332,7 @@ var audioContent = async (input) => {
|
|
|
302
332
|
`Server responded with status: ${response.status} - ${response.statusText}`
|
|
303
333
|
);
|
|
304
334
|
}
|
|
335
|
+
declaredMimeType = response.headers.get("content-type");
|
|
305
336
|
rawData = Buffer.from(await response.arrayBuffer());
|
|
306
337
|
} catch (error) {
|
|
307
338
|
if (error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError")) {
|
|
@@ -329,16 +360,17 @@ var audioContent = async (input) => {
|
|
|
329
360
|
);
|
|
330
361
|
}
|
|
331
362
|
const { fileTypeFromBuffer } = await Promise.resolve().then(() => _interopRequireWildcard(require("file-type")));
|
|
332
|
-
const
|
|
333
|
-
|
|
363
|
+
const detected = await fileTypeFromBuffer(rawData);
|
|
364
|
+
const mimeType = resolveAudioMimeType(_optionalChain([detected, 'optionalAccess', _16 => _16.mime]), declaredMimeType);
|
|
365
|
+
if (!mimeType || !mimeType.startsWith("audio/")) {
|
|
334
366
|
console.warn(
|
|
335
|
-
`Warning: Content may not be a valid audio file. Detected MIME: ${
|
|
367
|
+
`Warning: Content may not be a valid audio file. Detected MIME: ${mimeType || "unknown"}`
|
|
336
368
|
);
|
|
337
369
|
}
|
|
338
370
|
const base64Data = rawData.toString("base64");
|
|
339
371
|
return {
|
|
340
372
|
data: base64Data,
|
|
341
|
-
mimeType: _nullishCoalesce(
|
|
373
|
+
mimeType: _nullishCoalesce(mimeType, () => ( "audio/mpeg")),
|
|
342
374
|
type: "audio"
|
|
343
375
|
};
|
|
344
376
|
} catch (error) {
|
|
@@ -369,7 +401,7 @@ var UserError = class extends UnexpectedStateError {
|
|
|
369
401
|
};
|
|
370
402
|
function assertStandardSchema(toolName, schemaName, schema) {
|
|
371
403
|
const standard = schema["~standard"];
|
|
372
|
-
if (typeof _optionalChain([standard, 'optionalAccess',
|
|
404
|
+
if (typeof _optionalChain([standard, 'optionalAccess', _17 => _17.validate]) === "function") {
|
|
373
405
|
return;
|
|
374
406
|
}
|
|
375
407
|
throw new UserError(
|
|
@@ -486,7 +518,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
486
518
|
*/
|
|
487
519
|
get sessionId() {
|
|
488
520
|
if (this.#sessionId === void 0) {
|
|
489
|
-
const transportSessionId = _optionalChain([this, 'access',
|
|
521
|
+
const transportSessionId = _optionalChain([this, 'access', _18 => _18.#server, 'access', _19 => _19.transport, 'optionalAccess', _20 => _20.sessionId]);
|
|
490
522
|
if (typeof transportSessionId === "string") {
|
|
491
523
|
this.#sessionId = transportSessionId;
|
|
492
524
|
}
|
|
@@ -545,6 +577,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
545
577
|
* to interested clients only.
|
|
546
578
|
*/
|
|
547
579
|
#subscriptions = /* @__PURE__ */ new Set();
|
|
580
|
+
#tools;
|
|
548
581
|
#transportType;
|
|
549
582
|
/**
|
|
550
583
|
* Capabilities this session has already warned about in `#canRefresh`, so a
|
|
@@ -553,6 +586,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
553
586
|
*/
|
|
554
587
|
#unnegotiatedWarnings = /* @__PURE__ */ new Set();
|
|
555
588
|
#utils;
|
|
589
|
+
#visibleTools = [];
|
|
556
590
|
constructor({
|
|
557
591
|
auth,
|
|
558
592
|
authRequired = false,
|
|
@@ -587,6 +621,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
587
621
|
this.#sessionId = sessionId;
|
|
588
622
|
this.#stateless = stateless;
|
|
589
623
|
this.#streamKeepaliveConfig = streamKeepalive;
|
|
624
|
+
this.#tools = tools;
|
|
590
625
|
this.#transportType = transportType;
|
|
591
626
|
this.#needsEventLoopFlush = transportType === "httpStream";
|
|
592
627
|
const supportsTools = _nullishCoalesce(hasTools, () => ( tools.length > 0));
|
|
@@ -620,7 +655,9 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
620
655
|
this.setupRootsHandlers();
|
|
621
656
|
this.setupCompleteHandlers();
|
|
622
657
|
if (supportsTools) {
|
|
623
|
-
this.setupToolHandlers(
|
|
658
|
+
this.setupToolHandlers(
|
|
659
|
+
toolsVisibleTo(tools, this.#auth, this.#authRequired)
|
|
660
|
+
);
|
|
624
661
|
}
|
|
625
662
|
if (resources.length || resourcesTemplates.length) {
|
|
626
663
|
for (const resource of resources) {
|
|
@@ -741,6 +778,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
741
778
|
if (!this.#canRefresh("tools")) {
|
|
742
779
|
return;
|
|
743
780
|
}
|
|
781
|
+
this.#tools = tools;
|
|
744
782
|
this.setupToolHandlers(
|
|
745
783
|
toolsVisibleTo(tools, this.#auth, this.#authRequired)
|
|
746
784
|
);
|
|
@@ -765,6 +803,11 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
765
803
|
*/
|
|
766
804
|
updateAuth(auth) {
|
|
767
805
|
this.#auth = auth;
|
|
806
|
+
const tools = toolsVisibleTo(this.#tools, auth, this.#authRequired);
|
|
807
|
+
if (tools.length !== this.#visibleTools.length || tools.some((tool, index) => tool !== this.#visibleTools[index])) {
|
|
808
|
+
this.setupToolHandlers(tools);
|
|
809
|
+
this.triggerListChangedNotification("notifications/tools/list_changed");
|
|
810
|
+
}
|
|
768
811
|
}
|
|
769
812
|
waitForReady() {
|
|
770
813
|
if (this.isReady) {
|
|
@@ -842,37 +885,37 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
842
885
|
* are tied to a tool call's progress token / streaming notification,
|
|
843
886
|
* which resource and prompt reads do not have.
|
|
844
887
|
*/
|
|
845
|
-
#createLoadContext(meta) {
|
|
888
|
+
#createLoadContext(meta, sendNotification) {
|
|
846
889
|
return {
|
|
847
890
|
client: {
|
|
848
891
|
version: this.#server.getClientVersion()
|
|
849
892
|
},
|
|
850
893
|
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
851
|
-
log: this.#createLog(),
|
|
852
|
-
requestId: typeof _optionalChain([meta, 'optionalAccess',
|
|
894
|
+
log: this.#createLog(sendNotification),
|
|
895
|
+
requestId: typeof _optionalChain([meta, 'optionalAccess', _21 => _21.requestId]) === "string" ? meta.requestId : void 0,
|
|
853
896
|
session: this.#auth,
|
|
854
897
|
sessionId: this.sessionId
|
|
855
898
|
};
|
|
856
899
|
}
|
|
857
|
-
#createLog() {
|
|
900
|
+
#createLog(sendNotification) {
|
|
858
901
|
return {
|
|
859
902
|
debug: (message, context) => {
|
|
860
|
-
this.#sendLog("debug", message, context);
|
|
903
|
+
this.#sendLog(sendNotification, "debug", message, context);
|
|
861
904
|
},
|
|
862
905
|
error: (message, context) => {
|
|
863
|
-
this.#sendLog("error", message, context);
|
|
906
|
+
this.#sendLog(sendNotification, "error", message, context);
|
|
864
907
|
},
|
|
865
908
|
info: (message, context) => {
|
|
866
|
-
this.#sendLog("info", message, context);
|
|
909
|
+
this.#sendLog(sendNotification, "info", message, context);
|
|
867
910
|
},
|
|
868
911
|
warn: (message, context) => {
|
|
869
|
-
this.#sendLog("warning", message, context);
|
|
912
|
+
this.#sendLog(sendNotification, "warning", message, context);
|
|
870
913
|
}
|
|
871
914
|
};
|
|
872
915
|
}
|
|
873
916
|
#formatSchemaIssues(issues) {
|
|
874
|
-
return _optionalChain([this, 'access',
|
|
875
|
-
const path = _optionalChain([issue, 'access',
|
|
917
|
+
return _optionalChain([this, 'access', _22 => _22.#utils, 'optionalAccess', _23 => _23.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
|
|
918
|
+
const path = _optionalChain([issue, 'access', _24 => _24.path, 'optionalAccess', _25 => _25.join, 'call', _26 => _26(".")]) || "root";
|
|
876
919
|
return `${path}: ${issue.message}`;
|
|
877
920
|
}).join(", ");
|
|
878
921
|
}
|
|
@@ -894,7 +937,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
894
937
|
* is bounded and retried, and the result is announced with `rootsChanged`.
|
|
895
938
|
*/
|
|
896
939
|
async #loadRoots(streamableHttp) {
|
|
897
|
-
if (_optionalChain([this, 'access',
|
|
940
|
+
if (_optionalChain([this, 'access', _27 => _27.#rootsConfig, 'optionalAccess', _28 => _28.enabled]) === false || !_optionalChain([this, 'access', _29 => _29.#clientCapabilities, 'optionalAccess', _30 => _30.roots, 'optionalAccess', _31 => _31.listChanged]) || typeof this.#server.listRoots !== "function") {
|
|
898
941
|
return;
|
|
899
942
|
}
|
|
900
943
|
const maxAttempts = streamableHttp ? 5 : 1;
|
|
@@ -904,7 +947,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
904
947
|
void 0,
|
|
905
948
|
streamableHttp ? { timeout: 1e3 } : void 0
|
|
906
949
|
);
|
|
907
|
-
this.#roots = _optionalChain([roots, 'optionalAccess',
|
|
950
|
+
this.#roots = _optionalChain([roots, 'optionalAccess', _32 => _32.roots]) || [];
|
|
908
951
|
if (streamableHttp) {
|
|
909
952
|
this.emit("rootsChanged", { roots: this.#roots });
|
|
910
953
|
}
|
|
@@ -932,22 +975,23 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
|
932
975
|
}
|
|
933
976
|
}
|
|
934
977
|
/**
|
|
935
|
-
*
|
|
978
|
+
* Sending rejects once the client has hung up, and these four
|
|
936
979
|
* callers are synchronous, so the rejection has nowhere to go. Swallow it the
|
|
937
980
|
* way every other notification sender in this class does, or a client that
|
|
938
981
|
* disconnects mid-tool takes the server process down with it.
|
|
939
982
|
*/
|
|
940
|
-
#sendLog(level, message, context) {
|
|
983
|
+
#sendLog(sendNotification, level, message, context) {
|
|
941
984
|
if (this.#loggingLevel && LOGGING_LEVEL_SEVERITY[level] < LOGGING_LEVEL_SEVERITY[this.#loggingLevel]) {
|
|
942
985
|
return;
|
|
943
986
|
}
|
|
944
|
-
|
|
987
|
+
const params = {
|
|
945
988
|
data: {
|
|
946
989
|
context,
|
|
947
990
|
message
|
|
948
991
|
},
|
|
949
992
|
level
|
|
950
|
-
}
|
|
993
|
+
};
|
|
994
|
+
sendNotification({ method: "notifications/message", params }).catch(() => this.#server.sendLoggingMessage(params)).catch((error) => {
|
|
951
995
|
this.#logger.error(
|
|
952
996
|
`[FastMCP error] failed to send ${level} log notification.
|
|
953
997
|
|
|
@@ -1041,7 +1085,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1041
1085
|
*/
|
|
1042
1086
|
#startStreamKeepalive(extra, toolName) {
|
|
1043
1087
|
const config = this.#streamKeepaliveConfig;
|
|
1044
|
-
if (!_optionalChain([config, 'optionalAccess',
|
|
1088
|
+
if (!_optionalChain([config, 'optionalAccess', _33 => _33.enabled])) {
|
|
1045
1089
|
return () => {
|
|
1046
1090
|
};
|
|
1047
1091
|
}
|
|
@@ -1061,9 +1105,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1061
1105
|
);
|
|
1062
1106
|
});
|
|
1063
1107
|
}, intervalMs);
|
|
1064
|
-
_optionalChain([timer, 'access',
|
|
1108
|
+
_optionalChain([timer, 'access', _34 => _34.unref, 'optionalCall', _35 => _35()]);
|
|
1065
1109
|
const stop = () => clearInterval(timer);
|
|
1066
|
-
_optionalChain([extra, 'access',
|
|
1110
|
+
_optionalChain([extra, 'access', _36 => _36.signal, 'optionalAccess', _37 => _37.addEventListener, 'call', _38 => _38("abort", stop, { once: true })]);
|
|
1067
1111
|
return stop;
|
|
1068
1112
|
}
|
|
1069
1113
|
async #validateStructuredContent(tool, value, toolName) {
|
|
@@ -1258,54 +1302,60 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1258
1302
|
prompts: cachedPromptsList
|
|
1259
1303
|
};
|
|
1260
1304
|
});
|
|
1261
|
-
this.#server.setRequestHandler(
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
`Unknown prompt: ${request.params.name}`
|
|
1267
|
-
);
|
|
1268
|
-
}
|
|
1269
|
-
const args = request.params.arguments;
|
|
1270
|
-
for (const arg of _nullishCoalesce(prompt.arguments, () => ( []))) {
|
|
1271
|
-
if (arg.required && !(args && Object.hasOwn(args, arg.name))) {
|
|
1305
|
+
this.#server.setRequestHandler(
|
|
1306
|
+
_typesjs.GetPromptRequestSchema,
|
|
1307
|
+
async (request, extra) => {
|
|
1308
|
+
const prompt = this.#prompts.get(request.params.name);
|
|
1309
|
+
if (!prompt) {
|
|
1272
1310
|
throw new (0, _typesjs.McpError)(
|
|
1273
1311
|
_typesjs.ErrorCode.InvalidParams,
|
|
1274
|
-
`
|
|
1312
|
+
`Unknown prompt: ${request.params.name}`
|
|
1275
1313
|
);
|
|
1276
1314
|
}
|
|
1315
|
+
const args = request.params.arguments;
|
|
1316
|
+
for (const arg of _nullishCoalesce(prompt.arguments, () => ( []))) {
|
|
1317
|
+
if (arg.required && !(args && Object.hasOwn(args, arg.name))) {
|
|
1318
|
+
throw new (0, _typesjs.McpError)(
|
|
1319
|
+
_typesjs.ErrorCode.InvalidParams,
|
|
1320
|
+
`Prompt '${request.params.name}' requires argument '${arg.name}': ${arg.description || "No description provided"}`
|
|
1321
|
+
);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
let result;
|
|
1325
|
+
try {
|
|
1326
|
+
result = await prompt.load(
|
|
1327
|
+
_nullishCoalesce(args, () => ( {})),
|
|
1328
|
+
this.#auth,
|
|
1329
|
+
this.#createLoadContext(
|
|
1330
|
+
_optionalChain([request, 'access', _39 => _39.params, 'optionalAccess', _40 => _40._meta]),
|
|
1331
|
+
extra.sendNotification
|
|
1332
|
+
)
|
|
1333
|
+
);
|
|
1334
|
+
} catch (error) {
|
|
1335
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1336
|
+
throw new (0, _typesjs.McpError)(
|
|
1337
|
+
_typesjs.ErrorCode.InternalError,
|
|
1338
|
+
`Failed to load prompt '${request.params.name}': ${errorMessage}`
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
if (typeof result === "string") {
|
|
1342
|
+
return {
|
|
1343
|
+
description: prompt.description,
|
|
1344
|
+
messages: [
|
|
1345
|
+
{
|
|
1346
|
+
content: { text: result, type: "text" },
|
|
1347
|
+
role: "user"
|
|
1348
|
+
}
|
|
1349
|
+
]
|
|
1350
|
+
};
|
|
1351
|
+
} else {
|
|
1352
|
+
return {
|
|
1353
|
+
description: prompt.description,
|
|
1354
|
+
messages: result.messages
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1277
1357
|
}
|
|
1278
|
-
|
|
1279
|
-
try {
|
|
1280
|
-
result = await prompt.load(
|
|
1281
|
-
_nullishCoalesce(args, () => ( {})),
|
|
1282
|
-
this.#auth,
|
|
1283
|
-
this.#createLoadContext(_optionalChain([request, 'access', _30 => _30.params, 'optionalAccess', _31 => _31._meta]))
|
|
1284
|
-
);
|
|
1285
|
-
} catch (error) {
|
|
1286
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1287
|
-
throw new (0, _typesjs.McpError)(
|
|
1288
|
-
_typesjs.ErrorCode.InternalError,
|
|
1289
|
-
`Failed to load prompt '${request.params.name}': ${errorMessage}`
|
|
1290
|
-
);
|
|
1291
|
-
}
|
|
1292
|
-
if (typeof result === "string") {
|
|
1293
|
-
return {
|
|
1294
|
-
description: prompt.description,
|
|
1295
|
-
messages: [
|
|
1296
|
-
{
|
|
1297
|
-
content: { text: result, type: "text" },
|
|
1298
|
-
role: "user"
|
|
1299
|
-
}
|
|
1300
|
-
]
|
|
1301
|
-
};
|
|
1302
|
-
} else {
|
|
1303
|
-
return {
|
|
1304
|
-
description: prompt.description,
|
|
1305
|
-
messages: result.messages
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1358
|
+
);
|
|
1309
1359
|
}
|
|
1310
1360
|
setupResourceHandlers() {
|
|
1311
1361
|
let cachedResourcesList = null;
|
|
@@ -1329,7 +1379,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1329
1379
|
});
|
|
1330
1380
|
this.#server.setRequestHandler(
|
|
1331
1381
|
_typesjs.ReadResourceRequestSchema,
|
|
1332
|
-
async (request) => {
|
|
1382
|
+
async (request, extra) => {
|
|
1333
1383
|
if ("uri" in request.params) {
|
|
1334
1384
|
const resource = this.#resources.get(request.params.uri);
|
|
1335
1385
|
if (!resource) {
|
|
@@ -1345,7 +1395,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1345
1395
|
const result = await resourceTemplate.load(
|
|
1346
1396
|
match,
|
|
1347
1397
|
this.#auth,
|
|
1348
|
-
this.#createLoadContext(
|
|
1398
|
+
this.#createLoadContext(
|
|
1399
|
+
_optionalChain([request, 'access', _41 => _41.params, 'optionalAccess', _42 => _42._meta]),
|
|
1400
|
+
extra.sendNotification
|
|
1401
|
+
)
|
|
1349
1402
|
);
|
|
1350
1403
|
const resources = Array.isArray(result) ? result : [result];
|
|
1351
1404
|
return {
|
|
@@ -1371,7 +1424,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1371
1424
|
try {
|
|
1372
1425
|
maybeArrayResult = await resource.load(
|
|
1373
1426
|
this.#auth,
|
|
1374
|
-
this.#createLoadContext(
|
|
1427
|
+
this.#createLoadContext(
|
|
1428
|
+
_optionalChain([request, 'access', _43 => _43.params, 'optionalAccess', _44 => _44._meta]),
|
|
1429
|
+
extra.sendNotification
|
|
1430
|
+
)
|
|
1375
1431
|
);
|
|
1376
1432
|
} catch (error) {
|
|
1377
1433
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1434,7 +1490,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1434
1490
|
);
|
|
1435
1491
|
}
|
|
1436
1492
|
setupRootsHandlers() {
|
|
1437
|
-
if (_optionalChain([this, 'access',
|
|
1493
|
+
if (_optionalChain([this, 'access', _45 => _45.#rootsConfig, 'optionalAccess', _46 => _46.enabled]) === false) {
|
|
1438
1494
|
this.#logger.debug(
|
|
1439
1495
|
"[FastMCP debug] roots capability explicitly disabled via config"
|
|
1440
1496
|
);
|
|
@@ -1471,6 +1527,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1471
1527
|
}
|
|
1472
1528
|
}
|
|
1473
1529
|
setupToolHandlers(tools) {
|
|
1530
|
+
this.#visibleTools = tools;
|
|
1474
1531
|
const toolsMap = new Map(tools.map((tool) => [tool.name, tool]));
|
|
1475
1532
|
let cachedToolsList = null;
|
|
1476
1533
|
this.#server.setRequestHandler(_typesjs.ListToolsRequestSchema, async () => {
|
|
@@ -1528,7 +1585,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1528
1585
|
}
|
|
1529
1586
|
args = parsed.value;
|
|
1530
1587
|
}
|
|
1531
|
-
const progressToken = _optionalChain([request, 'access',
|
|
1588
|
+
const progressToken = _optionalChain([request, 'access', _47 => _47.params, 'optionalAccess', _48 => _48._meta, 'optionalAccess', _49 => _49.progressToken]);
|
|
1532
1589
|
let result;
|
|
1533
1590
|
try {
|
|
1534
1591
|
const reportProgress = async (progress) => {
|
|
@@ -1553,7 +1610,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1553
1610
|
);
|
|
1554
1611
|
}
|
|
1555
1612
|
};
|
|
1556
|
-
const log = this.#createLog();
|
|
1613
|
+
const log = this.#createLog(extra.sendNotification);
|
|
1557
1614
|
const streamContent = async (content) => {
|
|
1558
1615
|
const contentArray = Array.isArray(content) ? content : [content];
|
|
1559
1616
|
try {
|
|
@@ -1596,7 +1653,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1596
1653
|
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
1597
1654
|
log,
|
|
1598
1655
|
reportProgress,
|
|
1599
|
-
requestId: typeof _optionalChain([request, 'access',
|
|
1656
|
+
requestId: typeof _optionalChain([request, 'access', _50 => _50.params, 'optionalAccess', _51 => _51._meta, 'optionalAccess', _52 => _52.requestId]) === "string" ? request.params._meta.requestId : void 0,
|
|
1600
1657
|
session: this.#auth,
|
|
1601
1658
|
sessionId: this.sessionId,
|
|
1602
1659
|
signal,
|
|
@@ -1738,7 +1795,7 @@ function normalizePath(path) {
|
|
|
1738
1795
|
return path.startsWith("/") ? path : `/${path}`;
|
|
1739
1796
|
}
|
|
1740
1797
|
function parseBasicAuthHeader(authHeader) {
|
|
1741
|
-
const basicMatch = _optionalChain([authHeader, 'optionalAccess',
|
|
1798
|
+
const basicMatch = _optionalChain([authHeader, 'optionalAccess', _53 => _53.match, 'call', _54 => _54(/^Basic\s+(.+)$/)]);
|
|
1742
1799
|
if (!basicMatch) return null;
|
|
1743
1800
|
try {
|
|
1744
1801
|
const credentials = Buffer.from(basicMatch[1], "base64").toString("utf-8");
|
|
@@ -2217,7 +2274,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2217
2274
|
roots: this.#options.roots,
|
|
2218
2275
|
streamKeepalive: this.#options.streamKeepalive,
|
|
2219
2276
|
title: this.#options.title,
|
|
2220
|
-
tools:
|
|
2277
|
+
tools: this.#tools,
|
|
2221
2278
|
transportType: "stdio",
|
|
2222
2279
|
utils: this.#options.utils,
|
|
2223
2280
|
version: this.#options.version,
|
|
@@ -2384,9 +2441,9 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2384
2441
|
const originalOnClose = transport.onclose;
|
|
2385
2442
|
transport.onclose = () => {
|
|
2386
2443
|
closed = true;
|
|
2387
|
-
_optionalChain([onClose, 'optionalCall',
|
|
2444
|
+
_optionalChain([onClose, 'optionalCall', _55 => _55()]);
|
|
2388
2445
|
this.#removeSession(session);
|
|
2389
|
-
_optionalChain([originalOnClose, 'optionalCall',
|
|
2446
|
+
_optionalChain([originalOnClose, 'optionalCall', _56 => _56()]);
|
|
2390
2447
|
};
|
|
2391
2448
|
await session.connect(transport);
|
|
2392
2449
|
if (closed) {
|
|
@@ -2428,7 +2485,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2428
2485
|
stateless,
|
|
2429
2486
|
streamKeepalive: this.#options.streamKeepalive,
|
|
2430
2487
|
title: this.#options.title,
|
|
2431
|
-
tools:
|
|
2488
|
+
tools: this.#tools,
|
|
2432
2489
|
transportType: "httpStream",
|
|
2433
2490
|
utils: this.#options.utils,
|
|
2434
2491
|
version: this.#options.version,
|
|
@@ -2450,7 +2507,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2450
2507
|
*/
|
|
2451
2508
|
#createUnauthorizedResponse(message) {
|
|
2452
2509
|
const oauth = this.#options.oauth;
|
|
2453
|
-
const resource = _optionalChain([oauth, 'optionalAccess',
|
|
2510
|
+
const resource = _optionalChain([oauth, 'optionalAccess', _57 => _57.enabled]) ? _optionalChain([oauth, 'access', _58 => _58.protectedResource, 'optionalAccess', _59 => _59.resource]) : void 0;
|
|
2454
2511
|
const wwwAuthenticateParts = [
|
|
2455
2512
|
'error="invalid_token"',
|
|
2456
2513
|
`error_description="${message.replace(/"/g, '\\"')}"`
|
|
@@ -2589,7 +2646,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2589
2646
|
}
|
|
2590
2647
|
}
|
|
2591
2648
|
const oauthConfig = this.#options.oauth;
|
|
2592
|
-
if (_optionalChain([oauthConfig, 'optionalAccess',
|
|
2649
|
+
if (_optionalChain([oauthConfig, 'optionalAccess', _60 => _60.enabled]) && req.method === "GET") {
|
|
2593
2650
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2594
2651
|
const authorizationServerMetadataPath = joinPaths(
|
|
2595
2652
|
"",
|
|
@@ -2623,8 +2680,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2623
2680
|
}
|
|
2624
2681
|
}
|
|
2625
2682
|
}
|
|
2626
|
-
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess',
|
|
2627
|
-
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess',
|
|
2683
|
+
const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _61 => _61.proxy]);
|
|
2684
|
+
if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _62 => _62.enabled])) {
|
|
2628
2685
|
const url2 = new URL(req.url || "", `http://${host}`);
|
|
2629
2686
|
const oauthPath = basePathRelativePath;
|
|
2630
2687
|
try {
|
|
@@ -2677,7 +2734,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2677
2734
|
const statusCode = error.statusCode || 400;
|
|
2678
2735
|
res.writeHead(statusCode, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(
|
|
2679
2736
|
JSON.stringify(
|
|
2680
|
-
_optionalChain([error, 'access',
|
|
2737
|
+
_optionalChain([error, 'access', _63 => _63.toJSON, 'optionalCall', _64 => _64()]) || {
|
|
2681
2738
|
error: "invalid_request"
|
|
2682
2739
|
}
|
|
2683
2740
|
)
|
|
@@ -2704,7 +2761,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2704
2761
|
} catch (error) {
|
|
2705
2762
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2706
2763
|
JSON.stringify(
|
|
2707
|
-
_optionalChain([error, 'access',
|
|
2764
|
+
_optionalChain([error, 'access', _65 => _65.toJSON, 'optionalCall', _66 => _66()]) || {
|
|
2708
2765
|
error: "invalid_request"
|
|
2709
2766
|
}
|
|
2710
2767
|
)
|
|
@@ -2726,7 +2783,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2726
2783
|
} catch (error) {
|
|
2727
2784
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2728
2785
|
JSON.stringify(
|
|
2729
|
-
_optionalChain([error, 'access',
|
|
2786
|
+
_optionalChain([error, 'access', _67 => _67.toJSON, 'optionalCall', _68 => _68()]) || {
|
|
2730
2787
|
error: "server_error"
|
|
2731
2788
|
}
|
|
2732
2789
|
)
|
|
@@ -2795,7 +2852,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2795
2852
|
} catch (error) {
|
|
2796
2853
|
res.writeHead(400, { "Content-Type": "application/json" }).end(
|
|
2797
2854
|
JSON.stringify(
|
|
2798
|
-
_optionalChain([error, 'access',
|
|
2855
|
+
_optionalChain([error, 'access', _69 => _69.toJSON, 'optionalCall', _70 => _70()]) || {
|
|
2799
2856
|
error: "server_error"
|
|
2800
2857
|
}
|
|
2801
2858
|
)
|
|
@@ -2853,8 +2910,8 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2853
2910
|
const basicAuth = parseBasicAuthHeader(
|
|
2854
2911
|
req.headers.authorization
|
|
2855
2912
|
);
|
|
2856
|
-
const clientId = _optionalChain([basicAuth, 'optionalAccess',
|
|
2857
|
-
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess',
|
|
2913
|
+
const clientId = _optionalChain([basicAuth, 'optionalAccess', _71 => _71.clientId]) || params.get("client_id") || "";
|
|
2914
|
+
const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _72 => _72.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
|
|
2858
2915
|
let response;
|
|
2859
2916
|
if (grantType === "authorization_code") {
|
|
2860
2917
|
response = await oauthProxy.exchangeAuthorizationCode({
|
|
@@ -2884,7 +2941,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2884
2941
|
const statusCode = error.statusCode || 400;
|
|
2885
2942
|
res.writeHead(statusCode, OAUTH_CREDENTIAL_RESPONSE_HEADERS).end(
|
|
2886
2943
|
JSON.stringify(
|
|
2887
|
-
_optionalChain([error, 'access',
|
|
2944
|
+
_optionalChain([error, 'access', _73 => _73.toJSON, 'optionalCall', _74 => _74()]) || {
|
|
2888
2945
|
error: "invalid_request"
|
|
2889
2946
|
}
|
|
2890
2947
|
)
|
|
@@ -2910,7 +2967,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2910
2967
|
* regardless (RFC 7235), so no config is needed just to get the header.
|
|
2911
2968
|
*/
|
|
2912
2969
|
#httpStreamOAuthConfig() {
|
|
2913
|
-
const resource = _optionalChain([this, 'access',
|
|
2970
|
+
const resource = _optionalChain([this, 'access', _75 => _75.#options, 'access', _76 => _76.oauth, 'optionalAccess', _77 => _77.enabled]) ? _optionalChain([this, 'access', _78 => _78.#options, 'access', _79 => _79.oauth, 'access', _80 => _80.protectedResource, 'optionalAccess', _81 => _81.resource]) : void 0;
|
|
2914
2971
|
if (!resource) {
|
|
2915
2972
|
return {};
|
|
2916
2973
|
}
|
|
@@ -3018,24 +3075,24 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3018
3075
|
const envBasePath = process.env.FASTMCP_BASE_PATH;
|
|
3019
3076
|
const envStateless = process.env.FASTMCP_STATELESS;
|
|
3020
3077
|
const envHost = process.env.FASTMCP_HOST;
|
|
3021
|
-
const transportType = _optionalChain([overrides, 'optionalAccess',
|
|
3078
|
+
const transportType = _optionalChain([overrides, 'optionalAccess', _82 => _82.transportType]) || parseTransportSetting(transportArg, "--transport") || parseTransportSetting(envTransport, "FASTMCP_TRANSPORT") || "stdio";
|
|
3022
3079
|
if (transportType === "httpStream") {
|
|
3023
3080
|
const port = parseInt(
|
|
3024
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
3081
|
+
_optionalChain([overrides, 'optionalAccess', _83 => _83.httpStream, 'optionalAccess', _84 => _84.port, 'optionalAccess', _85 => _85.toString, 'call', _86 => _86()]) || portArg || envPort || "8080"
|
|
3025
3082
|
);
|
|
3026
|
-
const host = _optionalChain([overrides, 'optionalAccess',
|
|
3027
|
-
const endpoint = _optionalChain([overrides, 'optionalAccess',
|
|
3083
|
+
const host = _optionalChain([overrides, 'optionalAccess', _87 => _87.httpStream, 'optionalAccess', _88 => _88.host]) || hostArg || envHost || "localhost";
|
|
3084
|
+
const endpoint = _optionalChain([overrides, 'optionalAccess', _89 => _89.httpStream, 'optionalAccess', _90 => _90.endpoint]) || endpointArg || envEndpoint || "/mcp";
|
|
3028
3085
|
const basePath = normalizeBasePath(
|
|
3029
|
-
_optionalChain([overrides, 'optionalAccess',
|
|
3086
|
+
_optionalChain([overrides, 'optionalAccess', _91 => _91.httpStream, 'optionalAccess', _92 => _92.basePath]) || basePathArg || envBasePath
|
|
3030
3087
|
);
|
|
3031
|
-
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess',
|
|
3032
|
-
const stateless = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([overrides, 'optionalAccess',
|
|
3088
|
+
const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _93 => _93.httpStream, 'optionalAccess', _94 => _94.enableJsonResponse]) || false;
|
|
3089
|
+
const stateless = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _95 => _95.httpStream, 'optionalAccess', _96 => _96.stateless]), () => ( // A bare `--stateless` means `--stateless true`.
|
|
3033
3090
|
(statelessArg === "" ? true : parseBooleanSetting(statelessArg, "--stateless")))), () => ( parseBooleanSetting(envStateless, "FASTMCP_STATELESS"))), () => ( false));
|
|
3034
|
-
const cors = _optionalChain([overrides, 'optionalAccess',
|
|
3035
|
-
const eventStore = _optionalChain([overrides, 'optionalAccess',
|
|
3036
|
-
const sslCa = _optionalChain([overrides, 'optionalAccess',
|
|
3037
|
-
const sslCert = _optionalChain([overrides, 'optionalAccess',
|
|
3038
|
-
const sslKey = _optionalChain([overrides, 'optionalAccess',
|
|
3091
|
+
const cors = _optionalChain([overrides, 'optionalAccess', _97 => _97.httpStream, 'optionalAccess', _98 => _98.cors]);
|
|
3092
|
+
const eventStore = _optionalChain([overrides, 'optionalAccess', _99 => _99.httpStream, 'optionalAccess', _100 => _100.eventStore]);
|
|
3093
|
+
const sslCa = _optionalChain([overrides, 'optionalAccess', _101 => _101.httpStream, 'optionalAccess', _102 => _102.sslCa]);
|
|
3094
|
+
const sslCert = _optionalChain([overrides, 'optionalAccess', _103 => _103.httpStream, 'optionalAccess', _104 => _104.sslCert]);
|
|
3095
|
+
const sslKey = _optionalChain([overrides, 'optionalAccess', _105 => _105.httpStream, 'optionalAccess', _106 => _106.sslKey]);
|
|
3039
3096
|
return {
|
|
3040
3097
|
httpStream: {
|
|
3041
3098
|
basePath,
|
|
@@ -3127,7 +3184,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3127
3184
|
*/
|
|
3128
3185
|
#useEndpointAsResource(endpoint) {
|
|
3129
3186
|
const oauth = this.#options.oauth;
|
|
3130
|
-
if (this.#providerResourceBase === void 0 || !_optionalChain([oauth, 'optionalAccess',
|
|
3187
|
+
if (this.#providerResourceBase === void 0 || !_optionalChain([oauth, 'optionalAccess', _107 => _107.protectedResource]))
|
|
3131
3188
|
return;
|
|
3132
3189
|
this.#options = {
|
|
3133
3190
|
...this.#options,
|
|
@@ -3156,4 +3213,4 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3156
3213
|
|
|
3157
3214
|
|
|
3158
3215
|
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;
|
|
3159
|
-
//# sourceMappingURL=chunk-
|
|
3216
|
+
//# sourceMappingURL=chunk-2PXF6JQB.cjs.map
|