fastmcp 4.4.0 → 4.5.0

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/README.md CHANGED
@@ -1329,6 +1329,23 @@ async load() {
1329
1329
  }
1330
1330
  ```
1331
1331
 
1332
+ `load` also receives `auth` (the value returned by your `authenticate` function, if any) and a `context` object as its second and third arguments. `context` mirrors the `client`, `log`, `session`, and `sessionId` fields available to `tool.execute` (see [Session ID and Request ID Tracking](#session-id-and-request-id-tracking)); `reportProgress` and `streamContent` are not included since they are tied to a tool call's progress token:
1333
+
1334
+ ```ts
1335
+ server.addResource({
1336
+ uri: "file:///logs/app.log",
1337
+ name: "Application Logs",
1338
+ mimeType: "text/plain",
1339
+ async load(auth, context) {
1340
+ context.log.info("loading application logs", { requestedBy: auth?.userId });
1341
+
1342
+ return {
1343
+ text: await readLogFile(),
1344
+ };
1345
+ },
1346
+ });
1347
+ ```
1348
+
1332
1349
  ### Resource templates
1333
1350
 
1334
1351
  You can also define resource templates:
@@ -1353,6 +1370,8 @@ server.addResourceTemplate({
1353
1370
  });
1354
1371
  ```
1355
1372
 
1373
+ Like plain resources, `load` also receives `auth` and `context` as its second and third arguments (see [Resources](#resources)).
1374
+
1356
1375
  #### Resource template argument auto-completion
1357
1376
 
1358
1377
  Provide `complete` functions for resource template arguments to enable automatic completion:
@@ -1517,6 +1536,27 @@ server.addPrompt({
1517
1536
  });
1518
1537
  ```
1519
1538
 
1539
+ Like resources, `load` also receives `auth` and `context` as its second and third arguments (see [Resources](#resources)):
1540
+
1541
+ ```ts
1542
+ server.addPrompt({
1543
+ name: "git-commit",
1544
+ description: "Generate a Git commit message",
1545
+ arguments: [
1546
+ {
1547
+ name: "changes",
1548
+ description: "Git diff or description of changes",
1549
+ required: true,
1550
+ },
1551
+ ],
1552
+ load: async (args, auth, context) => {
1553
+ context.log.debug("generating git commit prompt", { user: auth?.userId });
1554
+
1555
+ return `Generate a concise but descriptive commit message for these changes:\n\n${args.changes}`;
1556
+ },
1557
+ });
1558
+ ```
1559
+
1520
1560
  #### Prompt argument auto-completion
1521
1561
 
1522
1562
  Prompts can provide auto-completion for their arguments:
package/dist/FastMCP.cjs CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
 
10
- var _chunk3YTRRGCEcjs = require('./chunk-3YTRRGCE.cjs');
10
+ var _chunkBJF2JTTEcjs = require('./chunk-BJF2JTTE.cjs');
11
11
 
12
12
 
13
13
 
@@ -41,5 +41,5 @@ var _chunkIX3HKAX4cjs = require('./chunk-IX3HKAX4.cjs');
41
41
 
42
42
 
43
43
 
44
- exports.AuthProvider = _chunkIX3HKAX4cjs.AuthProvider; exports.AzureProvider = _chunkIX3HKAX4cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunk3YTRRGCEcjs.DiscoveryDocumentCache; exports.FastMCP = _chunk3YTRRGCEcjs.FastMCP; exports.FastMCPSession = _chunk3YTRRGCEcjs.FastMCPSession; exports.GitHubProvider = _chunkIX3HKAX4cjs.GitHubProvider; exports.GoogleProvider = _chunkIX3HKAX4cjs.GoogleProvider; exports.OAuthProvider = _chunkIX3HKAX4cjs.OAuthProvider; exports.ServerState = _chunk3YTRRGCEcjs.ServerState; exports.UnexpectedStateError = _chunk3YTRRGCEcjs.UnexpectedStateError; exports.UserError = _chunk3YTRRGCEcjs.UserError; exports.audioContent = _chunk3YTRRGCEcjs.audioContent; exports.getAuthSession = _chunkIX3HKAX4cjs.getAuthSession; exports.imageContent = _chunk3YTRRGCEcjs.imageContent; exports.requireAll = _chunkIX3HKAX4cjs.requireAll; exports.requireAny = _chunkIX3HKAX4cjs.requireAny; exports.requireAuth = _chunkIX3HKAX4cjs.requireAuth; exports.requireRole = _chunkIX3HKAX4cjs.requireRole; exports.requireScopes = _chunkIX3HKAX4cjs.requireScopes;
44
+ exports.AuthProvider = _chunkIX3HKAX4cjs.AuthProvider; exports.AzureProvider = _chunkIX3HKAX4cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkBJF2JTTEcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkBJF2JTTEcjs.FastMCP; exports.FastMCPSession = _chunkBJF2JTTEcjs.FastMCPSession; exports.GitHubProvider = _chunkIX3HKAX4cjs.GitHubProvider; exports.GoogleProvider = _chunkIX3HKAX4cjs.GoogleProvider; exports.OAuthProvider = _chunkIX3HKAX4cjs.OAuthProvider; exports.ServerState = _chunkBJF2JTTEcjs.ServerState; exports.UnexpectedStateError = _chunkBJF2JTTEcjs.UnexpectedStateError; exports.UserError = _chunkBJF2JTTEcjs.UserError; exports.audioContent = _chunkBJF2JTTEcjs.audioContent; exports.getAuthSession = _chunkIX3HKAX4cjs.getAuthSession; exports.imageContent = _chunkBJF2JTTEcjs.imageContent; exports.requireAll = _chunkIX3HKAX4cjs.requireAll; exports.requireAny = _chunkIX3HKAX4cjs.requireAny; exports.requireAuth = _chunkIX3HKAX4cjs.requireAuth; exports.requireRole = _chunkIX3HKAX4cjs.requireRole; exports.requireScopes = _chunkIX3HKAX4cjs.requireScopes;
45
45
  //# sourceMappingURL=FastMCP.cjs.map
@@ -117,6 +117,14 @@ type Context<T extends FastMCPSessionAuth> = {
117
117
  type Extra = unknown;
118
118
  type Extras = Record<string, Extra>;
119
119
  type Literal = boolean | null | number | string | undefined;
120
+ /**
121
+ * Context passed to `load` for resources, resource templates, and prompts.
122
+ *
123
+ * This is a subset of the tool execution {@link Context}. `reportProgress`
124
+ * and `streamContent` are tied to a tool call's progress token / streaming
125
+ * notification and are not available outside of `tool.execute`.
126
+ */
127
+ type LoadContext<T extends FastMCPSessionAuth> = Omit<Context<T>, "reportProgress" | "streamContent">;
120
128
  type Progress = {
121
129
  /**
122
130
  * The progress thus far. This should increase every time progress is made, even if the total is unknown.
@@ -182,7 +190,7 @@ type InputPrompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments ex
182
190
  arguments?: InputPromptArgument<T>[];
183
191
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
184
192
  description?: string;
185
- load: (args: Args, auth?: T) => Promise<PromptResult>;
193
+ load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
186
194
  name: string;
187
195
  };
188
196
  type InputPromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
@@ -196,7 +204,7 @@ type InputResourceTemplate<T extends FastMCPSessionAuth, Arguments extends Input
196
204
  arguments: Arguments;
197
205
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
198
206
  description?: string;
199
- load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
207
+ load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
200
208
  mimeType?: string;
201
209
  name: string;
202
210
  uriTemplate: string;
@@ -212,7 +220,7 @@ type Prompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments extends
212
220
  arguments?: PromptArgument<T>[];
213
221
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
214
222
  description?: string;
215
- load: (args: Args, auth?: T) => Promise<PromptResult>;
223
+ load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
216
224
  name: string;
217
225
  };
218
226
  type PromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
@@ -234,7 +242,7 @@ type PromptResult = Pick<GetPromptResult, "messages"> | string;
234
242
  type Resource<T extends FastMCPSessionAuth> = {
235
243
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
236
244
  description?: string;
237
- load: (auth?: T) => Promise<ResourceResult | ResourceResult[]>;
245
+ load: (auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
238
246
  mimeType?: string;
239
247
  name: string;
240
248
  uri: string;
@@ -252,7 +260,7 @@ type ResourceTemplate<T extends FastMCPSessionAuth, Arguments extends ResourceTe
252
260
  arguments: Arguments;
253
261
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
254
262
  description?: string;
255
- load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
263
+ load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
256
264
  mimeType?: string;
257
265
  name: string;
258
266
  uriTemplate: string;
@@ -881,4 +889,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
881
889
  stop(): Promise<void>;
882
890
  }
883
891
 
884
- export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
892
+ export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
package/dist/FastMCP.d.ts CHANGED
@@ -117,6 +117,14 @@ type Context<T extends FastMCPSessionAuth> = {
117
117
  type Extra = unknown;
118
118
  type Extras = Record<string, Extra>;
119
119
  type Literal = boolean | null | number | string | undefined;
120
+ /**
121
+ * Context passed to `load` for resources, resource templates, and prompts.
122
+ *
123
+ * This is a subset of the tool execution {@link Context}. `reportProgress`
124
+ * and `streamContent` are tied to a tool call's progress token / streaming
125
+ * notification and are not available outside of `tool.execute`.
126
+ */
127
+ type LoadContext<T extends FastMCPSessionAuth> = Omit<Context<T>, "reportProgress" | "streamContent">;
120
128
  type Progress = {
121
129
  /**
122
130
  * The progress thus far. This should increase every time progress is made, even if the total is unknown.
@@ -182,7 +190,7 @@ type InputPrompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments ex
182
190
  arguments?: InputPromptArgument<T>[];
183
191
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
184
192
  description?: string;
185
- load: (args: Args, auth?: T) => Promise<PromptResult>;
193
+ load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
186
194
  name: string;
187
195
  };
188
196
  type InputPromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
@@ -196,7 +204,7 @@ type InputResourceTemplate<T extends FastMCPSessionAuth, Arguments extends Input
196
204
  arguments: Arguments;
197
205
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
198
206
  description?: string;
199
- load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
207
+ load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
200
208
  mimeType?: string;
201
209
  name: string;
202
210
  uriTemplate: string;
@@ -212,7 +220,7 @@ type Prompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments extends
212
220
  arguments?: PromptArgument<T>[];
213
221
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
214
222
  description?: string;
215
- load: (args: Args, auth?: T) => Promise<PromptResult>;
223
+ load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
216
224
  name: string;
217
225
  };
218
226
  type PromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
@@ -234,7 +242,7 @@ type PromptResult = Pick<GetPromptResult, "messages"> | string;
234
242
  type Resource<T extends FastMCPSessionAuth> = {
235
243
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
236
244
  description?: string;
237
- load: (auth?: T) => Promise<ResourceResult | ResourceResult[]>;
245
+ load: (auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
238
246
  mimeType?: string;
239
247
  name: string;
240
248
  uri: string;
@@ -252,7 +260,7 @@ type ResourceTemplate<T extends FastMCPSessionAuth, Arguments extends ResourceTe
252
260
  arguments: Arguments;
253
261
  complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
254
262
  description?: string;
255
- load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
263
+ load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
256
264
  mimeType?: string;
257
265
  name: string;
258
266
  uriTemplate: string;
@@ -881,4 +889,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
881
889
  stop(): Promise<void>;
882
890
  }
883
891
 
884
- export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
892
+ export { type AudioContent, AuthProvider, type Content, type ContentResult, type Context, DiscoveryDocumentCache, FastMCP, type FastMCPEvents, type FastMCPRequest, type FastMCPResponse, FastMCPSession, type FastMCPSessionAuth, type FastMCPSessionEvents, type HTTPMethod, type ImageContent, type InputPrompt, type InputPromptArgument, type LoadContext, type Logger, type LoggingLevel, OAuthSession, type Progress, type Prompt, type PromptArgument, type Resource, type ResourceContent, type ResourceResult, type ResourceTemplate, type ResourceTemplateArgument, type RouteHandler, type RouteOptions, type SSEServer, type SerializableValue, type ServerOptions, ServerState, type TextContent, type Tool, type ToolParameters, UnexpectedStateError, UserError, audioContent, imageContent };
package/dist/FastMCP.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  UserError,
8
8
  audioContent,
9
9
  imageContent
10
- } from "./chunk-MDIESGNI.js";
10
+ } from "./chunk-BTMLQWIR.js";
11
11
  import {
12
12
  AuthProvider,
13
13
  AzureProvider,
@@ -599,9 +599,70 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
599
599
  });
600
600
  });
601
601
  }
602
+ /**
603
+ * Builds the context object passed as the third argument to
604
+ * `resource.load` / `resourceTemplate.load` / `prompt.load`.
605
+ *
606
+ * This mirrors the `client`, `log`, `requestId`, `session`, and
607
+ * `sessionId` fields available to `tool.execute` via {@link Context}.
608
+ * `reportProgress` and `streamContent` are intentionally omitted: they
609
+ * are tied to a tool call's progress token / streaming notification,
610
+ * which resource and prompt reads do not have.
611
+ */
612
+ #createLoadContext(meta) {
613
+ return {
614
+ client: {
615
+ version: this.#server.getClientVersion()
616
+ },
617
+ log: this.#createLog(),
618
+ requestId: typeof _optionalChain([meta, 'optionalAccess', _12 => _12.requestId]) === "string" ? meta.requestId : void 0,
619
+ session: this.#auth,
620
+ sessionId: this.#sessionId
621
+ };
622
+ }
623
+ #createLog() {
624
+ return {
625
+ debug: (message, context) => {
626
+ this.#server.sendLoggingMessage({
627
+ data: {
628
+ context,
629
+ message
630
+ },
631
+ level: "debug"
632
+ });
633
+ },
634
+ error: (message, context) => {
635
+ this.#server.sendLoggingMessage({
636
+ data: {
637
+ context,
638
+ message
639
+ },
640
+ level: "error"
641
+ });
642
+ },
643
+ info: (message, context) => {
644
+ this.#server.sendLoggingMessage({
645
+ data: {
646
+ context,
647
+ message
648
+ },
649
+ level: "info"
650
+ });
651
+ },
652
+ warn: (message, context) => {
653
+ this.#server.sendLoggingMessage({
654
+ data: {
655
+ context,
656
+ message
657
+ },
658
+ level: "warning"
659
+ });
660
+ }
661
+ };
662
+ }
602
663
  #formatSchemaIssues(issues) {
603
- return _optionalChain([this, 'access', _12 => _12.#utils, 'optionalAccess', _13 => _13.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
604
- const path = _optionalChain([issue, 'access', _14 => _14.path, 'optionalAccess', _15 => _15.join, 'call', _16 => _16(".")]) || "root";
664
+ return _optionalChain([this, 'access', _13 => _13.#utils, 'optionalAccess', _14 => _14.formatInvalidParamsErrorMessage]) ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
665
+ const path = _optionalChain([issue, 'access', _15 => _15.path, 'optionalAccess', _16 => _16.join, 'call', _17 => _17(".")]) || "root";
605
666
  return `${path}: ${issue.message}`;
606
667
  }).join(", ");
607
668
  }
@@ -812,7 +873,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
812
873
  try {
813
874
  result = await prompt.load(
814
875
  args,
815
- this.#auth
876
+ this.#auth,
877
+ this.#createLoadContext(_optionalChain([request, 'access', _18 => _18.params, 'optionalAccess', _19 => _19._meta]))
816
878
  );
817
879
  } catch (error) {
818
880
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -874,7 +936,11 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
874
936
  continue;
875
937
  }
876
938
  const uri = uriTemplate.fill(match);
877
- const result = await resourceTemplate.load(match, this.#auth);
939
+ const result = await resourceTemplate.load(
940
+ match,
941
+ this.#auth,
942
+ this.#createLoadContext(_optionalChain([request, 'access', _20 => _20.params, 'optionalAccess', _21 => _21._meta]))
943
+ );
878
944
  const resources = Array.isArray(result) ? result : [result];
879
945
  return {
880
946
  contents: resources.map((resource2) => ({
@@ -896,7 +962,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
896
962
  }
897
963
  let maybeArrayResult;
898
964
  try {
899
- maybeArrayResult = await resource.load(this.#auth);
965
+ maybeArrayResult = await resource.load(
966
+ this.#auth,
967
+ this.#createLoadContext(_optionalChain([request, 'access', _22 => _22.params, 'optionalAccess', _23 => _23._meta]))
968
+ );
900
969
  } catch (error) {
901
970
  const errorMessage = error instanceof Error ? error.message : String(error);
902
971
  throw new (0, _typesjs.McpError)(
@@ -948,7 +1017,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
948
1017
  );
949
1018
  }
950
1019
  setupRootsHandlers() {
951
- if (_optionalChain([this, 'access', _17 => _17.#rootsConfig, 'optionalAccess', _18 => _18.enabled]) === false) {
1020
+ if (_optionalChain([this, 'access', _24 => _24.#rootsConfig, 'optionalAccess', _25 => _25.enabled]) === false) {
952
1021
  this.#logger.debug(
953
1022
  "[FastMCP debug] roots capability explicitly disabled via config"
954
1023
  );
@@ -1040,7 +1109,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1040
1109
  }
1041
1110
  args = parsed.value;
1042
1111
  }
1043
- const progressToken = _optionalChain([request, 'access', _19 => _19.params, 'optionalAccess', _20 => _20._meta, 'optionalAccess', _21 => _21.progressToken]);
1112
+ const progressToken = _optionalChain([request, 'access', _26 => _26.params, 'optionalAccess', _27 => _27._meta, 'optionalAccess', _28 => _28.progressToken]);
1044
1113
  let result;
1045
1114
  try {
1046
1115
  const reportProgress = async (progress) => {
@@ -1065,44 +1134,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1065
1134
  );
1066
1135
  }
1067
1136
  };
1068
- const log = {
1069
- debug: (message, context) => {
1070
- this.#server.sendLoggingMessage({
1071
- data: {
1072
- context,
1073
- message
1074
- },
1075
- level: "debug"
1076
- });
1077
- },
1078
- error: (message, context) => {
1079
- this.#server.sendLoggingMessage({
1080
- data: {
1081
- context,
1082
- message
1083
- },
1084
- level: "error"
1085
- });
1086
- },
1087
- info: (message, context) => {
1088
- this.#server.sendLoggingMessage({
1089
- data: {
1090
- context,
1091
- message
1092
- },
1093
- level: "info"
1094
- });
1095
- },
1096
- warn: (message, context) => {
1097
- this.#server.sendLoggingMessage({
1098
- data: {
1099
- context,
1100
- message
1101
- },
1102
- level: "warning"
1103
- });
1104
- }
1105
- };
1137
+ const log = this.#createLog();
1106
1138
  const streamContent = async (content) => {
1107
1139
  const contentArray = Array.isArray(content) ? content : [content];
1108
1140
  try {
@@ -1135,7 +1167,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
1135
1167
  },
1136
1168
  log,
1137
1169
  reportProgress,
1138
- requestId: typeof _optionalChain([request, 'access', _22 => _22.params, 'optionalAccess', _23 => _23._meta, 'optionalAccess', _24 => _24.requestId]) === "string" ? request.params._meta.requestId : void 0,
1170
+ requestId: typeof _optionalChain([request, 'access', _29 => _29.params, 'optionalAccess', _30 => _30._meta, 'optionalAccess', _31 => _31.requestId]) === "string" ? request.params._meta.requestId : void 0,
1139
1171
  session: this.#auth,
1140
1172
  sessionId: this.#sessionId,
1141
1173
  streamContent
@@ -1245,7 +1277,7 @@ function normalizePath(path) {
1245
1277
  return path.startsWith("/") ? path : `/${path}`;
1246
1278
  }
1247
1279
  function parseBasicAuthHeader(authHeader) {
1248
- const basicMatch = _optionalChain([authHeader, 'optionalAccess', _25 => _25.match, 'call', _26 => _26(/^Basic\s+(.+)$/)]);
1280
+ const basicMatch = _optionalChain([authHeader, 'optionalAccess', _32 => _32.match, 'call', _33 => _33(/^Basic\s+(.+)$/)]);
1249
1281
  if (!basicMatch) return null;
1250
1282
  try {
1251
1283
  const credentials = Buffer.from(basicMatch[1], "base64").toString("utf-8");
@@ -1647,7 +1679,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1647
1679
  enableJsonResponse: httpConfig.enableJsonResponse,
1648
1680
  eventStore: httpConfig.eventStore,
1649
1681
  host: httpConfig.host,
1650
- ..._optionalChain([this, 'access', _27 => _27.#options, 'access', _28 => _28.oauth, 'optionalAccess', _29 => _29.enabled]) && _optionalChain([this, 'access', _30 => _30.#options, 'access', _31 => _31.oauth, 'access', _32 => _32.protectedResource, 'optionalAccess', _33 => _33.resource]) ? {
1682
+ ..._optionalChain([this, 'access', _34 => _34.#options, 'access', _35 => _35.oauth, 'optionalAccess', _36 => _36.enabled]) && _optionalChain([this, 'access', _37 => _37.#options, 'access', _38 => _38.oauth, 'access', _39 => _39.protectedResource, 'optionalAccess', _40 => _40.resource]) ? {
1651
1683
  oauth: {
1652
1684
  protectedResource: {
1653
1685
  resource: this.#options.oauth.protectedResource.resource
@@ -1694,7 +1726,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1694
1726
  enableJsonResponse: httpConfig.enableJsonResponse,
1695
1727
  eventStore: httpConfig.eventStore,
1696
1728
  host: httpConfig.host,
1697
- ..._optionalChain([this, 'access', _34 => _34.#options, 'access', _35 => _35.oauth, 'optionalAccess', _36 => _36.enabled]) && _optionalChain([this, 'access', _37 => _37.#options, 'access', _38 => _38.oauth, 'access', _39 => _39.protectedResource, 'optionalAccess', _40 => _40.resource]) ? {
1729
+ ..._optionalChain([this, 'access', _41 => _41.#options, 'access', _42 => _42.oauth, 'optionalAccess', _43 => _43.enabled]) && _optionalChain([this, 'access', _44 => _44.#options, 'access', _45 => _45.oauth, 'access', _46 => _46.protectedResource, 'optionalAccess', _47 => _47.resource]) ? {
1698
1730
  oauth: {
1699
1731
  protectedResource: {
1700
1732
  resource: this.#options.oauth.protectedResource.resource
@@ -1867,7 +1899,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1867
1899
  }
1868
1900
  }
1869
1901
  const oauthConfig = this.#options.oauth;
1870
- if (_optionalChain([oauthConfig, 'optionalAccess', _41 => _41.enabled]) && req.method === "GET") {
1902
+ if (_optionalChain([oauthConfig, 'optionalAccess', _48 => _48.enabled]) && req.method === "GET") {
1871
1903
  const url2 = new URL(req.url || "", `http://${host}`);
1872
1904
  const authorizationServerMetadataPath = joinPaths(
1873
1905
  "",
@@ -1901,8 +1933,8 @@ var FastMCP = class extends FastMCPEventEmitter {
1901
1933
  }
1902
1934
  }
1903
1935
  }
1904
- const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _42 => _42.proxy]);
1905
- if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _43 => _43.enabled])) {
1936
+ const oauthProxy = _optionalChain([oauthConfig, 'optionalAccess', _49 => _49.proxy]);
1937
+ if (oauthProxy && _optionalChain([oauthConfig, 'optionalAccess', _50 => _50.enabled])) {
1906
1938
  const url2 = new URL(req.url || "", `http://${host}`);
1907
1939
  const oauthPath = basePathRelativePath;
1908
1940
  try {
@@ -1919,7 +1951,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1919
1951
  const statusCode = error.statusCode || 400;
1920
1952
  res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
1921
1953
  JSON.stringify(
1922
- _optionalChain([error, 'access', _44 => _44.toJSON, 'optionalCall', _45 => _45()]) || {
1954
+ _optionalChain([error, 'access', _51 => _51.toJSON, 'optionalCall', _52 => _52()]) || {
1923
1955
  error: "invalid_request"
1924
1956
  }
1925
1957
  )
@@ -1946,7 +1978,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1946
1978
  } catch (error) {
1947
1979
  res.writeHead(400, { "Content-Type": "application/json" }).end(
1948
1980
  JSON.stringify(
1949
- _optionalChain([error, 'access', _46 => _46.toJSON, 'optionalCall', _47 => _47()]) || {
1981
+ _optionalChain([error, 'access', _53 => _53.toJSON, 'optionalCall', _54 => _54()]) || {
1950
1982
  error: "invalid_request"
1951
1983
  }
1952
1984
  )
@@ -1968,7 +2000,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1968
2000
  } catch (error) {
1969
2001
  res.writeHead(400, { "Content-Type": "application/json" }).end(
1970
2002
  JSON.stringify(
1971
- _optionalChain([error, 'access', _48 => _48.toJSON, 'optionalCall', _49 => _49()]) || {
2003
+ _optionalChain([error, 'access', _55 => _55.toJSON, 'optionalCall', _56 => _56()]) || {
1972
2004
  error: "server_error"
1973
2005
  }
1974
2006
  )
@@ -2003,7 +2035,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2003
2035
  } catch (error) {
2004
2036
  res.writeHead(400, { "Content-Type": "application/json" }).end(
2005
2037
  JSON.stringify(
2006
- _optionalChain([error, 'access', _50 => _50.toJSON, 'optionalCall', _51 => _51()]) || {
2038
+ _optionalChain([error, 'access', _57 => _57.toJSON, 'optionalCall', _58 => _58()]) || {
2007
2039
  error: "server_error"
2008
2040
  }
2009
2041
  )
@@ -2025,8 +2057,8 @@ var FastMCP = class extends FastMCPEventEmitter {
2025
2057
  const basicAuth = parseBasicAuthHeader(
2026
2058
  req.headers.authorization
2027
2059
  );
2028
- const clientId = _optionalChain([basicAuth, 'optionalAccess', _52 => _52.clientId]) || params.get("client_id") || "";
2029
- const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _53 => _53.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
2060
+ const clientId = _optionalChain([basicAuth, 'optionalAccess', _59 => _59.clientId]) || params.get("client_id") || "";
2061
+ const clientSecret = _nullishCoalesce(_nullishCoalesce(_optionalChain([basicAuth, 'optionalAccess', _60 => _60.clientSecret]), () => ( params.get("client_secret"))), () => ( void 0));
2030
2062
  let response;
2031
2063
  if (grantType === "authorization_code") {
2032
2064
  response = await oauthProxy.exchangeAuthorizationCode({
@@ -2056,7 +2088,7 @@ var FastMCP = class extends FastMCPEventEmitter {
2056
2088
  const statusCode = error.statusCode || 400;
2057
2089
  res.writeHead(statusCode, { "Content-Type": "application/json" }).end(
2058
2090
  JSON.stringify(
2059
- _optionalChain([error, 'access', _54 => _54.toJSON, 'optionalCall', _55 => _55()]) || {
2091
+ _optionalChain([error, 'access', _61 => _61.toJSON, 'optionalCall', _62 => _62()]) || {
2060
2092
  error: "invalid_request"
2061
2093
  }
2062
2094
  )
@@ -2127,23 +2159,23 @@ var FastMCP = class extends FastMCPEventEmitter {
2127
2159
  const envBasePath = process.env.FASTMCP_BASE_PATH;
2128
2160
  const envStateless = process.env.FASTMCP_STATELESS;
2129
2161
  const envHost = process.env.FASTMCP_HOST;
2130
- const transportType = _optionalChain([overrides, 'optionalAccess', _56 => _56.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
2162
+ const transportType = _optionalChain([overrides, 'optionalAccess', _63 => _63.transportType]) || (transportArg === "http-stream" ? "httpStream" : transportArg) || envTransport || "stdio";
2131
2163
  if (transportType === "httpStream") {
2132
2164
  const port = parseInt(
2133
- _optionalChain([overrides, 'optionalAccess', _57 => _57.httpStream, 'optionalAccess', _58 => _58.port, 'optionalAccess', _59 => _59.toString, 'call', _60 => _60()]) || portArg || envPort || "8080"
2165
+ _optionalChain([overrides, 'optionalAccess', _64 => _64.httpStream, 'optionalAccess', _65 => _65.port, 'optionalAccess', _66 => _66.toString, 'call', _67 => _67()]) || portArg || envPort || "8080"
2134
2166
  );
2135
- const host = _optionalChain([overrides, 'optionalAccess', _61 => _61.httpStream, 'optionalAccess', _62 => _62.host]) || hostArg || envHost || "localhost";
2136
- const endpoint = _optionalChain([overrides, 'optionalAccess', _63 => _63.httpStream, 'optionalAccess', _64 => _64.endpoint]) || endpointArg || envEndpoint || "/mcp";
2167
+ const host = _optionalChain([overrides, 'optionalAccess', _68 => _68.httpStream, 'optionalAccess', _69 => _69.host]) || hostArg || envHost || "localhost";
2168
+ const endpoint = _optionalChain([overrides, 'optionalAccess', _70 => _70.httpStream, 'optionalAccess', _71 => _71.endpoint]) || endpointArg || envEndpoint || "/mcp";
2137
2169
  const basePath = normalizeBasePath(
2138
- _optionalChain([overrides, 'optionalAccess', _65 => _65.httpStream, 'optionalAccess', _66 => _66.basePath]) || basePathArg || envBasePath
2170
+ _optionalChain([overrides, 'optionalAccess', _72 => _72.httpStream, 'optionalAccess', _73 => _73.basePath]) || basePathArg || envBasePath
2139
2171
  );
2140
- const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _67 => _67.httpStream, 'optionalAccess', _68 => _68.enableJsonResponse]) || false;
2141
- const stateless = _optionalChain([overrides, 'optionalAccess', _69 => _69.httpStream, 'optionalAccess', _70 => _70.stateless]) || statelessArg === "true" || envStateless === "true" || false;
2142
- const cors = _optionalChain([overrides, 'optionalAccess', _71 => _71.httpStream, 'optionalAccess', _72 => _72.cors]);
2143
- const eventStore = _optionalChain([overrides, 'optionalAccess', _73 => _73.httpStream, 'optionalAccess', _74 => _74.eventStore]);
2144
- const sslCa = _optionalChain([overrides, 'optionalAccess', _75 => _75.httpStream, 'optionalAccess', _76 => _76.sslCa]);
2145
- const sslCert = _optionalChain([overrides, 'optionalAccess', _77 => _77.httpStream, 'optionalAccess', _78 => _78.sslCert]);
2146
- const sslKey = _optionalChain([overrides, 'optionalAccess', _79 => _79.httpStream, 'optionalAccess', _80 => _80.sslKey]);
2172
+ const enableJsonResponse = _optionalChain([overrides, 'optionalAccess', _74 => _74.httpStream, 'optionalAccess', _75 => _75.enableJsonResponse]) || false;
2173
+ const stateless = _optionalChain([overrides, 'optionalAccess', _76 => _76.httpStream, 'optionalAccess', _77 => _77.stateless]) || statelessArg === "true" || envStateless === "true" || false;
2174
+ const cors = _optionalChain([overrides, 'optionalAccess', _78 => _78.httpStream, 'optionalAccess', _79 => _79.cors]);
2175
+ const eventStore = _optionalChain([overrides, 'optionalAccess', _80 => _80.httpStream, 'optionalAccess', _81 => _81.eventStore]);
2176
+ const sslCa = _optionalChain([overrides, 'optionalAccess', _82 => _82.httpStream, 'optionalAccess', _83 => _83.sslCa]);
2177
+ const sslCert = _optionalChain([overrides, 'optionalAccess', _84 => _84.httpStream, 'optionalAccess', _85 => _85.sslCert]);
2178
+ const sslKey = _optionalChain([overrides, 'optionalAccess', _86 => _86.httpStream, 'optionalAccess', _87 => _87.sslKey]);
2147
2179
  return {
2148
2180
  httpStream: {
2149
2181
  basePath,
@@ -2216,4 +2248,4 @@ var FastMCP = class extends FastMCPEventEmitter {
2216
2248
 
2217
2249
 
2218
2250
  exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ServerState = ServerState; exports.FastMCPSession = FastMCPSession; exports.FastMCP = FastMCP;
2219
- //# sourceMappingURL=chunk-3YTRRGCE.cjs.map
2251
+ //# sourceMappingURL=chunk-BJF2JTTE.cjs.map