fastmcp 4.21.0 → 4.21.2
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 +11 -4
- package/dist/FastMCP.cjs +3 -2
- package/dist/FastMCP.cjs.map +1 -1
- package/dist/FastMCP.d.cts +7 -1
- package/dist/FastMCP.d.ts +7 -1
- package/dist/FastMCP.js +2 -1
- package/dist/bin/fastmcp.cjs +63 -13
- package/dist/bin/fastmcp.cjs.map +1 -1
- package/dist/bin/fastmcp.js +69 -19
- package/dist/bin/fastmcp.js.map +1 -1
- package/dist/{chunk-J5E7VICR.cjs → chunk-C5VOVQPC.cjs} +40 -33
- package/dist/chunk-C5VOVQPC.cjs.map +1 -0
- package/dist/chunk-O22SYZMC.cjs +22 -0
- package/dist/chunk-O22SYZMC.cjs.map +1 -0
- package/dist/{chunk-XQ2CLYB3.js → chunk-QMRS4ZLD.js} +39 -32
- package/dist/chunk-QMRS4ZLD.js.map +1 -0
- package/dist/chunk-UMDUIBFW.js +22 -0
- package/dist/chunk-UMDUIBFW.js.map +1 -0
- package/dist/edge/index.cjs +7 -4
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.js +6 -3
- package/dist/edge/index.js.map +1 -1
- package/dist/examples/custom-routes.cjs +3 -2
- package/dist/examples/custom-routes.cjs.map +1 -1
- package/dist/examples/custom-routes.js +2 -1
- package/dist/examples/custom-routes.js.map +1 -1
- package/dist/openapi/index.cjs +6 -5
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.js +2 -1
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-J5E7VICR.cjs.map +0 -1
- package/dist/chunk-XQ2CLYB3.js.map +0 -1
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var _chunkGTPK7A57cjs = require('./chunk-GTPK7A57.cjs');
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
var _chunkO22SYZMCcjs = require('./chunk-O22SYZMC.cjs');
|
|
7
|
+
|
|
5
8
|
// src/FastMCP.ts
|
|
6
9
|
var _indexjs = require('@modelcontextprotocol/sdk/server/index.js');
|
|
7
10
|
var _stdiojs = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
@@ -376,21 +379,6 @@ function assertToolSchemas(tool) {
|
|
|
376
379
|
assertStandardSchema(tool.name, "outputSchema", tool.outputSchema);
|
|
377
380
|
}
|
|
378
381
|
}
|
|
379
|
-
function strictInputSchema(schema) {
|
|
380
|
-
const isDictionary = typeof schema.additionalProperties === "object" && Object.keys(_nullishCoalesce(schema.properties, () => ( {}))).length === 0;
|
|
381
|
-
return {
|
|
382
|
-
...schema,
|
|
383
|
-
additionalProperties: isDictionary ? schema.additionalProperties : false,
|
|
384
|
-
...schema.properties && {
|
|
385
|
-
properties: Object.fromEntries(
|
|
386
|
-
Object.entries(schema.properties).map(([key, value]) => [
|
|
387
|
-
key,
|
|
388
|
-
typeof value === "object" && value.type === "object" ? strictInputSchema(value) : value
|
|
389
|
-
])
|
|
390
|
-
)
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
382
|
var STREAM_KEEPALIVE_LOGGER = "fastmcp-keepalive";
|
|
395
383
|
var STREAM_KEEPALIVE_DEFAULT_INTERVAL_MS = 2e4;
|
|
396
384
|
var TextContentZodSchema = _zod.z.object({
|
|
@@ -537,6 +525,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
537
525
|
*/
|
|
538
526
|
#abortController = new AbortController();
|
|
539
527
|
#auth;
|
|
528
|
+
#authRequired;
|
|
540
529
|
#capabilities = {};
|
|
541
530
|
#clientCapabilities;
|
|
542
531
|
#connectionState = "connecting";
|
|
@@ -575,6 +564,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
575
564
|
#utils;
|
|
576
565
|
constructor({
|
|
577
566
|
auth,
|
|
567
|
+
authRequired = false,
|
|
578
568
|
hasTools,
|
|
579
569
|
icons,
|
|
580
570
|
instructions,
|
|
@@ -598,6 +588,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
598
588
|
}) {
|
|
599
589
|
super();
|
|
600
590
|
this.#auth = auth;
|
|
591
|
+
this.#authRequired = authRequired;
|
|
601
592
|
this.#logger = logger;
|
|
602
593
|
this.#onToolCall = onToolCall;
|
|
603
594
|
this.#pingConfig = ping;
|
|
@@ -804,10 +795,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
804
795
|
}
|
|
805
796
|
}
|
|
806
797
|
toolsListChanged(tools) {
|
|
807
|
-
|
|
808
|
-
(
|
|
809
|
-
)
|
|
810
|
-
this.setupToolHandlers(allowedTools);
|
|
798
|
+
this.setupToolHandlers(
|
|
799
|
+
toolsVisibleTo(tools, this.#auth, this.#authRequired)
|
|
800
|
+
);
|
|
811
801
|
this.triggerListChangedNotification("notifications/tools/list_changed");
|
|
812
802
|
}
|
|
813
803
|
async triggerListChangedNotification(method) {
|
|
@@ -1070,9 +1060,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1070
1060
|
const ref = request.params.ref;
|
|
1071
1061
|
const prompt = "name" in ref && this.#prompts.get(ref.name);
|
|
1072
1062
|
if (!prompt) {
|
|
1073
|
-
throw new
|
|
1074
|
-
|
|
1075
|
-
|
|
1063
|
+
throw new (0, _typesjs.McpError)(
|
|
1064
|
+
_typesjs.ErrorCode.InvalidParams,
|
|
1065
|
+
`Unknown prompt: ${ref.name}`
|
|
1066
|
+
);
|
|
1076
1067
|
}
|
|
1077
1068
|
if (!prompt.complete) {
|
|
1078
1069
|
throw new UnexpectedStateError("Prompt does not support completion", {
|
|
@@ -1098,9 +1089,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1098
1089
|
(resource2) => resource2.uriTemplate === ref.uri
|
|
1099
1090
|
);
|
|
1100
1091
|
if (!resource) {
|
|
1101
|
-
throw new
|
|
1102
|
-
|
|
1103
|
-
|
|
1092
|
+
throw new (0, _typesjs.McpError)(
|
|
1093
|
+
_typesjs.ErrorCode.InvalidParams,
|
|
1094
|
+
`Unknown resource template: ${ref.uri}`
|
|
1095
|
+
);
|
|
1104
1096
|
}
|
|
1105
1097
|
if (!("uriTemplate" in resource)) {
|
|
1106
1098
|
throw new UnexpectedStateError("Unexpected resource");
|
|
@@ -1169,7 +1161,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1169
1161
|
const prompt = this.#prompts.get(request.params.name);
|
|
1170
1162
|
if (!prompt) {
|
|
1171
1163
|
throw new (0, _typesjs.McpError)(
|
|
1172
|
-
_typesjs.ErrorCode.
|
|
1164
|
+
_typesjs.ErrorCode.InvalidParams,
|
|
1173
1165
|
`Unknown prompt: ${request.params.name}`
|
|
1174
1166
|
);
|
|
1175
1167
|
}
|
|
@@ -1390,7 +1382,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1390
1382
|
return {
|
|
1391
1383
|
annotations: tool.annotations,
|
|
1392
1384
|
description: tool.description,
|
|
1393
|
-
inputSchema: tool.parameters ? strictInputSchema(await _xsschema.toJsonSchema.call(void 0, tool.parameters)) : {
|
|
1385
|
+
inputSchema: tool.parameters ? _chunkO22SYZMCcjs.strictInputSchema.call(void 0, await _xsschema.toJsonSchema.call(void 0, tool.parameters)) : {
|
|
1394
1386
|
additionalProperties: false,
|
|
1395
1387
|
properties: {},
|
|
1396
1388
|
type: "object"
|
|
@@ -1648,6 +1640,14 @@ function stripBasePath(path, basePath) {
|
|
|
1648
1640
|
}
|
|
1649
1641
|
return null;
|
|
1650
1642
|
}
|
|
1643
|
+
function toolsVisibleTo(tools, auth, authRequired) {
|
|
1644
|
+
if (auth) {
|
|
1645
|
+
return tools.filter(
|
|
1646
|
+
(tool) => tool.canAccess ? tool.canAccess(auth) : true
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
return authRequired ? tools.filter((tool) => !tool.canAccess) : tools;
|
|
1650
|
+
}
|
|
1651
1651
|
var FastMCPEventEmitterBase = _events.EventEmitter;
|
|
1652
1652
|
var FastMCPEventEmitter = class extends FastMCPEventEmitterBase {
|
|
1653
1653
|
};
|
|
@@ -2027,6 +2027,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2027
2027
|
if (config.transportType === "stdio") {
|
|
2028
2028
|
const transport = new (0, _stdiojs.StdioServerTransport)();
|
|
2029
2029
|
let auth;
|
|
2030
|
+
const authRequired = this.#authenticate !== void 0;
|
|
2030
2031
|
if (this.#authenticate) {
|
|
2031
2032
|
try {
|
|
2032
2033
|
auth = await _asyncNullishCoalesce(await this.#authenticate(
|
|
@@ -2038,9 +2039,16 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2038
2039
|
error instanceof Error ? error.message : String(error)
|
|
2039
2040
|
);
|
|
2040
2041
|
}
|
|
2042
|
+
if (!auth && this.#tools.some((tool) => tool.canAccess)) {
|
|
2043
|
+
this.#logger.warn(
|
|
2044
|
+
"[FastMCP warning] The stdio session has no auth, so tools gated by canAccess are hidden from it."
|
|
2045
|
+
);
|
|
2046
|
+
}
|
|
2041
2047
|
}
|
|
2042
2048
|
const session = new FastMCPSession({
|
|
2043
2049
|
auth,
|
|
2050
|
+
authRequired,
|
|
2051
|
+
hasTools: this.#tools.length > 0,
|
|
2044
2052
|
icons: this.#options.icons,
|
|
2045
2053
|
instructions: this.#options.instructions,
|
|
2046
2054
|
logger: this.#logger,
|
|
@@ -2053,7 +2061,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2053
2061
|
roots: this.#options.roots,
|
|
2054
2062
|
streamKeepalive: this.#options.streamKeepalive,
|
|
2055
2063
|
title: this.#options.title,
|
|
2056
|
-
tools: this.#tools,
|
|
2064
|
+
tools: toolsVisibleTo(this.#tools, auth, authRequired),
|
|
2057
2065
|
transportType: "stdio",
|
|
2058
2066
|
utils: this.#options.utils,
|
|
2059
2067
|
version: this.#options.version,
|
|
@@ -2223,11 +2231,10 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2223
2231
|
const errorMessage = "error" in auth && typeof auth.error === "string" ? auth.error : "Authentication failed";
|
|
2224
2232
|
throw this.#createUnauthorizedResponse(errorMessage);
|
|
2225
2233
|
}
|
|
2226
|
-
const
|
|
2227
|
-
(tool) => tool.canAccess ? tool.canAccess(auth) : true
|
|
2228
|
-
) : this.#tools;
|
|
2234
|
+
const authRequired = this.#authenticate !== void 0;
|
|
2229
2235
|
return new FastMCPSession({
|
|
2230
2236
|
auth,
|
|
2237
|
+
authRequired,
|
|
2231
2238
|
hasTools: this.#tools.length > 0,
|
|
2232
2239
|
icons: this.#options.icons,
|
|
2233
2240
|
instructions: this.#options.instructions,
|
|
@@ -2243,7 +2250,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2243
2250
|
stateless,
|
|
2244
2251
|
streamKeepalive: this.#options.streamKeepalive,
|
|
2245
2252
|
title: this.#options.title,
|
|
2246
|
-
tools:
|
|
2253
|
+
tools: toolsVisibleTo(this.#tools, auth, authRequired),
|
|
2247
2254
|
transportType: "httpStream",
|
|
2248
2255
|
utils: this.#options.utils,
|
|
2249
2256
|
version: this.#options.version,
|
|
@@ -2939,4 +2946,4 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
2939
2946
|
|
|
2940
2947
|
|
|
2941
2948
|
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;
|
|
2942
|
-
//# sourceMappingURL=chunk-
|
|
2949
|
+
//# sourceMappingURL=chunk-C5VOVQPC.cjs.map
|