fastmcp 4.23.6 → 4.23.7

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 _chunk2PXF6JQBcjs = require('./chunk-2PXF6JQB.cjs');
14
+ var _chunkTBMRFQ6Mcjs = require('./chunk-TBMRFQ6M.cjs');
15
15
 
16
16
 
17
17
 
@@ -25,7 +25,7 @@ var _chunk2PXF6JQBcjs = require('./chunk-2PXF6JQB.cjs');
25
25
 
26
26
 
27
27
  var _chunkC7TBI7A5cjs = require('./chunk-C7TBI7A5.cjs');
28
- require('./chunk-O22SYZMC.cjs');
28
+ require('./chunk-MPFPOZ2H.cjs');
29
29
 
30
30
 
31
31
 
@@ -50,5 +50,5 @@ require('./chunk-O22SYZMC.cjs');
50
50
 
51
51
 
52
52
 
53
- exports.AuthProvider = _chunkC7TBI7A5cjs.AuthProvider; exports.AzureProvider = _chunkC7TBI7A5cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunk2PXF6JQBcjs.DiscoveryDocumentCache; exports.FastMCP = _chunk2PXF6JQBcjs.FastMCP; exports.FastMCPError = _chunk2PXF6JQBcjs.FastMCPError; exports.FastMCPSession = _chunk2PXF6JQBcjs.FastMCPSession; exports.GitHubProvider = _chunkC7TBI7A5cjs.GitHubProvider; exports.GoogleProvider = _chunkC7TBI7A5cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunk2PXF6JQBcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkC7TBI7A5cjs.OAuthProvider; exports.ServerState = _chunk2PXF6JQBcjs.ServerState; exports.SessionError = _chunk2PXF6JQBcjs.SessionError; exports.UnexpectedStateError = _chunk2PXF6JQBcjs.UnexpectedStateError; exports.UserError = _chunk2PXF6JQBcjs.UserError; exports.audioContent = _chunk2PXF6JQBcjs.audioContent; exports.getAuthSession = _chunkC7TBI7A5cjs.getAuthSession; exports.imageContent = _chunk2PXF6JQBcjs.imageContent; exports.jsonSchemaAdapter = _chunk2PXF6JQBcjs.jsonSchemaAdapter; exports.requireAll = _chunkC7TBI7A5cjs.requireAll; exports.requireAny = _chunkC7TBI7A5cjs.requireAny; exports.requireAuth = _chunkC7TBI7A5cjs.requireAuth; exports.requireRole = _chunkC7TBI7A5cjs.requireRole; exports.requireScopes = _chunkC7TBI7A5cjs.requireScopes;
53
+ exports.AuthProvider = _chunkC7TBI7A5cjs.AuthProvider; exports.AzureProvider = _chunkC7TBI7A5cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkTBMRFQ6Mcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkTBMRFQ6Mcjs.FastMCP; exports.FastMCPError = _chunkTBMRFQ6Mcjs.FastMCPError; exports.FastMCPSession = _chunkTBMRFQ6Mcjs.FastMCPSession; exports.GitHubProvider = _chunkC7TBI7A5cjs.GitHubProvider; exports.GoogleProvider = _chunkC7TBI7A5cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkTBMRFQ6Mcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkC7TBI7A5cjs.OAuthProvider; exports.ServerState = _chunkTBMRFQ6Mcjs.ServerState; exports.SessionError = _chunkTBMRFQ6Mcjs.SessionError; exports.UnexpectedStateError = _chunkTBMRFQ6Mcjs.UnexpectedStateError; exports.UserError = _chunkTBMRFQ6Mcjs.UserError; exports.audioContent = _chunkTBMRFQ6Mcjs.audioContent; exports.getAuthSession = _chunkC7TBI7A5cjs.getAuthSession; exports.imageContent = _chunkTBMRFQ6Mcjs.imageContent; exports.jsonSchemaAdapter = _chunkTBMRFQ6Mcjs.jsonSchemaAdapter; exports.requireAll = _chunkC7TBI7A5cjs.requireAll; exports.requireAny = _chunkC7TBI7A5cjs.requireAny; exports.requireAuth = _chunkC7TBI7A5cjs.requireAuth; exports.requireRole = _chunkC7TBI7A5cjs.requireRole; exports.requireScopes = _chunkC7TBI7A5cjs.requireScopes;
54
54
  //# sourceMappingURL=FastMCP.cjs.map
@@ -925,7 +925,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
925
925
  */
926
926
  get sessionId(): string | undefined;
927
927
  set sessionId(value: string | undefined);
928
- constructor({ auth, authRequired, hasTools, icons, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, stateless, streamKeepalive, title, tools, transportType, utils, version, websiteUrl, }: {
928
+ constructor({ auth, authRequired, enableJsonResponse, hasTools, icons, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, stateless, streamKeepalive, title, tools, transportType, utils, version, websiteUrl, }: {
929
929
  auth?: T;
930
930
  /**
931
931
  * Whether the server authenticates its sessions (`authenticate` is
@@ -933,6 +933,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
933
933
  * gated by `canAccess` (see `toolsVisibleTo`).
934
934
  */
935
935
  authRequired?: boolean;
936
+ enableJsonResponse?: boolean;
936
937
  /**
937
938
  * Whether the server has any tools at all, including ones this session's
938
939
  * `canAccess` filtering removed from `tools`. Defaults to `tools.length > 0`.
package/dist/FastMCP.d.ts CHANGED
@@ -925,7 +925,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
925
925
  */
926
926
  get sessionId(): string | undefined;
927
927
  set sessionId(value: string | undefined);
928
- constructor({ auth, authRequired, hasTools, icons, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, stateless, streamKeepalive, title, tools, transportType, utils, version, websiteUrl, }: {
928
+ constructor({ auth, authRequired, enableJsonResponse, hasTools, icons, instructions, logger, name, onToolCall, ping, prompts, resources, resourcesTemplates, roots, sessionId, stateless, streamKeepalive, title, tools, transportType, utils, version, websiteUrl, }: {
929
929
  auth?: T;
930
930
  /**
931
931
  * Whether the server authenticates its sessions (`authenticate` is
@@ -933,6 +933,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
933
933
  * gated by `canAccess` (see `toolsVisibleTo`).
934
934
  */
935
935
  authRequired?: boolean;
936
+ enableJsonResponse?: boolean;
936
937
  /**
937
938
  * Whether the server has any tools at all, including ones this session's
938
939
  * `canAccess` filtering removed from `tools`. Defaults to `tools.length > 0`.
package/dist/FastMCP.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  audioContent,
12
12
  imageContent,
13
13
  jsonSchemaAdapter
14
- } from "./chunk-5QKBH7JC.js";
14
+ } from "./chunk-7WNI6AGD.js";
15
15
  import {
16
16
  AuthProvider,
17
17
  AzureProvider,
@@ -25,7 +25,7 @@ import {
25
25
  requireRole,
26
26
  requireScopes
27
27
  } from "./chunk-CA2EPNZF.js";
28
- import "./chunk-UMDUIBFW.js";
28
+ import "./chunk-YZ5QEHBX.js";
29
29
  export {
30
30
  AuthProvider,
31
31
  AzureProvider,
@@ -2,8 +2,9 @@ import {
2
2
  cancelResponseBody
3
3
  } from "./chunk-CA2EPNZF.js";
4
4
  import {
5
- strictInputSchema
6
- } from "./chunk-UMDUIBFW.js";
5
+ strictInputSchema,
6
+ zodInputSchema
7
+ } from "./chunk-YZ5QEHBX.js";
7
8
 
8
9
  // src/FastMCP.ts
9
10
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
@@ -542,6 +543,8 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
542
543
  #capabilities = {};
543
544
  #clientCapabilities;
544
545
  #connectionState = "connecting";
546
+ // Caller-supplied transports leave the response mode unspecified.
547
+ #enableJsonResponse;
545
548
  #logger;
546
549
  /**
547
550
  * The minimum level the client asked for with `logging/setLevel`, or
@@ -590,6 +593,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
590
593
  constructor({
591
594
  auth,
592
595
  authRequired = false,
596
+ enableJsonResponse,
593
597
  hasTools,
594
598
  icons,
595
599
  instructions,
@@ -614,6 +618,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
614
618
  super();
615
619
  this.#auth = auth;
616
620
  this.#authRequired = authRequired;
621
+ this.#enableJsonResponse = enableJsonResponse;
617
622
  this.#logger = logger;
618
623
  this.#onToolCall = onToolCall;
619
624
  this.#pingConfig = ping;
@@ -875,6 +880,19 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
875
880
  }
876
881
  return false;
877
882
  }
883
+ /**
884
+ * When `start()` streams responses, an elicitation goes out on its request's
885
+ * own SSE stream, as the SDK's `extra.sendRequest` does, so it reaches a
886
+ * client that never opened the optional standalone GET stream. A JSON
887
+ * response cannot carry it, and a transport passed to `connect()` does not
888
+ * say which mode it uses, so those keep the session's standalone stream.
889
+ */
890
+ #createElicit(requestId) {
891
+ return (params, options) => this.#server.elicitInput(
892
+ params,
893
+ this.#enableJsonResponse === false ? { ...options, relatedRequestId: requestId } : options
894
+ );
895
+ }
878
896
  /**
879
897
  * Builds the context object passed as the third argument to
880
898
  * `resource.load` / `resourceTemplate.load` / `prompt.load`.
@@ -885,12 +903,12 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
885
903
  * are tied to a tool call's progress token / streaming notification,
886
904
  * which resource and prompt reads do not have.
887
905
  */
888
- #createLoadContext(meta, sendNotification) {
906
+ #createLoadContext(meta, sendNotification, requestId) {
889
907
  return {
890
908
  client: {
891
909
  version: this.#server.getClientVersion()
892
910
  },
893
- elicit: (params, options) => this.#server.elicitInput(params, options),
911
+ elicit: this.#createElicit(requestId),
894
912
  log: this.#createLog(sendNotification),
895
913
  requestId: typeof meta?.requestId === "string" ? meta.requestId : void 0,
896
914
  session: this.#auth,
@@ -1328,7 +1346,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1328
1346
  this.#auth,
1329
1347
  this.#createLoadContext(
1330
1348
  request.params?._meta,
1331
- extra.sendNotification
1349
+ extra.sendNotification,
1350
+ extra.requestId
1332
1351
  )
1333
1352
  );
1334
1353
  } catch (error) {
@@ -1397,7 +1416,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1397
1416
  this.#auth,
1398
1417
  this.#createLoadContext(
1399
1418
  request.params?._meta,
1400
- extra.sendNotification
1419
+ extra.sendNotification,
1420
+ extra.requestId
1401
1421
  )
1402
1422
  );
1403
1423
  const resources = Array.isArray(result) ? result : [result];
@@ -1426,7 +1446,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1426
1446
  this.#auth,
1427
1447
  this.#createLoadContext(
1428
1448
  request.params?._meta,
1429
- extra.sendNotification
1449
+ extra.sendNotification,
1450
+ extra.requestId
1430
1451
  )
1431
1452
  );
1432
1453
  } catch (error) {
@@ -1541,7 +1562,9 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1541
1562
  return {
1542
1563
  annotations: tool.annotations,
1543
1564
  description: tool.description,
1544
- inputSchema: tool.parameters ? strictInputSchema(await toJsonSchema(tool.parameters)) : {
1565
+ inputSchema: tool.parameters ? strictInputSchema(
1566
+ tool.parameters["~standard"].vendor === "zod" && "_zod" in tool.parameters ? zodInputSchema(tool.parameters, "draft-7") : await toJsonSchema(tool.parameters)
1567
+ ) : {
1545
1568
  additionalProperties: false,
1546
1569
  properties: {},
1547
1570
  type: "object"
@@ -1650,7 +1673,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1650
1673
  client: {
1651
1674
  version: this.#server.getClientVersion()
1652
1675
  },
1653
- elicit: (params, options) => this.#server.elicitInput(params, options),
1676
+ elicit: this.#createElicit(extra.requestId),
1654
1677
  log,
1655
1678
  reportProgress,
1656
1679
  requestId: typeof request.params?._meta?.requestId === "string" ? request.params._meta.requestId : void 0,
@@ -2330,7 +2353,12 @@ var FastMCP = class extends FastMCPEventEmitter {
2330
2353
  auth = this.#requireAuthenticated(await authenticate(request));
2331
2354
  }
2332
2355
  const sessionId = Array.isArray(request.headers["mcp-session-id"]) ? request.headers["mcp-session-id"][0] : request.headers["mcp-session-id"];
2333
- return this.#createSession(auth, sessionId, true);
2356
+ return this.#createSession(
2357
+ auth,
2358
+ sessionId,
2359
+ true,
2360
+ httpConfig.enableJsonResponse
2361
+ );
2334
2362
  },
2335
2363
  enableJsonResponse: httpConfig.enableJsonResponse,
2336
2364
  eventStore: httpConfig.eventStore,
@@ -2372,7 +2400,12 @@ var FastMCP = class extends FastMCPEventEmitter {
2372
2400
  auth = this.#requireAuthenticated(await authenticate(request));
2373
2401
  }
2374
2402
  const sessionId = Array.isArray(request.headers["mcp-session-id"]) ? request.headers["mcp-session-id"][0] : request.headers["mcp-session-id"];
2375
- return this.#createSession(auth, sessionId);
2403
+ return this.#createSession(
2404
+ auth,
2405
+ sessionId,
2406
+ false,
2407
+ httpConfig.enableJsonResponse
2408
+ );
2376
2409
  },
2377
2410
  enableJsonResponse: httpConfig.enableJsonResponse,
2378
2411
  eventStore: httpConfig.eventStore,
@@ -2461,7 +2494,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2461
2494
  * Creates a new FastMCPSession instance with the current configuration.
2462
2495
  * Used both for regular sessions and stateless requests.
2463
2496
  */
2464
- #createSession(auth, sessionId, stateless = false) {
2497
+ #createSession(auth, sessionId, stateless = false, enableJsonResponse) {
2465
2498
  if (auth && typeof auth === "object" && "authenticated" in auth && !auth.authenticated) {
2466
2499
  const errorMessage = "error" in auth && typeof auth.error === "string" ? auth.error : "Authentication failed";
2467
2500
  throw this.#createUnauthorizedResponse(errorMessage);
@@ -2470,6 +2503,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2470
2503
  return new FastMCPSession({
2471
2504
  auth,
2472
2505
  authRequired,
2506
+ enableJsonResponse,
2473
2507
  hasTools: this.#tools.length > 0,
2474
2508
  icons: this.#options.icons,
2475
2509
  instructions: this.#options.instructions,
@@ -3213,4 +3247,4 @@ export {
3213
3247
  FastMCPSession,
3214
3248
  FastMCP
3215
3249
  };
3216
- //# sourceMappingURL=chunk-5QKBH7JC.js.map
3250
+ //# sourceMappingURL=chunk-7WNI6AGD.js.map