fastmcp 4.23.0 → 4.23.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkYLLBANV4cjs = require('./chunk-YLLBANV4.cjs');
3
+ var _chunkC7TBI7A5cjs = require('./chunk-C7TBI7A5.cjs');
4
4
 
5
5
 
6
6
  var _chunkO22SYZMCcjs = require('./chunk-O22SYZMC.cjs');
@@ -134,7 +134,7 @@ var DiscoveryDocumentCache = class {
134
134
  throw error;
135
135
  }
136
136
  if (!res.ok) {
137
- await _chunkYLLBANV4cjs.cancelResponseBody.call(void 0, res);
137
+ await _chunkC7TBI7A5cjs.cancelResponseBody.call(void 0, res);
138
138
  throw new Error(
139
139
  `Failed to fetch discovery document from ${url}: ${res.status} ${res.statusText}`
140
140
  );
@@ -230,7 +230,7 @@ var imageContent = async (input) => {
230
230
  signal: AbortSignal.timeout(timeoutMs)
231
231
  });
232
232
  if (!response.ok) {
233
- await _chunkYLLBANV4cjs.cancelResponseBody.call(void 0, response);
233
+ await _chunkC7TBI7A5cjs.cancelResponseBody.call(void 0, response);
234
234
  throw new Error(
235
235
  `Server responded with status: ${response.status} - ${response.statusText}`
236
236
  );
@@ -292,7 +292,7 @@ var audioContent = async (input) => {
292
292
  signal: AbortSignal.timeout(timeoutMs)
293
293
  });
294
294
  if (!response.ok) {
295
- await _chunkYLLBANV4cjs.cancelResponseBody.call(void 0, response);
295
+ await _chunkC7TBI7A5cjs.cancelResponseBody.call(void 0, response);
296
296
  throw new Error(
297
297
  `Server responded with status: ${response.status} - ${response.statusText}`
298
298
  );
@@ -1887,6 +1887,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1887
1887
  #resourcesTemplates = [];
1888
1888
  #serverState = "stopped" /* Stopped */;
1889
1889
  #sessions = [];
1890
+ #stdioSessions = /* @__PURE__ */ new Set();
1890
1891
  #tools = [];
1891
1892
  /**
1892
1893
  * Adds a prompt to the server.
@@ -2263,11 +2264,23 @@ var FastMCP = class extends FastMCPEventEmitter {
2263
2264
  };
2264
2265
  process.stdin.on("close", onStdinClose);
2265
2266
  process.stdin.on("end", onStdinClose);
2266
- await this.#connectSession(session, transport, () => {
2267
- process.stdin.off("close", onStdinClose);
2268
- process.stdin.off("end", onStdinClose);
2269
- });
2270
- this.#serverState = "running" /* Running */;
2267
+ if (process.stdin.isPaused()) {
2268
+ process.stdin.resume();
2269
+ }
2270
+ this.#stdioSessions.add(session);
2271
+ try {
2272
+ await this.#connectSession(session, transport, () => {
2273
+ this.#stdioSessions.delete(session);
2274
+ process.stdin.off("close", onStdinClose);
2275
+ process.stdin.off("end", onStdinClose);
2276
+ });
2277
+ } catch (error) {
2278
+ await session.close();
2279
+ throw error;
2280
+ }
2281
+ if (this.#stdioSessions.has(session)) {
2282
+ this.#serverState = "running" /* Running */;
2283
+ }
2271
2284
  } else if (config.transportType === "httpStream") {
2272
2285
  const httpConfig = config.httpStream;
2273
2286
  const protocol = httpConfig.sslCert || httpConfig.sslKey ? "https" : "http";
@@ -2379,9 +2392,13 @@ var FastMCP = class extends FastMCPEventEmitter {
2379
2392
  }
2380
2393
  }
2381
2394
  /**
2382
- * Stops the server.
2395
+ * Stops transports created by `start()`. Transports passed to `connect()`
2396
+ * remain open and belong to the caller.
2383
2397
  */
2384
2398
  async stop() {
2399
+ await Promise.all(
2400
+ [...this.#stdioSessions].map((session) => session.close())
2401
+ );
2385
2402
  if (this.#httpStreamServer) {
2386
2403
  await this.#httpStreamServer.close();
2387
2404
  }
@@ -3169,4 +3186,4 @@ var FastMCP = class extends FastMCPEventEmitter {
3169
3186
 
3170
3187
 
3171
3188
  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;
3172
- //# sourceMappingURL=chunk-X7KNHPR4.cjs.map
3189
+ //# sourceMappingURL=chunk-TBJSX5UF.cjs.map