fastmcp 4.22.8 → 4.22.9

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.
@@ -668,10 +668,6 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
668
668
  }
669
669
  }
670
670
  async close() {
671
- this.#connectionState = "closed";
672
- if (this.#pingInterval) {
673
- clearInterval(this.#pingInterval);
674
- }
675
671
  this.#abortSession();
676
672
  try {
677
673
  await this.#server.close();
@@ -828,11 +824,16 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
828
824
  });
829
825
  }
830
826
  /**
831
- * Cancels the `signal` held by every tool still executing on this session.
832
- * Idempotent, so the close path and the transport's own close handler can
833
- * both call it.
827
+ * Marks the session closed, stops pinging the client and cancels the
828
+ * `signal` held by every tool still executing on this session. Idempotent,
829
+ * so the close path and the transport's own close handler can both call it.
834
830
  */
835
831
  #abortSession() {
832
+ this.#connectionState = "closed";
833
+ if (this.#pingInterval) {
834
+ clearInterval(this.#pingInterval);
835
+ this.#pingInterval = null;
836
+ }
836
837
  if (!this.#abortController.signal.aborted) {
837
838
  this.#abortController.abort(new SessionError("Session closed"));
838
839
  }
@@ -1013,6 +1014,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1013
1014
  void this.#loadRoots(true);
1014
1015
  } else {
1015
1016
  await this.#loadRoots(false);
1017
+ if (this.#abortController.signal.aborted) {
1018
+ return;
1019
+ }
1016
1020
  }
1017
1021
  if (this.#clientCapabilities) {
1018
1022
  const pingConfig = this.#getPingConfig();
@@ -1775,6 +1779,35 @@ function parseBasicAuthHeader(authHeader) {
1775
1779
  return null;
1776
1780
  }
1777
1781
  }
1782
+ function parseBooleanSetting(value, source) {
1783
+ if (!value) {
1784
+ return void 0;
1785
+ }
1786
+ switch (value.toLowerCase()) {
1787
+ case "false":
1788
+ return false;
1789
+ case "true":
1790
+ return true;
1791
+ default:
1792
+ throw new Error(`${source} must be "true" or "false", got "${value}"`);
1793
+ }
1794
+ }
1795
+ function parseTransportSetting(value, source) {
1796
+ if (!value) {
1797
+ return void 0;
1798
+ }
1799
+ switch (value.toLowerCase()) {
1800
+ case "http-stream":
1801
+ case "httpstream":
1802
+ return "httpStream";
1803
+ case "stdio":
1804
+ return "stdio";
1805
+ default:
1806
+ throw new Error(
1807
+ `${source} must be "stdio", "httpStream" or "http-stream", got "${value}"`
1808
+ );
1809
+ }
1810
+ }
1778
1811
  function protectedResourceMetadataUrl(resource) {
1779
1812
  let url;
1780
1813
  try {
@@ -2982,8 +3015,17 @@ var FastMCP = class extends FastMCPEventEmitter {
2982
3015
  #parseRuntimeConfig(overrides) {
2983
3016
  const args = process.argv.slice(2);
2984
3017
  const getArg = (name) => {
2985
- const index = args.findIndex((arg) => arg === `--${name}`);
2986
- return index !== -1 && index + 1 < args.length ? args[index + 1] : void 0;
3018
+ const index = args.findIndex(
3019
+ (arg) => arg === `--${name}` || arg.startsWith(`--${name}=`)
3020
+ );
3021
+ if (index === -1) {
3022
+ return void 0;
3023
+ }
3024
+ if (args[index] !== `--${name}`) {
3025
+ return args[index].slice(name.length + 3);
3026
+ }
3027
+ const value = args[index + 1];
3028
+ return value === void 0 || value.startsWith("--") ? "" : value;
2987
3029
  };
2988
3030
  const transportArg = getArg("transport");
2989
3031
  const portArg = getArg("port");
@@ -2997,7 +3039,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2997
3039
  const envBasePath = process.env.FASTMCP_BASE_PATH;
2998
3040
  const envStateless = process.env.FASTMCP_STATELESS;
2999
3041
  const envHost = process.env.FASTMCP_HOST;
3000
- const transportType = _optionalChain([overrides, 'optionalAccess', _71 => _71.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
3042
+ const transportType = _optionalChain([overrides, 'optionalAccess', _71 => _71.transportType]) || parseTransportSetting(transportArg, "--transport") || parseTransportSetting(envTransport, "FASTMCP_TRANSPORT") || "stdio";
3001
3043
  if (transportType === "httpStream") {
3002
3044
  const port = parseInt(
3003
3045
  _optionalChain([overrides, 'optionalAccess', _72 => _72.httpStream, 'optionalAccess', _73 => _73.port, 'optionalAccess', _74 => _74.toString, 'call', _75 => _75()]) || portArg || envPort || "8080"
@@ -3008,7 +3050,8 @@ var FastMCP = class extends FastMCPEventEmitter {
3008
3050
  _optionalChain([overrides, 'optionalAccess', _80 => _80.httpStream, 'optionalAccess', _81 => _81.basePath]) || basePathArg || envBasePath
3009
3051
  );
3010
3052
  const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _82 => _82.httpStream, 'optionalAccess', _83 => _83.enableJsonResponse]) || false;
3011
- const stateless = _nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _84 => _84.httpStream, 'optionalAccess', _85 => _85.stateless]), () => ( (statelessArg !== void 0 ? statelessArg === "true" : envStateless === "true")));
3053
+ const stateless = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([overrides, 'optionalAccess', _84 => _84.httpStream, 'optionalAccess', _85 => _85.stateless]), () => ( // A bare `--stateless` means `--stateless true`.
3054
+ (statelessArg === "" ? true : parseBooleanSetting(statelessArg, "--stateless")))), () => ( parseBooleanSetting(envStateless, "FASTMCP_STATELESS"))), () => ( false));
3012
3055
  const cors = _optionalChain([overrides, 'optionalAccess', _86 => _86.httpStream, 'optionalAccess', _87 => _87.cors]);
3013
3056
  const eventStore = _optionalChain([overrides, 'optionalAccess', _88 => _88.httpStream, 'optionalAccess', _89 => _89.eventStore]);
3014
3057
  const sslCa = _optionalChain([overrides, 'optionalAccess', _90 => _90.httpStream, 'optionalAccess', _91 => _91.sslCa]);
@@ -3134,4 +3177,4 @@ var FastMCP = class extends FastMCPEventEmitter {
3134
3177
 
3135
3178
 
3136
3179
  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;
3137
- //# sourceMappingURL=chunk-44X25GBU.cjs.map
3180
+ //# sourceMappingURL=chunk-YDWOFVQN.cjs.map