fastmcp 4.30.2 → 4.30.3

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.
Files changed (39) hide show
  1. package/dist/FastMCP.cjs +4 -4
  2. package/dist/FastMCP.d.cts +2 -2
  3. package/dist/FastMCP.d.ts +2 -2
  4. package/dist/FastMCP.js +3 -3
  5. package/dist/{OAuthProvider-C2Z93xC5.d.cts → OAuthProvider-BuBMMpsX.d.cts} +18 -2
  6. package/dist/{OAuthProvider-C2Z93xC5.d.ts → OAuthProvider-BuBMMpsX.d.ts} +18 -2
  7. package/dist/auth/index.cjs +2 -2
  8. package/dist/auth/index.d.cts +2 -2
  9. package/dist/auth/index.d.ts +2 -2
  10. package/dist/auth/index.js +1 -1
  11. package/dist/{chunk-CZGQ2WTQ.cjs → chunk-F7XD3S4L.cjs} +54 -7
  12. package/dist/chunk-F7XD3S4L.cjs.map +1 -0
  13. package/dist/{chunk-LTBNX7PX.cjs → chunk-M3SNOHIM.cjs} +56 -13
  14. package/dist/chunk-M3SNOHIM.cjs.map +1 -0
  15. package/dist/{chunk-FBDPX4H2.cjs → chunk-NYV5TK43.cjs} +125 -2
  16. package/dist/chunk-NYV5TK43.cjs.map +1 -0
  17. package/dist/{chunk-XPTUOWUT.js → chunk-P4ZFER5I.js} +50 -3
  18. package/dist/chunk-P4ZFER5I.js.map +1 -0
  19. package/dist/{chunk-3JQE5IXF.js → chunk-UEEX3RD5.js} +51 -8
  20. package/dist/chunk-UEEX3RD5.js.map +1 -0
  21. package/dist/{chunk-JCKJRUCE.js → chunk-YEXAT4PO.js} +125 -2
  22. package/dist/chunk-YEXAT4PO.js.map +1 -0
  23. package/dist/edge/index.cjs +4 -4
  24. package/dist/edge/index.js +1 -1
  25. package/dist/examples/custom-routes.cjs +4 -4
  26. package/dist/examples/custom-routes.js +3 -3
  27. package/dist/openapi/index.cjs +13 -10
  28. package/dist/openapi/index.cjs.map +1 -1
  29. package/dist/openapi/index.d.cts +4 -3
  30. package/dist/openapi/index.d.ts +4 -3
  31. package/dist/openapi/index.js +7 -4
  32. package/dist/openapi/index.js.map +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-3JQE5IXF.js.map +0 -1
  35. package/dist/chunk-CZGQ2WTQ.cjs.map +0 -1
  36. package/dist/chunk-FBDPX4H2.cjs.map +0 -1
  37. package/dist/chunk-JCKJRUCE.js.map +0 -1
  38. package/dist/chunk-LTBNX7PX.cjs.map +0 -1
  39. package/dist/chunk-XPTUOWUT.js.map +0 -1
@@ -1,11 +1,12 @@
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 _chunkCZGQ2WTQcjs = require('./chunk-CZGQ2WTQ.cjs');
3
+ var _chunkF7XD3S4Lcjs = require('./chunk-F7XD3S4L.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
- var _chunkFBDPX4H2cjs = require('./chunk-FBDPX4H2.cjs');
8
+
9
+ var _chunkNYV5TK43cjs = require('./chunk-NYV5TK43.cjs');
9
10
 
10
11
  // src/FastMCP.ts
11
12
  var _indexjs = require('@modelcontextprotocol/sdk/server/index.js');
@@ -141,7 +142,7 @@ var DiscoveryDocumentCache = class {
141
142
  throw error;
142
143
  }
143
144
  if (!res.ok) {
144
- await _chunkCZGQ2WTQcjs.cancelResponseBody.call(void 0, res);
145
+ await _chunkF7XD3S4Lcjs.cancelResponseBody.call(void 0, res);
145
146
  throw new Error(
146
147
  `Failed to fetch discovery document from ${url}: ${res.status} ${res.statusText}`
147
148
  );
@@ -258,7 +259,7 @@ var imageContent = async (input) => {
258
259
  signal: AbortSignal.timeout(timeoutMs)
259
260
  });
260
261
  if (!response.ok) {
261
- await _chunkCZGQ2WTQcjs.cancelResponseBody.call(void 0, response);
262
+ await _chunkF7XD3S4Lcjs.cancelResponseBody.call(void 0, response);
262
263
  throw new Error(
263
264
  `Server responded with status: ${response.status} - ${response.statusText}`
264
265
  );
@@ -340,7 +341,7 @@ var audioContent = async (input) => {
340
341
  signal: AbortSignal.timeout(timeoutMs)
341
342
  });
342
343
  if (!response.ok) {
343
- await _chunkCZGQ2WTQcjs.cancelResponseBody.call(void 0, response);
344
+ await _chunkF7XD3S4Lcjs.cancelResponseBody.call(void 0, response);
344
345
  throw new Error(
345
346
  `Server responded with status: ${response.status} - ${response.statusText}`
346
347
  );
@@ -1683,8 +1684,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1683
1684
  tools.map(async (tool) => {
1684
1685
  let inputSchema;
1685
1686
  try {
1686
- inputSchema = tool.parameters ? _chunkFBDPX4H2cjs.strictInputSchema.call(void 0,
1687
- tool.parameters["~standard"].vendor === "zod" && "_zod" in tool.parameters ? _chunkFBDPX4H2cjs.zodInputSchema.call(void 0, tool.parameters, "draft-7") : await _xsschema.toJsonSchema.call(void 0, tool.parameters)
1687
+ inputSchema = tool.parameters ? _chunkNYV5TK43cjs.strictInputSchema.call(void 0,
1688
+ tool.parameters["~standard"].vendor === "zod" && "_zod" in tool.parameters ? _chunkNYV5TK43cjs.zodInputSchema.call(void 0, tool.parameters, "draft-7") : await _xsschema.toJsonSchema.call(void 0, tool.parameters)
1688
1689
  ) : {
1689
1690
  additionalProperties: false,
1690
1691
  properties: {},
@@ -1706,8 +1707,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1706
1707
  let outputSchema;
1707
1708
  if (tool.outputSchema) {
1708
1709
  try {
1709
- outputSchema = _chunkFBDPX4H2cjs.objectRootSchema.call(void 0,
1710
- await _xsschema.toJsonSchema.call(void 0, tool.outputSchema)
1710
+ outputSchema = _chunkNYV5TK43cjs.objectRootSchema.call(void 0,
1711
+ tool.outputSchema["~standard"].vendor === "zod" && "_zod" in tool.outputSchema ? _chunkNYV5TK43cjs.zodOutputSchema.call(void 0, tool.outputSchema, "draft-7") : await _xsschema.toJsonSchema.call(void 0, tool.outputSchema)
1711
1712
  );
1712
1713
  } catch (error) {
1713
1714
  this.#logger.warn(
@@ -2292,6 +2293,12 @@ var FastMCP = class extends FastMCPEventEmitter {
2292
2293
  #resources = [];
2293
2294
  #resourcesTemplates = [];
2294
2295
  #serverState = "stopped" /* Stopped */;
2296
+ /**
2297
+ * What each session was built from, until it is listed in `#sessions`. Only
2298
+ * listed sessions hear about a registration, so one made while a session is
2299
+ * still connecting is passed on when it is listed.
2300
+ */
2301
+ #sessionRegistrations = /* @__PURE__ */ new WeakMap();
2295
2302
  #sessions = [];
2296
2303
  #stdioSessions = /* @__PURE__ */ new Set();
2297
2304
  #tools = [];
@@ -2645,6 +2652,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2645
2652
  version: this.#options.version,
2646
2653
  websiteUrl: this.#options.websiteUrl
2647
2654
  });
2655
+ this.#sessionRegistrations.set(session, this.#registrations());
2648
2656
  let stdinClosed = false;
2649
2657
  const onStdinClose = () => {
2650
2658
  if (stdinClosed) return;
@@ -2779,7 +2787,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2779
2787
  });
2780
2788
  },
2781
2789
  onConnect: async (session) => {
2782
- this.#sessions.push(session);
2790
+ this.#addSession(session);
2783
2791
  this.#logger.info(`[FastMCP info] HTTP Stream session established`);
2784
2792
  this.emit("connect", {
2785
2793
  session
@@ -2827,6 +2835,31 @@ var FastMCP = class extends FastMCPEventEmitter {
2827
2835
  }
2828
2836
  this.#serverState = "stopped" /* Stopped */;
2829
2837
  }
2838
+ /**
2839
+ * Lists a connected session in `sessions`, first passing on whatever was
2840
+ * registered or removed since it was built.
2841
+ */
2842
+ #addSession(session) {
2843
+ this.#sessions.push(session);
2844
+ const built = this.#sessionRegistrations.get(session);
2845
+ const current = this.#registrations();
2846
+ this.#sessionRegistrations.delete(session);
2847
+ if (!built) {
2848
+ return;
2849
+ }
2850
+ if (built.tools !== current.tools) {
2851
+ session.toolsListChanged(current.tools);
2852
+ }
2853
+ if (built.resources !== current.resources) {
2854
+ session.resourcesListChanged(current.resources);
2855
+ }
2856
+ if (built.resourcesTemplates !== current.resourcesTemplates) {
2857
+ session.resourceTemplatesListChanged(current.resourcesTemplates);
2858
+ }
2859
+ if (built.prompts !== current.prompts) {
2860
+ session.promptsListChanged(current.prompts);
2861
+ }
2862
+ }
2830
2863
  /**
2831
2864
  * mcp-proxy's `beforeDispatch`: answers a `tools/call` the session's token
2832
2865
  * lacks scopes for with MCP's 403 scope challenge. It runs for every message
@@ -2862,7 +2895,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2862
2895
  if (closed) {
2863
2896
  return;
2864
2897
  }
2865
- this.#sessions.push(session);
2898
+ this.#addSession(session);
2866
2899
  session.once("error", () => {
2867
2900
  this.#removeSession(session);
2868
2901
  });
@@ -2928,7 +2961,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2928
2961
  throw this.#createUnauthorizedResponse(errorMessage);
2929
2962
  }
2930
2963
  const authRequired = this.#authenticate !== void 0;
2931
- return new FastMCPSession({
2964
+ const session = new FastMCPSession({
2932
2965
  auth,
2933
2966
  authRequired,
2934
2967
  enableJsonResponse,
@@ -2953,6 +2986,8 @@ var FastMCP = class extends FastMCPEventEmitter {
2953
2986
  version: this.#options.version,
2954
2987
  websiteUrl: this.#options.websiteUrl
2955
2988
  });
2989
+ this.#sessionRegistrations.set(session, this.#registrations());
2990
+ return session;
2956
2991
  }
2957
2992
  /**
2958
2993
  * Builds a 401 Unauthorized HTTP Response for authentication failures.
@@ -3635,6 +3670,14 @@ var FastMCP = class extends FastMCPEventEmitter {
3635
3670
  session.promptsListChanged(prompts);
3636
3671
  }
3637
3672
  }
3673
+ #registrations() {
3674
+ return {
3675
+ prompts: this.#prompts,
3676
+ resources: this.#resources,
3677
+ resourcesTemplates: this.#resourcesTemplates,
3678
+ tools: this.#tools
3679
+ };
3680
+ }
3638
3681
  #removeSession(session) {
3639
3682
  const sessionIndex = this.#sessions.indexOf(session);
3640
3683
  if (sessionIndex !== -1) {
@@ -3727,4 +3770,4 @@ var FastMCP = class extends FastMCPEventEmitter {
3727
3770
 
3728
3771
 
3729
3772
  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;
3730
- //# sourceMappingURL=chunk-LTBNX7PX.cjs.map
3773
+ //# sourceMappingURL=chunk-M3SNOHIM.cjs.map