fastmcp 4.22.6 → 4.22.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FastMCP.cjs +2 -2
- package/dist/FastMCP.js +1 -1
- package/dist/{chunk-QJIFKZYZ.cjs → chunk-44X25GBU.cjs} +141 -73
- package/dist/chunk-44X25GBU.cjs.map +1 -0
- package/dist/{chunk-OAM6AYJY.js → chunk-76QWMCYJ.js} +138 -70
- package/dist/chunk-76QWMCYJ.js.map +1 -0
- package/dist/edge/index.cjs +9 -0
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.js +9 -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 +28 -16
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.js +19 -7
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-OAM6AYJY.js.map +0 -1
- package/dist/chunk-QJIFKZYZ.cjs.map +0 -1
package/dist/FastMCP.cjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunk44X25GBUcjs = require('./chunk-44X25GBU.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -50,5 +50,5 @@ require('./chunk-O22SYZMC.cjs');
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
exports.AuthProvider = _chunkYLLBANV4cjs.AuthProvider; exports.AzureProvider = _chunkYLLBANV4cjs.AzureProvider; exports.DiscoveryDocumentCache =
|
|
53
|
+
exports.AuthProvider = _chunkYLLBANV4cjs.AuthProvider; exports.AzureProvider = _chunkYLLBANV4cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunk44X25GBUcjs.DiscoveryDocumentCache; exports.FastMCP = _chunk44X25GBUcjs.FastMCP; exports.FastMCPError = _chunk44X25GBUcjs.FastMCPError; exports.FastMCPSession = _chunk44X25GBUcjs.FastMCPSession; exports.GitHubProvider = _chunkYLLBANV4cjs.GitHubProvider; exports.GoogleProvider = _chunkYLLBANV4cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunk44X25GBUcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkYLLBANV4cjs.OAuthProvider; exports.ServerState = _chunk44X25GBUcjs.ServerState; exports.SessionError = _chunk44X25GBUcjs.SessionError; exports.UnexpectedStateError = _chunk44X25GBUcjs.UnexpectedStateError; exports.UserError = _chunk44X25GBUcjs.UserError; exports.audioContent = _chunk44X25GBUcjs.audioContent; exports.getAuthSession = _chunkYLLBANV4cjs.getAuthSession; exports.imageContent = _chunk44X25GBUcjs.imageContent; exports.jsonSchemaAdapter = _chunk44X25GBUcjs.jsonSchemaAdapter; exports.requireAll = _chunkYLLBANV4cjs.requireAll; exports.requireAny = _chunkYLLBANV4cjs.requireAny; exports.requireAuth = _chunkYLLBANV4cjs.requireAuth; exports.requireRole = _chunkYLLBANV4cjs.requireRole; exports.requireScopes = _chunkYLLBANV4cjs.requireScopes;
|
|
54
54
|
//# sourceMappingURL=FastMCP.cjs.map
|
package/dist/FastMCP.js
CHANGED
|
@@ -684,77 +684,12 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
684
684
|
throw new UnexpectedStateError("Server is already connected");
|
|
685
685
|
}
|
|
686
686
|
this.#connectionState = "connecting";
|
|
687
|
+
const streamableHttp = !this.#stateless && isStreamableHttpTransport(transport);
|
|
687
688
|
try {
|
|
688
689
|
await this.#server.connect(transport);
|
|
689
|
-
if (!
|
|
690
|
-
|
|
691
|
-
const maxAttempts = 10;
|
|
692
|
-
const retryDelay = 100;
|
|
693
|
-
while (attempt++ < maxAttempts) {
|
|
694
|
-
const capabilities = this.#server.getClientCapabilities();
|
|
695
|
-
if (capabilities) {
|
|
696
|
-
this.#clientCapabilities = capabilities;
|
|
697
|
-
break;
|
|
698
|
-
}
|
|
699
|
-
await _promises3.setTimeout.call(void 0, retryDelay);
|
|
700
|
-
}
|
|
701
|
-
if (!this.#clientCapabilities) {
|
|
702
|
-
this.#logger.warn(
|
|
703
|
-
`[FastMCP warning] could not infer client capabilities after ${maxAttempts} attempts. Connection may be unstable.`
|
|
704
|
-
);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
if (_optionalChain([this, 'access', _12 => _12.#rootsConfig, 'optionalAccess', _13 => _13.enabled]) !== false && _optionalChain([this, 'access', _14 => _14.#clientCapabilities, 'optionalAccess', _15 => _15.roots, 'optionalAccess', _16 => _16.listChanged]) && typeof this.#server.listRoots === "function") {
|
|
708
|
-
try {
|
|
709
|
-
const roots = await this.#server.listRoots();
|
|
710
|
-
this.#roots = _optionalChain([roots, 'optionalAccess', _17 => _17.roots]) || [];
|
|
711
|
-
} catch (e) {
|
|
712
|
-
if (e instanceof _typesjs.McpError && e.code === _typesjs.ErrorCode.MethodNotFound) {
|
|
713
|
-
this.#logger.debug(
|
|
714
|
-
"[FastMCP debug] listRoots method not supported by client"
|
|
715
|
-
);
|
|
716
|
-
} else {
|
|
717
|
-
this.#logger.error(
|
|
718
|
-
`[FastMCP error] received error listing roots.
|
|
719
|
-
|
|
720
|
-
${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
721
|
-
);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
if (this.#clientCapabilities) {
|
|
726
|
-
const pingConfig = this.#getPingConfig();
|
|
727
|
-
if (pingConfig.enabled) {
|
|
728
|
-
this.#pingInterval = setInterval(async () => {
|
|
729
|
-
if (this.#pingInFlight) {
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
this.#pingInFlight = true;
|
|
733
|
-
try {
|
|
734
|
-
await this.#server.ping();
|
|
735
|
-
} catch (e4) {
|
|
736
|
-
const logLevel = pingConfig.logLevel;
|
|
737
|
-
if (logLevel === "debug") {
|
|
738
|
-
this.#logger.debug("[FastMCP debug] server ping failed");
|
|
739
|
-
} else if (logLevel === "warning") {
|
|
740
|
-
this.#logger.warn(
|
|
741
|
-
"[FastMCP warning] server is not responding to ping"
|
|
742
|
-
);
|
|
743
|
-
} else if (logLevel === "error") {
|
|
744
|
-
this.#logger.error(
|
|
745
|
-
"[FastMCP error] server is not responding to ping"
|
|
746
|
-
);
|
|
747
|
-
} else {
|
|
748
|
-
this.#logger.info("[FastMCP info] server ping failed");
|
|
749
|
-
}
|
|
750
|
-
} finally {
|
|
751
|
-
this.#pingInFlight = false;
|
|
752
|
-
}
|
|
753
|
-
}, pingConfig.intervalMs);
|
|
754
|
-
}
|
|
690
|
+
if (!streamableHttp) {
|
|
691
|
+
await this.#setUpSession(false);
|
|
755
692
|
}
|
|
756
|
-
this.#connectionState = "ready";
|
|
757
|
-
this.emit("ready");
|
|
758
693
|
} catch (error) {
|
|
759
694
|
this.#connectionState = "error";
|
|
760
695
|
const errorEvent = {
|
|
@@ -763,6 +698,18 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
|
763
698
|
this.emit("error", errorEvent);
|
|
764
699
|
throw error;
|
|
765
700
|
}
|
|
701
|
+
if (streamableHttp) {
|
|
702
|
+
this.#setUpSession(true).catch((error) => {
|
|
703
|
+
this.#connectionState = "error";
|
|
704
|
+
if (this.listenerCount("error") > 0) {
|
|
705
|
+
this.emit("error", {
|
|
706
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
707
|
+
});
|
|
708
|
+
} else {
|
|
709
|
+
this.#logger.error("[FastMCP error] session setup failed", error);
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
766
713
|
}
|
|
767
714
|
promptsListChanged(prompts) {
|
|
768
715
|
if (!this.#canRefresh("prompts")) {
|
|
@@ -931,7 +878,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
931
878
|
},
|
|
932
879
|
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
933
880
|
log: this.#createLog(),
|
|
934
|
-
requestId: typeof _optionalChain([meta, 'optionalAccess',
|
|
881
|
+
requestId: typeof _optionalChain([meta, 'optionalAccess', _12 => _12.requestId]) === "string" ? meta.requestId : void 0,
|
|
935
882
|
session: this.#auth,
|
|
936
883
|
sessionId: this.sessionId
|
|
937
884
|
};
|
|
@@ -953,8 +900,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
953
900
|
};
|
|
954
901
|
}
|
|
955
902
|
#formatSchemaIssues(issues) {
|
|
956
|
-
return _optionalChain([this, 'access',
|
|
957
|
-
const path = _optionalChain([issue, 'access',
|
|
903
|
+
return _optionalChain([this, 'access', _13 => _13.#utils, 'optionalAccess', _14 => _14.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
|
|
904
|
+
const path = _optionalChain([issue, 'access', _15 => _15.path, 'optionalAccess', _16 => _16.join, 'call', _17 => _17(".")]) || "root";
|
|
958
905
|
return `${path}: ${issue.message}`;
|
|
959
906
|
}).join(", ");
|
|
960
907
|
}
|
|
@@ -967,6 +914,52 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
967
914
|
logLevel: pingConfig.logLevel || "debug"
|
|
968
915
|
};
|
|
969
916
|
}
|
|
917
|
+
/**
|
|
918
|
+
* Fetches the client's roots if it advertised `roots.listChanged`.
|
|
919
|
+
*
|
|
920
|
+
* Over Streamable HTTP a server-initiated request travels on the client's
|
|
921
|
+
* standalone GET stream, which the client opens only after initialization,
|
|
922
|
+
* and the transport drops a request sent before that. So there each attempt
|
|
923
|
+
* is bounded and retried, and the result is announced with `rootsChanged`.
|
|
924
|
+
*/
|
|
925
|
+
async #loadRoots(streamableHttp) {
|
|
926
|
+
if (_optionalChain([this, 'access', _18 => _18.#rootsConfig, 'optionalAccess', _19 => _19.enabled]) === false || !_optionalChain([this, 'access', _20 => _20.#clientCapabilities, 'optionalAccess', _21 => _21.roots, 'optionalAccess', _22 => _22.listChanged]) || typeof this.#server.listRoots !== "function") {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
const maxAttempts = streamableHttp ? 5 : 1;
|
|
930
|
+
for (let attempt = 1; ; attempt++) {
|
|
931
|
+
try {
|
|
932
|
+
const roots = await this.#server.listRoots(
|
|
933
|
+
void 0,
|
|
934
|
+
streamableHttp ? { timeout: 1e3 } : void 0
|
|
935
|
+
);
|
|
936
|
+
this.#roots = _optionalChain([roots, 'optionalAccess', _23 => _23.roots]) || [];
|
|
937
|
+
if (streamableHttp) {
|
|
938
|
+
this.emit("rootsChanged", { roots: this.#roots });
|
|
939
|
+
}
|
|
940
|
+
return;
|
|
941
|
+
} catch (e) {
|
|
942
|
+
if (this.#connectionState === "closed") {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (attempt < maxAttempts && e instanceof _typesjs.McpError && e.code === _typesjs.ErrorCode.RequestTimeout) {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
if (e instanceof _typesjs.McpError && e.code === _typesjs.ErrorCode.MethodNotFound) {
|
|
949
|
+
this.#logger.debug(
|
|
950
|
+
"[FastMCP debug] listRoots method not supported by client"
|
|
951
|
+
);
|
|
952
|
+
} else {
|
|
953
|
+
this.#logger.error(
|
|
954
|
+
`[FastMCP error] received error listing roots.
|
|
955
|
+
|
|
956
|
+
${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
970
963
|
/**
|
|
971
964
|
* `sendLoggingMessage` rejects once the client has hung up, and these four
|
|
972
965
|
* callers are synchronous, so the rejection has nowhere to go. Swallow it the
|
|
@@ -991,6 +984,70 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
991
984
|
);
|
|
992
985
|
});
|
|
993
986
|
}
|
|
987
|
+
async #setUpSession(streamableHttp) {
|
|
988
|
+
if (!this.#stateless) {
|
|
989
|
+
let attempt = 0;
|
|
990
|
+
const maxAttempts = 10;
|
|
991
|
+
const retryDelay = 100;
|
|
992
|
+
while (attempt++ < maxAttempts) {
|
|
993
|
+
const capabilities = this.#server.getClientCapabilities();
|
|
994
|
+
if (capabilities) {
|
|
995
|
+
this.#clientCapabilities = capabilities;
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
await _promises3.setTimeout.call(void 0, retryDelay);
|
|
999
|
+
if (this.#connectionState === "closed") {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
if (!this.#clientCapabilities) {
|
|
1004
|
+
this.#logger.warn(
|
|
1005
|
+
`[FastMCP warning] could not infer client capabilities after ${maxAttempts} attempts. Connection may be unstable.`
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
if (this.#connectionState === "closed") {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
if (streamableHttp) {
|
|
1013
|
+
void this.#loadRoots(true);
|
|
1014
|
+
} else {
|
|
1015
|
+
await this.#loadRoots(false);
|
|
1016
|
+
}
|
|
1017
|
+
if (this.#clientCapabilities) {
|
|
1018
|
+
const pingConfig = this.#getPingConfig();
|
|
1019
|
+
if (pingConfig.enabled) {
|
|
1020
|
+
this.#pingInterval = setInterval(async () => {
|
|
1021
|
+
if (this.#pingInFlight) {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
this.#pingInFlight = true;
|
|
1025
|
+
try {
|
|
1026
|
+
await this.#server.ping();
|
|
1027
|
+
} catch (e4) {
|
|
1028
|
+
const logLevel = pingConfig.logLevel;
|
|
1029
|
+
if (logLevel === "debug") {
|
|
1030
|
+
this.#logger.debug("[FastMCP debug] server ping failed");
|
|
1031
|
+
} else if (logLevel === "warning") {
|
|
1032
|
+
this.#logger.warn(
|
|
1033
|
+
"[FastMCP warning] server is not responding to ping"
|
|
1034
|
+
);
|
|
1035
|
+
} else if (logLevel === "error") {
|
|
1036
|
+
this.#logger.error(
|
|
1037
|
+
"[FastMCP error] server is not responding to ping"
|
|
1038
|
+
);
|
|
1039
|
+
} else {
|
|
1040
|
+
this.#logger.info("[FastMCP info] server ping failed");
|
|
1041
|
+
}
|
|
1042
|
+
} finally {
|
|
1043
|
+
this.#pingInFlight = false;
|
|
1044
|
+
}
|
|
1045
|
+
}, pingConfig.intervalMs);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
this.#connectionState = "ready";
|
|
1049
|
+
this.emit("ready");
|
|
1050
|
+
}
|
|
994
1051
|
/**
|
|
995
1052
|
* Periodically writes to the response stream of an in-flight tool call, so an
|
|
996
1053
|
* idle-connection timeout (proxy, load balancer) does not close it while a
|
|
@@ -1667,11 +1724,22 @@ function convertObjectToSnakeCase(obj) {
|
|
|
1667
1724
|
}
|
|
1668
1725
|
return result;
|
|
1669
1726
|
}
|
|
1727
|
+
function isStreamableHttpTransport(transport) {
|
|
1728
|
+
return "handleRequest" in transport && typeof transport.handleRequest === "function";
|
|
1729
|
+
}
|
|
1670
1730
|
function joinPaths(basePath, path) {
|
|
1671
1731
|
return `${basePath}${normalizePath(path)}`;
|
|
1672
1732
|
}
|
|
1673
1733
|
function matchUriTemplate(template, uri) {
|
|
1674
|
-
|
|
1734
|
+
let match;
|
|
1735
|
+
try {
|
|
1736
|
+
match = template.fromUri(uri);
|
|
1737
|
+
} catch (error) {
|
|
1738
|
+
if (error instanceof URIError) {
|
|
1739
|
+
return void 0;
|
|
1740
|
+
}
|
|
1741
|
+
throw error;
|
|
1742
|
+
}
|
|
1675
1743
|
if (!match) {
|
|
1676
1744
|
return void 0;
|
|
1677
1745
|
}
|
|
@@ -3066,4 +3134,4 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
3066
3134
|
|
|
3067
3135
|
|
|
3068
3136
|
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;
|
|
3069
|
-
//# sourceMappingURL=chunk-
|
|
3137
|
+
//# sourceMappingURL=chunk-44X25GBU.cjs.map
|