fastmcp 3.7.0 → 3.8.1

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.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { EventStore } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
2
3
  import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
4
  import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
4
5
  import { ResourceLink, Root, ClientCapabilities, GetPromptResult, CreateMessageRequestSchema } from '@modelcontextprotocol/sdk/types.js';
@@ -116,44 +117,44 @@ type Completion = {
116
117
  total?: number;
117
118
  values: string[];
118
119
  };
119
- type ArgumentValueCompleter = (value: string) => Promise<Completion>;
120
- type InputPrompt<Arguments extends InputPromptArgument[] = InputPromptArgument[], Args = PromptArgumentsToObject<Arguments>> = {
121
- arguments?: InputPromptArgument[];
120
+ type ArgumentValueCompleter<T extends FastMCPSessionAuth = FastMCPSessionAuth> = (value: string, auth?: T) => Promise<Completion>;
121
+ type InputPrompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments extends InputPromptArgument<T>[] = InputPromptArgument<T>[], Args = PromptArgumentsToObject<Arguments>> = {
122
+ arguments?: InputPromptArgument<T>[];
122
123
  description?: string;
123
- load: (args: Args) => Promise<PromptResult>;
124
+ load: (args: Args, auth?: T) => Promise<PromptResult>;
124
125
  name: string;
125
126
  };
126
- type InputPromptArgument = Readonly<{
127
- complete?: ArgumentValueCompleter;
127
+ type InputPromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
128
+ complete?: ArgumentValueCompleter<T>;
128
129
  description?: string;
129
130
  enum?: string[];
130
131
  name: string;
131
132
  required?: boolean;
132
133
  }>;
133
- type InputResourceTemplate<Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[]> = {
134
+ type InputResourceTemplate<T extends FastMCPSessionAuth, Arguments extends InputResourceTemplateArgument<T>[] = InputResourceTemplateArgument<T>[]> = {
134
135
  arguments: Arguments;
135
136
  description?: string;
136
- load: (args: ResourceTemplateArgumentsToObject<Arguments>) => Promise<ResourceResult | ResourceResult[]>;
137
+ load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
137
138
  mimeType?: string;
138
139
  name: string;
139
140
  uriTemplate: string;
140
141
  };
141
- type InputResourceTemplateArgument = Readonly<{
142
- complete?: ArgumentValueCompleter;
142
+ type InputResourceTemplateArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
143
+ complete?: ArgumentValueCompleter<T>;
143
144
  description?: string;
144
145
  name: string;
145
146
  required?: boolean;
146
147
  }>;
147
148
  type LoggingLevel = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
148
- type Prompt<Arguments extends PromptArgument[] = PromptArgument[], Args = PromptArgumentsToObject<Arguments>> = {
149
- arguments?: PromptArgument[];
150
- complete?: (name: string, value: string) => Promise<Completion>;
149
+ type Prompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments extends PromptArgument<T>[] = PromptArgument<T>[], Args = PromptArgumentsToObject<Arguments>> = {
150
+ arguments?: PromptArgument<T>[];
151
+ complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
151
152
  description?: string;
152
- load: (args: Args) => Promise<PromptResult>;
153
+ load: (args: Args, auth?: T) => Promise<PromptResult>;
153
154
  name: string;
154
155
  };
155
- type PromptArgument = Readonly<{
156
- complete?: ArgumentValueCompleter;
156
+ type PromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
157
+ complete?: ArgumentValueCompleter<T>;
157
158
  description?: string;
158
159
  enum?: string[];
159
160
  name: string;
@@ -168,10 +169,10 @@ type PromptArgumentsToObject<T extends {
168
169
  }>["required"] extends true ? string : string | undefined;
169
170
  };
170
171
  type PromptResult = Pick<GetPromptResult, "messages"> | string;
171
- type Resource = {
172
- complete?: (name: string, value: string) => Promise<Completion>;
172
+ type Resource<T extends FastMCPSessionAuth> = {
173
+ complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
173
174
  description?: string;
174
- load: () => Promise<ResourceResult | ResourceResult[]>;
175
+ load: (auth?: T) => Promise<ResourceResult | ResourceResult[]>;
175
176
  mimeType?: string;
176
177
  name: string;
177
178
  uri: string;
@@ -185,17 +186,17 @@ type ResourceResult = {
185
186
  text: string;
186
187
  uri?: string;
187
188
  };
188
- type ResourceTemplate<Arguments extends ResourceTemplateArgument[] = ResourceTemplateArgument[]> = {
189
+ type ResourceTemplate<T extends FastMCPSessionAuth, Arguments extends ResourceTemplateArgument<T>[] = ResourceTemplateArgument<T>[]> = {
189
190
  arguments: Arguments;
190
- complete?: (name: string, value: string) => Promise<Completion>;
191
+ complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
191
192
  description?: string;
192
- load: (args: ResourceTemplateArgumentsToObject<Arguments>) => Promise<ResourceResult | ResourceResult[]>;
193
+ load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
193
194
  mimeType?: string;
194
195
  name: string;
195
196
  uriTemplate: string;
196
197
  };
197
- type ResourceTemplateArgument = Readonly<{
198
- complete?: ArgumentValueCompleter;
198
+ type ResourceTemplateArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
199
+ complete?: ArgumentValueCompleter<T>;
199
200
  description?: string;
200
201
  name: string;
201
202
  required?: boolean;
@@ -388,6 +389,7 @@ type ToolAnnotations = {
388
389
  declare const FastMCPSessionEventEmitterBase: {
389
390
  new (): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;
390
391
  };
392
+ type Authenticate<T> = (request: http.IncomingMessage) => Promise<T>;
391
393
  type FastMCPSessionAuth = Record<string, unknown> | undefined;
392
394
  declare class FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {
393
395
  }
@@ -403,9 +405,9 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
403
405
  instructions?: string;
404
406
  name: string;
405
407
  ping?: ServerOptions<T>["ping"];
406
- prompts: Prompt[];
407
- resources: Resource[];
408
- resourcesTemplates: InputResourceTemplate[];
408
+ prompts: Prompt<T>[];
409
+ resources: Resource<T>[];
410
+ resourcesTemplates: InputResourceTemplate<T>[];
409
411
  roots?: ServerOptions<T>["roots"];
410
412
  tools: Tool<T>[];
411
413
  transportType?: "httpStream" | "stdio";
@@ -430,10 +432,9 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
430
432
  declare const FastMCPEventEmitterBase: {
431
433
  new (): StrictEventEmitter<EventEmitter, FastMCPEvents<FastMCPSessionAuth>>;
432
434
  };
433
- type Authenticate<T> = (request: http.IncomingMessage) => Promise<T>;
434
435
  declare class FastMCPEventEmitter extends FastMCPEventEmitterBase {
435
436
  }
436
- declare class FastMCP<T extends Record<string, unknown> | undefined = undefined> extends FastMCPEventEmitter {
437
+ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends FastMCPEventEmitter {
437
438
  #private;
438
439
  options: ServerOptions<T>;
439
440
  get sessions(): FastMCPSession<T>[];
@@ -441,15 +442,15 @@ declare class FastMCP<T extends Record<string, unknown> | undefined = undefined>
441
442
  /**
442
443
  * Adds a prompt to the server.
443
444
  */
444
- addPrompt<const Args extends InputPromptArgument[]>(prompt: InputPrompt<Args>): void;
445
+ addPrompt<const Args extends InputPromptArgument<T>[]>(prompt: InputPrompt<T, Args>): void;
445
446
  /**
446
447
  * Adds a resource to the server.
447
448
  */
448
- addResource(resource: Resource): void;
449
+ addResource(resource: Resource<T>): void;
449
450
  /**
450
451
  * Adds a resource template to the server.
451
452
  */
452
- addResourceTemplate<const Args extends InputResourceTemplateArgument[]>(resource: InputResourceTemplate<Args>): void;
453
+ addResourceTemplate<const Args extends InputResourceTemplateArgument[]>(resource: InputResourceTemplate<T, Args>): void;
453
454
  /**
454
455
  * Adds a tool to the server.
455
456
  */
@@ -467,6 +468,7 @@ declare class FastMCP<T extends Record<string, unknown> | undefined = undefined>
467
468
  start(options?: Partial<{
468
469
  httpStream: {
469
470
  endpoint?: `/${string}`;
471
+ eventStore?: EventStore;
470
472
  port: number;
471
473
  };
472
474
  transportType: "httpStream" | "stdio";
package/dist/FastMCP.js CHANGED
@@ -456,9 +456,9 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
456
456
  }
457
457
  const prompt = {
458
458
  ...inputPrompt,
459
- complete: async (name, value) => {
459
+ complete: async (name, value, auth) => {
460
460
  if (completers[name]) {
461
- return await completers[name](value);
461
+ return await completers[name](value, auth);
462
462
  }
463
463
  if (fuseInstances[name]) {
464
464
  const result = fuseInstances[name].search(value);
@@ -486,9 +486,9 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
486
486
  }
487
487
  const resourceTemplate = {
488
488
  ...inputResourceTemplate,
489
- complete: async (name, value) => {
489
+ complete: async (name, value, auth) => {
490
490
  if (completers[name]) {
491
- return await completers[name](value);
491
+ return await completers[name](value, auth);
492
492
  }
493
493
  return {
494
494
  values: []
@@ -516,7 +516,8 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
516
516
  const completion = CompletionZodSchema.parse(
517
517
  await prompt.complete(
518
518
  request.params.argument.name,
519
- request.params.argument.value
519
+ request.params.argument.value,
520
+ this.#auth
520
521
  )
521
522
  );
522
523
  return {
@@ -546,7 +547,8 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
546
547
  const completion = CompletionZodSchema.parse(
547
548
  await resource.complete(
548
549
  request.params.argument.name,
549
- request.params.argument.value
550
+ request.params.argument.value,
551
+ this.#auth
550
552
  )
551
553
  );
552
554
  return {
@@ -603,7 +605,10 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
603
605
  }
604
606
  let result;
605
607
  try {
606
- result = await prompt.load(args);
608
+ result = await prompt.load(
609
+ args,
610
+ this.#auth
611
+ );
607
612
  } catch (error) {
608
613
  const errorMessage = error instanceof Error ? error.message : String(error);
609
614
  throw new McpError(
@@ -657,7 +662,7 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
657
662
  continue;
658
663
  }
659
664
  const uri = uriTemplate.fill(match);
660
- const result = await resourceTemplate.load(match);
665
+ const result = await resourceTemplate.load(match, this.#auth);
661
666
  const resources2 = Array.isArray(result) ? result : [result];
662
667
  return {
663
668
  contents: resources2.map((resource2) => ({
@@ -679,7 +684,7 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
679
684
  }
680
685
  let maybeArrayResult;
681
686
  try {
682
- maybeArrayResult = await resource.load();
687
+ maybeArrayResult = await resource.load(this.#auth);
683
688
  } catch (error) {
684
689
  const errorMessage = error instanceof Error ? error.message : String(error);
685
690
  throw new McpError(
@@ -1096,6 +1101,7 @@ var FastMCP = class extends FastMCPEventEmitter {
1096
1101
  version: this.#options.version
1097
1102
  });
1098
1103
  },
1104
+ eventStore: httpConfig.eventStore,
1099
1105
  onClose: async (session) => {
1100
1106
  this.emit("disconnect", {
1101
1107
  session