fastmcp 4.3.2 → 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 +62 -0
- package/dist/FastMCP.cjs +2 -2
- package/dist/FastMCP.d.cts +15 -6
- package/dist/FastMCP.d.ts +15 -6
- package/dist/FastMCP.js +1 -1
- package/dist/{chunk-UYG7NPM6.cjs → chunk-BJF2JTTE.cjs} +163 -88
- package/dist/chunk-BJF2JTTE.cjs.map +1 -0
- package/dist/{chunk-LWU5CQGW.js → chunk-BTMLQWIR.js} +134 -59
- package/dist/chunk-BTMLQWIR.js.map +1 -0
- package/dist/examples/custom-routes.cjs +2 -2
- package/dist/examples/custom-routes.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-LWU5CQGW.js.map +0 -1
- package/dist/chunk-UYG7NPM6.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -139,6 +139,8 @@ This will start the server and listen for HTTP streaming connections on `http://
|
|
|
139
139
|
|
|
140
140
|
> **Note:** You can also customize the endpoint path using the `httpStream.endpoint` option (default is `/mcp`).
|
|
141
141
|
|
|
142
|
+
> **Note:** To serve HTTP streaming and built-in OAuth routes under an issuer path, set `httpStream.basePath` (for example, `/issuer1`). This exposes authorization server metadata at `/.well-known/oauth-authorization-server/issuer1` per RFC 8414.
|
|
143
|
+
|
|
142
144
|
> **Note:** This also starts an SSE server on `http://localhost:8080/sse`.
|
|
143
145
|
|
|
144
146
|
You can connect to these servers using the appropriate client transport.
|
|
@@ -1327,6 +1329,23 @@ async load() {
|
|
|
1327
1329
|
}
|
|
1328
1330
|
```
|
|
1329
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
|
+
|
|
1330
1349
|
### Resource templates
|
|
1331
1350
|
|
|
1332
1351
|
You can also define resource templates:
|
|
@@ -1351,6 +1370,8 @@ server.addResourceTemplate({
|
|
|
1351
1370
|
});
|
|
1352
1371
|
```
|
|
1353
1372
|
|
|
1373
|
+
Like plain resources, `load` also receives `auth` and `context` as its second and third arguments (see [Resources](#resources)).
|
|
1374
|
+
|
|
1354
1375
|
#### Resource template argument auto-completion
|
|
1355
1376
|
|
|
1356
1377
|
Provide `complete` functions for resource template arguments to enable automatic completion:
|
|
@@ -1515,6 +1536,27 @@ server.addPrompt({
|
|
|
1515
1536
|
});
|
|
1516
1537
|
```
|
|
1517
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
|
+
|
|
1518
1560
|
#### Prompt argument auto-completion
|
|
1519
1561
|
|
|
1520
1562
|
Prompts can provide auto-completion for their arguments:
|
|
@@ -1923,9 +1965,29 @@ const server = new FastMCP({
|
|
|
1923
1965
|
});
|
|
1924
1966
|
```
|
|
1925
1967
|
|
|
1968
|
+
If your MCP server is published below an issuer path, configure the HTTP
|
|
1969
|
+
stream base path as well:
|
|
1970
|
+
|
|
1971
|
+
```ts
|
|
1972
|
+
server.start({
|
|
1973
|
+
transportType: "httpStream",
|
|
1974
|
+
httpStream: {
|
|
1975
|
+
basePath: "/issuer1",
|
|
1976
|
+
endpoint: "/mcp",
|
|
1977
|
+
port: 8080,
|
|
1978
|
+
},
|
|
1979
|
+
});
|
|
1980
|
+
```
|
|
1981
|
+
|
|
1982
|
+
With this configuration, FastMCP serves the issuer-path authorization server
|
|
1983
|
+
metadata at `/.well-known/oauth-authorization-server/issuer1`, while protected
|
|
1984
|
+
resource metadata remains available for the MCP endpoint at
|
|
1985
|
+
`/.well-known/oauth-protected-resource/issuer1/mcp`.
|
|
1986
|
+
|
|
1926
1987
|
This configuration automatically exposes OAuth discovery endpoints:
|
|
1927
1988
|
|
|
1928
1989
|
- `/.well-known/oauth-authorization-server` - Authorization server metadata (RFC 8414)
|
|
1990
|
+
- `/.well-known/oauth-authorization-server<basePath>` - Authorization server metadata when `httpStream.basePath` is set (RFC 8414 Section 3)
|
|
1929
1991
|
- `/.well-known/oauth-protected-resource` - Protected resource metadata (RFC 9728)
|
|
1930
1992
|
- `/.well-known/oauth-protected-resource<endpoint>` - Protected resource metadata at sub-path (MCP 2025-11-25)
|
|
1931
1993
|
|
package/dist/FastMCP.cjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
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 =
|
|
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
|
package/dist/FastMCP.d.cts
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;
|
|
@@ -861,6 +869,7 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
861
869
|
*/
|
|
862
870
|
start(options?: Partial<{
|
|
863
871
|
httpStream: {
|
|
872
|
+
basePath?: `/${string}`;
|
|
864
873
|
cors?: boolean | CorsOptions;
|
|
865
874
|
enableJsonResponse?: boolean;
|
|
866
875
|
endpoint?: `/${string}`;
|
|
@@ -880,4 +889,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
880
889
|
stop(): Promise<void>;
|
|
881
890
|
}
|
|
882
891
|
|
|
883
|
-
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;
|
|
@@ -861,6 +869,7 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
861
869
|
*/
|
|
862
870
|
start(options?: Partial<{
|
|
863
871
|
httpStream: {
|
|
872
|
+
basePath?: `/${string}`;
|
|
864
873
|
cors?: boolean | CorsOptions;
|
|
865
874
|
enableJsonResponse?: boolean;
|
|
866
875
|
endpoint?: `/${string}`;
|
|
@@ -880,4 +889,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
880
889
|
stop(): Promise<void>;
|
|
881
890
|
}
|
|
882
891
|
|
|
883
|
-
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 };
|