fastmcp 4.22.7 → 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
  }
@@ -996,6 +997,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
996
997
  break;
997
998
  }
998
999
  await _promises3.setTimeout.call(void 0, retryDelay);
1000
+ if (this.#connectionState === "closed") {
1001
+ return;
1002
+ }
999
1003
  }
1000
1004
  if (!this.#clientCapabilities) {
1001
1005
  this.#logger.warn(
@@ -1010,6 +1014,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1010
1014
  void this.#loadRoots(true);
1011
1015
  } else {
1012
1016
  await this.#loadRoots(false);
1017
+ if (this.#abortController.signal.aborted) {
1018
+ return;
1019
+ }
1013
1020
  }
1014
1021
  if (this.#clientCapabilities) {
1015
1022
  const pingConfig = this.#getPingConfig();
@@ -1728,7 +1735,15 @@ function joinPaths(basePath, path) {
1728
1735
  return `${basePath}${normalizePath(path)}`;
1729
1736
  }
1730
1737
  function matchUriTemplate(template, uri) {
1731
- const match = template.fromUri(uri);
1738
+ let match;
1739
+ try {
1740
+ match = template.fromUri(uri);
1741
+ } catch (error) {
1742
+ if (error instanceof URIError) {
1743
+ return void 0;
1744
+ }
1745
+ throw error;
1746
+ }
1732
1747
  if (!match) {
1733
1748
  return void 0;
1734
1749
  }
@@ -1764,6 +1779,35 @@ function parseBasicAuthHeader(authHeader) {
1764
1779
  return null;
1765
1780
  }
1766
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
+ }
1767
1811
  function protectedResourceMetadataUrl(resource) {
1768
1812
  let url;
1769
1813
  try {
@@ -2971,8 +3015,17 @@ var FastMCP = class extends FastMCPEventEmitter {
2971
3015
  #parseRuntimeConfig(overrides) {
2972
3016
  const args = process.argv.slice(2);
2973
3017
  const getArg = (name) => {
2974
- const index = args.findIndex((arg) => arg === `--${name}`);
2975
- 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;
2976
3029
  };
2977
3030
  const transportArg = getArg("transport");
2978
3031
  const portArg = getArg("port");
@@ -2986,7 +3039,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2986
3039
  const envBasePath = process.env.FASTMCP_BASE_PATH;
2987
3040
  const envStateless = process.env.FASTMCP_STATELESS;
2988
3041
  const envHost = process.env.FASTMCP_HOST;
2989
- 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";
2990
3043
  if (transportType === "httpStream") {
2991
3044
  const port = parseInt(
2992
3045
  _optionalChain([overrides, 'optionalAccess', _72 => _72.httpStream, 'optionalAccess', _73 => _73.port, 'optionalAccess', _74 => _74.toString, 'call', _75 => _75()]) || portArg || envPort || "8080"
@@ -2997,7 +3050,8 @@ var FastMCP = class extends FastMCPEventEmitter {
2997
3050
  _optionalChain([overrides, 'optionalAccess', _80 => _80.httpStream, 'optionalAccess', _81 => _81.basePath]) || basePathArg || envBasePath
2998
3051
  );
2999
3052
  const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _82 => _82.httpStream, 'optionalAccess', _83 => _83.enableJsonResponse]) || false;
3000
- 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));
3001
3055
  const cors = _optionalChain([overrides, 'optionalAccess', _86 => _86.httpStream, 'optionalAccess', _87 => _87.cors]);
3002
3056
  const eventStore = _optionalChain([overrides, 'optionalAccess', _88 => _88.httpStream, 'optionalAccess', _89 => _89.eventStore]);
3003
3057
  const sslCa = _optionalChain([overrides, 'optionalAccess', _90 => _90.httpStream, 'optionalAccess', _91 => _91.sslCa]);
@@ -3123,4 +3177,4 @@ var FastMCP = class extends FastMCPEventEmitter {
3123
3177
 
3124
3178
 
3125
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;
3126
- //# sourceMappingURL=chunk-QICOIGCH.cjs.map
3180
+ //# sourceMappingURL=chunk-YDWOFVQN.cjs.map