fastmcp 4.30.1 → 4.30.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/dist/FastMCP.cjs CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunk4JEDH2ONcjs = require('./chunk-4JEDH2ON.cjs');
14
+ var _chunkLTBNX7PXcjs = require('./chunk-LTBNX7PX.cjs');
15
15
 
16
16
 
17
17
 
@@ -50,5 +50,5 @@ require('./chunk-FBDPX4H2.cjs');
50
50
 
51
51
 
52
52
 
53
- exports.AuthProvider = _chunkCZGQ2WTQcjs.AuthProvider; exports.AzureProvider = _chunkCZGQ2WTQcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunk4JEDH2ONcjs.DiscoveryDocumentCache; exports.FastMCP = _chunk4JEDH2ONcjs.FastMCP; exports.FastMCPError = _chunk4JEDH2ONcjs.FastMCPError; exports.FastMCPSession = _chunk4JEDH2ONcjs.FastMCPSession; exports.GitHubProvider = _chunkCZGQ2WTQcjs.GitHubProvider; exports.GoogleProvider = _chunkCZGQ2WTQcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunk4JEDH2ONcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkCZGQ2WTQcjs.OAuthProvider; exports.ServerState = _chunk4JEDH2ONcjs.ServerState; exports.SessionError = _chunk4JEDH2ONcjs.SessionError; exports.UnexpectedStateError = _chunk4JEDH2ONcjs.UnexpectedStateError; exports.UserError = _chunk4JEDH2ONcjs.UserError; exports.audioContent = _chunk4JEDH2ONcjs.audioContent; exports.getAuthSession = _chunkCZGQ2WTQcjs.getAuthSession; exports.imageContent = _chunk4JEDH2ONcjs.imageContent; exports.jsonSchemaAdapter = _chunk4JEDH2ONcjs.jsonSchemaAdapter; exports.requireAll = _chunkCZGQ2WTQcjs.requireAll; exports.requireAny = _chunkCZGQ2WTQcjs.requireAny; exports.requireAuth = _chunkCZGQ2WTQcjs.requireAuth; exports.requireRole = _chunkCZGQ2WTQcjs.requireRole; exports.requireScopes = _chunkCZGQ2WTQcjs.requireScopes;
53
+ exports.AuthProvider = _chunkCZGQ2WTQcjs.AuthProvider; exports.AzureProvider = _chunkCZGQ2WTQcjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkLTBNX7PXcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkLTBNX7PXcjs.FastMCP; exports.FastMCPError = _chunkLTBNX7PXcjs.FastMCPError; exports.FastMCPSession = _chunkLTBNX7PXcjs.FastMCPSession; exports.GitHubProvider = _chunkCZGQ2WTQcjs.GitHubProvider; exports.GoogleProvider = _chunkCZGQ2WTQcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkLTBNX7PXcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkCZGQ2WTQcjs.OAuthProvider; exports.ServerState = _chunkLTBNX7PXcjs.ServerState; exports.SessionError = _chunkLTBNX7PXcjs.SessionError; exports.UnexpectedStateError = _chunkLTBNX7PXcjs.UnexpectedStateError; exports.UserError = _chunkLTBNX7PXcjs.UserError; exports.audioContent = _chunkLTBNX7PXcjs.audioContent; exports.getAuthSession = _chunkCZGQ2WTQcjs.getAuthSession; exports.imageContent = _chunkLTBNX7PXcjs.imageContent; exports.jsonSchemaAdapter = _chunkLTBNX7PXcjs.jsonSchemaAdapter; exports.requireAll = _chunkCZGQ2WTQcjs.requireAll; exports.requireAny = _chunkCZGQ2WTQcjs.requireAny; exports.requireAuth = _chunkCZGQ2WTQcjs.requireAuth; exports.requireRole = _chunkCZGQ2WTQcjs.requireRole; exports.requireScopes = _chunkCZGQ2WTQcjs.requireScopes;
54
54
  //# sourceMappingURL=FastMCP.cjs.map
package/dist/FastMCP.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  audioContent,
12
12
  imageContent,
13
13
  jsonSchemaAdapter
14
- } from "./chunk-5KA6SOWT.js";
14
+ } from "./chunk-3JQE5IXF.js";
15
15
  import {
16
16
  AuthProvider,
17
17
  AzureProvider,
@@ -1029,7 +1029,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1029
1029
  streamableHttp ? { timeout: 1e3 } : void 0
1030
1030
  );
1031
1031
  this.#roots = roots?.roots || [];
1032
- if (streamableHttp) {
1032
+ if (streamableHttp || this.#connectionState === "ready") {
1033
1033
  this.emit("rootsChanged", { roots: this.#roots });
1034
1034
  }
1035
1035
  return;
@@ -1101,6 +1101,28 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1101
1101
  );
1102
1102
  });
1103
1103
  }
1104
+ /**
1105
+ * A gateway can start a stdio server long before any client connects and
1106
+ * forward the first initialize only then, after #setUpSession stopped
1107
+ * waiting for it. Finish the setup when that client initializes.
1108
+ */
1109
+ #setUpLateClient(streamableHttp) {
1110
+ const finish = () => {
1111
+ const capabilities = this.#server.getClientCapabilities();
1112
+ if (!capabilities || this.#clientCapabilities || this.#connectionState === "closed") {
1113
+ return;
1114
+ }
1115
+ this.#clientCapabilities = capabilities;
1116
+ void this.#loadRoots(streamableHttp);
1117
+ this.#startPing();
1118
+ };
1119
+ const oninitialized = this.#server.oninitialized;
1120
+ this.#server.oninitialized = () => {
1121
+ oninitialized?.();
1122
+ finish();
1123
+ };
1124
+ finish();
1125
+ }
1104
1126
  async #setUpSession(streamableHttp) {
1105
1127
  if (!this.#stateless) {
1106
1128
  let attempt = 0;
@@ -1135,38 +1157,44 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1135
1157
  }
1136
1158
  }
1137
1159
  if (this.#clientCapabilities) {
1138
- const pingConfig = this.#getPingConfig();
1139
- if (pingConfig.enabled) {
1140
- this.#pingInterval = setInterval(async () => {
1141
- if (this.#pingInFlight) {
1142
- return;
1143
- }
1144
- this.#pingInFlight = true;
1145
- try {
1146
- await this.#server.ping();
1147
- } catch {
1148
- const logLevel = pingConfig.logLevel;
1149
- if (logLevel === "debug") {
1150
- this.#logger.debug("[FastMCP debug] server ping failed");
1151
- } else if (logLevel === "warning") {
1152
- this.#logger.warn(
1153
- "[FastMCP warning] server is not responding to ping"
1154
- );
1155
- } else if (logLevel === "error") {
1156
- this.#logger.error(
1157
- "[FastMCP error] server is not responding to ping"
1158
- );
1159
- } else {
1160
- this.#logger.info("[FastMCP info] server ping failed");
1161
- }
1162
- } finally {
1163
- this.#pingInFlight = false;
1164
- }
1165
- }, pingConfig.intervalMs);
1166
- }
1160
+ this.#startPing();
1167
1161
  }
1168
1162
  this.#connectionState = "ready";
1169
1163
  this.emit("ready");
1164
+ if (!this.#stateless && !this.#clientCapabilities) {
1165
+ this.#setUpLateClient(streamableHttp);
1166
+ }
1167
+ }
1168
+ #startPing() {
1169
+ const pingConfig = this.#getPingConfig();
1170
+ if (pingConfig.enabled) {
1171
+ this.#pingInterval = setInterval(async () => {
1172
+ if (this.#pingInFlight) {
1173
+ return;
1174
+ }
1175
+ this.#pingInFlight = true;
1176
+ try {
1177
+ await this.#server.ping();
1178
+ } catch {
1179
+ const logLevel = pingConfig.logLevel;
1180
+ if (logLevel === "debug") {
1181
+ this.#logger.debug("[FastMCP debug] server ping failed");
1182
+ } else if (logLevel === "warning") {
1183
+ this.#logger.warn(
1184
+ "[FastMCP warning] server is not responding to ping"
1185
+ );
1186
+ } else if (logLevel === "error") {
1187
+ this.#logger.error(
1188
+ "[FastMCP error] server is not responding to ping"
1189
+ );
1190
+ } else {
1191
+ this.#logger.info("[FastMCP info] server ping failed");
1192
+ }
1193
+ } finally {
1194
+ this.#pingInFlight = false;
1195
+ }
1196
+ }, pingConfig.intervalMs);
1197
+ }
1170
1198
  }
1171
1199
  /**
1172
1200
  * Periodically writes to the response stream of an in-flight tool call, so an
@@ -3699,4 +3727,4 @@ export {
3699
3727
  FastMCPSession,
3700
3728
  FastMCP
3701
3729
  };
3702
- //# sourceMappingURL=chunk-5KA6SOWT.js.map
3730
+ //# sourceMappingURL=chunk-3JQE5IXF.js.map