fastmcp 4.4.0 → 4.6.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 +98 -0
- package/dist/FastMCP.cjs +2 -2
- package/dist/FastMCP.d.cts +24 -7
- package/dist/FastMCP.d.ts +24 -7
- package/dist/FastMCP.js +1 -1
- package/dist/{chunk-MDIESGNI.js → chunk-HSSO6TVV.js} +79 -42
- package/dist/chunk-HSSO6TVV.js.map +1 -0
- package/dist/{chunk-3YTRRGCE.cjs → chunk-VBRUMQDO.cjs} +109 -72
- package/dist/chunk-VBRUMQDO.cjs.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-3YTRRGCE.cjs.map +0 -1
- package/dist/chunk-MDIESGNI.js.map +0 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ A TypeScript framework for building [MCP](https://glama.ai/mcp) servers capable
|
|
|
29
29
|
- [Typed server events](#typed-server-events)
|
|
30
30
|
- [Prompt argument auto-completion](#prompt-argument-auto-completion)
|
|
31
31
|
- [Sampling](#requestsampling)
|
|
32
|
+
- [Elicitation](#elicitation)
|
|
32
33
|
- [Configurable ping behavior](#configurable-ping-behavior)
|
|
33
34
|
- [Health-check endpoint](#health-check-endpoint)
|
|
34
35
|
- [Roots](#roots-management)
|
|
@@ -1244,6 +1245,44 @@ server.addTool({
|
|
|
1244
1245
|
});
|
|
1245
1246
|
```
|
|
1246
1247
|
|
|
1248
|
+
#### Elicitation
|
|
1249
|
+
|
|
1250
|
+
Tools can request additional information from the user mid-execution via [elicitation](https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation), using the `elicit` method in the context object. The client must advertise the matching `elicitation` capability mode — `elicitation: { form: {} }` for form requests (the default) and/or `elicitation: { url: {} }` for url requests.
|
|
1251
|
+
|
|
1252
|
+
```js
|
|
1253
|
+
server.addTool({
|
|
1254
|
+
name: "delete-file",
|
|
1255
|
+
description: "Delete a file",
|
|
1256
|
+
parameters: z.object({
|
|
1257
|
+
path: z.string(),
|
|
1258
|
+
}),
|
|
1259
|
+
execute: async (args, { elicit }) => {
|
|
1260
|
+
const response = await elicit({
|
|
1261
|
+
message: `Are you sure you want to delete ${args.path}?`,
|
|
1262
|
+
requestedSchema: {
|
|
1263
|
+
type: "object",
|
|
1264
|
+
properties: {
|
|
1265
|
+
confirmed: {
|
|
1266
|
+
type: "boolean",
|
|
1267
|
+
},
|
|
1268
|
+
},
|
|
1269
|
+
required: ["confirmed"],
|
|
1270
|
+
},
|
|
1271
|
+
});
|
|
1272
|
+
|
|
1273
|
+
if (response.action !== "accept" || !response.content?.confirmed) {
|
|
1274
|
+
return "Deletion cancelled.";
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// ...
|
|
1278
|
+
|
|
1279
|
+
return `Deleted ${args.path}`;
|
|
1280
|
+
},
|
|
1281
|
+
});
|
|
1282
|
+
```
|
|
1283
|
+
|
|
1284
|
+
The response `action` is `"accept"`, `"decline"`, or `"cancel"`; on accept, `content` holds the user's answers matching `requestedSchema`. Elicitation is also available outside of tools via [`session.requestElicitation`](#requestelicitation).
|
|
1285
|
+
|
|
1247
1286
|
#### Tool Annotations
|
|
1248
1287
|
|
|
1249
1288
|
As of the MCP Specification (2025-03-26), tools can include annotations that provide richer context and control by adding metadata about a tool's behavior:
|
|
@@ -1329,6 +1368,23 @@ async load() {
|
|
|
1329
1368
|
}
|
|
1330
1369
|
```
|
|
1331
1370
|
|
|
1371
|
+
`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:
|
|
1372
|
+
|
|
1373
|
+
```ts
|
|
1374
|
+
server.addResource({
|
|
1375
|
+
uri: "file:///logs/app.log",
|
|
1376
|
+
name: "Application Logs",
|
|
1377
|
+
mimeType: "text/plain",
|
|
1378
|
+
async load(auth, context) {
|
|
1379
|
+
context.log.info("loading application logs", { requestedBy: auth?.userId });
|
|
1380
|
+
|
|
1381
|
+
return {
|
|
1382
|
+
text: await readLogFile(),
|
|
1383
|
+
};
|
|
1384
|
+
},
|
|
1385
|
+
});
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1332
1388
|
### Resource templates
|
|
1333
1389
|
|
|
1334
1390
|
You can also define resource templates:
|
|
@@ -1353,6 +1409,8 @@ server.addResourceTemplate({
|
|
|
1353
1409
|
});
|
|
1354
1410
|
```
|
|
1355
1411
|
|
|
1412
|
+
Like plain resources, `load` also receives `auth` and `context` as its second and third arguments (see [Resources](#resources)).
|
|
1413
|
+
|
|
1356
1414
|
#### Resource template argument auto-completion
|
|
1357
1415
|
|
|
1358
1416
|
Provide `complete` functions for resource template arguments to enable automatic completion:
|
|
@@ -1517,6 +1575,27 @@ server.addPrompt({
|
|
|
1517
1575
|
});
|
|
1518
1576
|
```
|
|
1519
1577
|
|
|
1578
|
+
Like resources, `load` also receives `auth` and `context` as its second and third arguments (see [Resources](#resources)):
|
|
1579
|
+
|
|
1580
|
+
```ts
|
|
1581
|
+
server.addPrompt({
|
|
1582
|
+
name: "git-commit",
|
|
1583
|
+
description: "Generate a Git commit message",
|
|
1584
|
+
arguments: [
|
|
1585
|
+
{
|
|
1586
|
+
name: "changes",
|
|
1587
|
+
description: "Git diff or description of changes",
|
|
1588
|
+
required: true,
|
|
1589
|
+
},
|
|
1590
|
+
],
|
|
1591
|
+
load: async (args, auth, context) => {
|
|
1592
|
+
context.log.debug("generating git commit prompt", { user: auth?.userId });
|
|
1593
|
+
|
|
1594
|
+
return `Generate a concise but descriptive commit message for these changes:\n\n${args.changes}`;
|
|
1595
|
+
},
|
|
1596
|
+
});
|
|
1597
|
+
```
|
|
1598
|
+
|
|
1520
1599
|
#### Prompt argument auto-completion
|
|
1521
1600
|
|
|
1522
1601
|
Prompts can provide auto-completion for their arguments:
|
|
@@ -2203,6 +2282,25 @@ server.on("disconnect", (event) => {
|
|
|
2203
2282
|
|
|
2204
2283
|
Refer to [Sessions](#sessions) for examples of how to obtain a `FastMCPSession` instance.
|
|
2205
2284
|
|
|
2285
|
+
### `requestElicitation`
|
|
2286
|
+
|
|
2287
|
+
`requestElicitation` creates an [elicitation](https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation) request to collect additional information from the user via the client and returns the response. The client must advertise the matching `elicitation` capability mode — `elicitation: { form: {} }` for form requests (the default) and/or `elicitation: { url: {} }` for url requests.
|
|
2288
|
+
|
|
2289
|
+
```ts
|
|
2290
|
+
await session.requestElicitation({
|
|
2291
|
+
message: "What is your name?",
|
|
2292
|
+
requestedSchema: {
|
|
2293
|
+
type: "object",
|
|
2294
|
+
properties: {
|
|
2295
|
+
name: { type: "string" },
|
|
2296
|
+
},
|
|
2297
|
+
required: ["name"],
|
|
2298
|
+
},
|
|
2299
|
+
});
|
|
2300
|
+
```
|
|
2301
|
+
|
|
2302
|
+
Inside a tool, prefer the `elicit` method from the [context object](#elicitation).
|
|
2303
|
+
|
|
2206
2304
|
### `requestSampling`
|
|
2207
2305
|
|
|
2208
2306
|
`requestSampling` creates a [sampling](https://modelcontextprotocol.io/docs/concepts/sampling) request and returns the response.
|
package/dist/FastMCP.cjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _chunkVBRUMQDOcjs = require('./chunk-VBRUMQDO.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 = _chunkVBRUMQDOcjs.DiscoveryDocumentCache; exports.FastMCP = _chunkVBRUMQDOcjs.FastMCP; exports.FastMCPSession = _chunkVBRUMQDOcjs.FastMCPSession; exports.GitHubProvider = _chunkIX3HKAX4cjs.GitHubProvider; exports.GoogleProvider = _chunkIX3HKAX4cjs.GoogleProvider; exports.OAuthProvider = _chunkIX3HKAX4cjs.OAuthProvider; exports.ServerState = _chunkVBRUMQDOcjs.ServerState; exports.UnexpectedStateError = _chunkVBRUMQDOcjs.UnexpectedStateError; exports.UserError = _chunkVBRUMQDOcjs.UserError; exports.audioContent = _chunkVBRUMQDOcjs.audioContent; exports.getAuthSession = _chunkIX3HKAX4cjs.getAuthSession; exports.imageContent = _chunkVBRUMQDOcjs.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
|
@@ -2,7 +2,7 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
|
2
2
|
import { EventStore } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
3
|
import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
4
4
|
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
5
|
-
import { ResourceLink, Root, ClientCapabilities, GetPromptResult, CreateMessageRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { ResourceLink, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, Root, ClientCapabilities, GetPromptResult, CreateMessageRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
export { ResourceLink } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
8
8
|
import { EventEmitter } from 'events';
|
|
@@ -92,6 +92,14 @@ type Context<T extends FastMCPSessionAuth> = {
|
|
|
92
92
|
client: {
|
|
93
93
|
version: ReturnType<Server["getClientVersion"]>;
|
|
94
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Requests additional information from the user via the client
|
|
97
|
+
* (see https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation).
|
|
98
|
+
* The client must advertise the matching `elicitation` capability mode —
|
|
99
|
+
* `elicitation: { form: {} }` for form requests (the default) and/or
|
|
100
|
+
* `elicitation: { url: {} }` for url requests.
|
|
101
|
+
*/
|
|
102
|
+
elicit: (params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions) => Promise<ElicitResult>;
|
|
95
103
|
log: {
|
|
96
104
|
debug: (message: string, data?: SerializableValue) => void;
|
|
97
105
|
error: (message: string, data?: SerializableValue) => void;
|
|
@@ -117,6 +125,14 @@ type Context<T extends FastMCPSessionAuth> = {
|
|
|
117
125
|
type Extra = unknown;
|
|
118
126
|
type Extras = Record<string, Extra>;
|
|
119
127
|
type Literal = boolean | null | number | string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Context passed to `load` for resources, resource templates, and prompts.
|
|
130
|
+
*
|
|
131
|
+
* This is a subset of the tool execution {@link Context}. `reportProgress`
|
|
132
|
+
* and `streamContent` are tied to a tool call's progress token / streaming
|
|
133
|
+
* notification and are not available outside of `tool.execute`.
|
|
134
|
+
*/
|
|
135
|
+
type LoadContext<T extends FastMCPSessionAuth> = Omit<Context<T>, "reportProgress" | "streamContent">;
|
|
120
136
|
type Progress = {
|
|
121
137
|
/**
|
|
122
138
|
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
@@ -182,7 +198,7 @@ type InputPrompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments ex
|
|
|
182
198
|
arguments?: InputPromptArgument<T>[];
|
|
183
199
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
184
200
|
description?: string;
|
|
185
|
-
load: (args: Args, auth?: T) => Promise<PromptResult>;
|
|
201
|
+
load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
|
|
186
202
|
name: string;
|
|
187
203
|
};
|
|
188
204
|
type InputPromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
|
|
@@ -196,7 +212,7 @@ type InputResourceTemplate<T extends FastMCPSessionAuth, Arguments extends Input
|
|
|
196
212
|
arguments: Arguments;
|
|
197
213
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
198
214
|
description?: string;
|
|
199
|
-
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
|
|
215
|
+
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
|
|
200
216
|
mimeType?: string;
|
|
201
217
|
name: string;
|
|
202
218
|
uriTemplate: string;
|
|
@@ -212,7 +228,7 @@ type Prompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments extends
|
|
|
212
228
|
arguments?: PromptArgument<T>[];
|
|
213
229
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
214
230
|
description?: string;
|
|
215
|
-
load: (args: Args, auth?: T) => Promise<PromptResult>;
|
|
231
|
+
load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
|
|
216
232
|
name: string;
|
|
217
233
|
};
|
|
218
234
|
type PromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
|
|
@@ -234,7 +250,7 @@ type PromptResult = Pick<GetPromptResult, "messages"> | string;
|
|
|
234
250
|
type Resource<T extends FastMCPSessionAuth> = {
|
|
235
251
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
236
252
|
description?: string;
|
|
237
|
-
load: (auth?: T) => Promise<ResourceResult | ResourceResult[]>;
|
|
253
|
+
load: (auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
|
|
238
254
|
mimeType?: string;
|
|
239
255
|
name: string;
|
|
240
256
|
uri: string;
|
|
@@ -252,7 +268,7 @@ type ResourceTemplate<T extends FastMCPSessionAuth, Arguments extends ResourceTe
|
|
|
252
268
|
arguments: Arguments;
|
|
253
269
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
254
270
|
description?: string;
|
|
255
|
-
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
|
|
271
|
+
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
|
|
256
272
|
mimeType?: string;
|
|
257
273
|
name: string;
|
|
258
274
|
uriTemplate: string;
|
|
@@ -729,6 +745,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
|
|
|
729
745
|
close(): Promise<void>;
|
|
730
746
|
connect(transport: Transport): Promise<void>;
|
|
731
747
|
promptsListChanged(prompts: Prompt<T>[]): void;
|
|
748
|
+
requestElicitation(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions): Promise<ElicitResult>;
|
|
732
749
|
requestSampling(message: z.infer<typeof CreateMessageRequestSchema>["params"], options?: RequestOptions): Promise<SamplingResponse>;
|
|
733
750
|
resourcesListChanged(resources: Resource<T>[]): void;
|
|
734
751
|
resourceTemplatesListChanged(resourceTemplates: ResourceTemplate<T>[]): void;
|
|
@@ -881,4 +898,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
881
898
|
stop(): Promise<void>;
|
|
882
899
|
}
|
|
883
900
|
|
|
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 };
|
|
901
|
+
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
|
@@ -2,7 +2,7 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
|
2
2
|
import { EventStore } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
3
|
import { RequestOptions } from '@modelcontextprotocol/sdk/shared/protocol.js';
|
|
4
4
|
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
5
|
-
import { ResourceLink, Root, ClientCapabilities, GetPromptResult, CreateMessageRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { ResourceLink, ElicitRequestFormParams, ElicitRequestURLParams, ElicitResult, Root, ClientCapabilities, GetPromptResult, CreateMessageRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
export { ResourceLink } from '@modelcontextprotocol/sdk/types.js';
|
|
7
7
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
8
8
|
import { EventEmitter } from 'events';
|
|
@@ -92,6 +92,14 @@ type Context<T extends FastMCPSessionAuth> = {
|
|
|
92
92
|
client: {
|
|
93
93
|
version: ReturnType<Server["getClientVersion"]>;
|
|
94
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Requests additional information from the user via the client
|
|
97
|
+
* (see https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation).
|
|
98
|
+
* The client must advertise the matching `elicitation` capability mode —
|
|
99
|
+
* `elicitation: { form: {} }` for form requests (the default) and/or
|
|
100
|
+
* `elicitation: { url: {} }` for url requests.
|
|
101
|
+
*/
|
|
102
|
+
elicit: (params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions) => Promise<ElicitResult>;
|
|
95
103
|
log: {
|
|
96
104
|
debug: (message: string, data?: SerializableValue) => void;
|
|
97
105
|
error: (message: string, data?: SerializableValue) => void;
|
|
@@ -117,6 +125,14 @@ type Context<T extends FastMCPSessionAuth> = {
|
|
|
117
125
|
type Extra = unknown;
|
|
118
126
|
type Extras = Record<string, Extra>;
|
|
119
127
|
type Literal = boolean | null | number | string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* Context passed to `load` for resources, resource templates, and prompts.
|
|
130
|
+
*
|
|
131
|
+
* This is a subset of the tool execution {@link Context}. `reportProgress`
|
|
132
|
+
* and `streamContent` are tied to a tool call's progress token / streaming
|
|
133
|
+
* notification and are not available outside of `tool.execute`.
|
|
134
|
+
*/
|
|
135
|
+
type LoadContext<T extends FastMCPSessionAuth> = Omit<Context<T>, "reportProgress" | "streamContent">;
|
|
120
136
|
type Progress = {
|
|
121
137
|
/**
|
|
122
138
|
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
@@ -182,7 +198,7 @@ type InputPrompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments ex
|
|
|
182
198
|
arguments?: InputPromptArgument<T>[];
|
|
183
199
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
184
200
|
description?: string;
|
|
185
|
-
load: (args: Args, auth?: T) => Promise<PromptResult>;
|
|
201
|
+
load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
|
|
186
202
|
name: string;
|
|
187
203
|
};
|
|
188
204
|
type InputPromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
|
|
@@ -196,7 +212,7 @@ type InputResourceTemplate<T extends FastMCPSessionAuth, Arguments extends Input
|
|
|
196
212
|
arguments: Arguments;
|
|
197
213
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
198
214
|
description?: string;
|
|
199
|
-
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
|
|
215
|
+
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
|
|
200
216
|
mimeType?: string;
|
|
201
217
|
name: string;
|
|
202
218
|
uriTemplate: string;
|
|
@@ -212,7 +228,7 @@ type Prompt<T extends FastMCPSessionAuth = FastMCPSessionAuth, Arguments extends
|
|
|
212
228
|
arguments?: PromptArgument<T>[];
|
|
213
229
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
214
230
|
description?: string;
|
|
215
|
-
load: (args: Args, auth?: T) => Promise<PromptResult>;
|
|
231
|
+
load: (args: Args, auth?: T, context?: LoadContext<T>) => Promise<PromptResult>;
|
|
216
232
|
name: string;
|
|
217
233
|
};
|
|
218
234
|
type PromptArgument<T extends FastMCPSessionAuth = FastMCPSessionAuth> = Readonly<{
|
|
@@ -234,7 +250,7 @@ type PromptResult = Pick<GetPromptResult, "messages"> | string;
|
|
|
234
250
|
type Resource<T extends FastMCPSessionAuth> = {
|
|
235
251
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
236
252
|
description?: string;
|
|
237
|
-
load: (auth?: T) => Promise<ResourceResult | ResourceResult[]>;
|
|
253
|
+
load: (auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
|
|
238
254
|
mimeType?: string;
|
|
239
255
|
name: string;
|
|
240
256
|
uri: string;
|
|
@@ -252,7 +268,7 @@ type ResourceTemplate<T extends FastMCPSessionAuth, Arguments extends ResourceTe
|
|
|
252
268
|
arguments: Arguments;
|
|
253
269
|
complete?: (name: string, value: string, auth?: T) => Promise<Completion>;
|
|
254
270
|
description?: string;
|
|
255
|
-
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T) => Promise<ResourceResult | ResourceResult[]>;
|
|
271
|
+
load: (args: ResourceTemplateArgumentsToObject<Arguments>, auth?: T, context?: LoadContext<T>) => Promise<ResourceResult | ResourceResult[]>;
|
|
256
272
|
mimeType?: string;
|
|
257
273
|
name: string;
|
|
258
274
|
uriTemplate: string;
|
|
@@ -729,6 +745,7 @@ declare class FastMCPSession<T extends FastMCPSessionAuth = FastMCPSessionAuth>
|
|
|
729
745
|
close(): Promise<void>;
|
|
730
746
|
connect(transport: Transport): Promise<void>;
|
|
731
747
|
promptsListChanged(prompts: Prompt<T>[]): void;
|
|
748
|
+
requestElicitation(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions): Promise<ElicitResult>;
|
|
732
749
|
requestSampling(message: z.infer<typeof CreateMessageRequestSchema>["params"], options?: RequestOptions): Promise<SamplingResponse>;
|
|
733
750
|
resourcesListChanged(resources: Resource<T>[]): void;
|
|
734
751
|
resourceTemplatesListChanged(resourceTemplates: ResourceTemplate<T>[]): void;
|
|
@@ -881,4 +898,4 @@ declare class FastMCP<T extends FastMCPSessionAuth = FastMCPSessionAuth> extends
|
|
|
881
898
|
stop(): Promise<void>;
|
|
882
899
|
}
|
|
883
900
|
|
|
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 };
|
|
901
|
+
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
|
@@ -526,6 +526,9 @@ ${e instanceof Error ? e.stack : JSON.stringify(e)}`
|
|
|
526
526
|
this.setupPromptHandlers();
|
|
527
527
|
this.triggerListChangedNotification("notifications/prompts/list_changed");
|
|
528
528
|
}
|
|
529
|
+
async requestElicitation(params, options) {
|
|
530
|
+
return this.#server.elicitInput(params, options);
|
|
531
|
+
}
|
|
529
532
|
async requestSampling(message, options) {
|
|
530
533
|
return this.#server.createMessage(message, options);
|
|
531
534
|
}
|
|
@@ -599,6 +602,68 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
599
602
|
});
|
|
600
603
|
});
|
|
601
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* Builds the context object passed as the third argument to
|
|
607
|
+
* `resource.load` / `resourceTemplate.load` / `prompt.load`.
|
|
608
|
+
*
|
|
609
|
+
* This mirrors the `client`, `elicit`, `log`, `requestId`, `session`,
|
|
610
|
+
* and `sessionId` fields available to `tool.execute` via {@link Context}.
|
|
611
|
+
* `reportProgress` and `streamContent` are intentionally omitted: they
|
|
612
|
+
* are tied to a tool call's progress token / streaming notification,
|
|
613
|
+
* which resource and prompt reads do not have.
|
|
614
|
+
*/
|
|
615
|
+
#createLoadContext(meta) {
|
|
616
|
+
return {
|
|
617
|
+
client: {
|
|
618
|
+
version: this.#server.getClientVersion()
|
|
619
|
+
},
|
|
620
|
+
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
621
|
+
log: this.#createLog(),
|
|
622
|
+
requestId: typeof meta?.requestId === "string" ? meta.requestId : void 0,
|
|
623
|
+
session: this.#auth,
|
|
624
|
+
sessionId: this.#sessionId
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
#createLog() {
|
|
628
|
+
return {
|
|
629
|
+
debug: (message, context) => {
|
|
630
|
+
this.#server.sendLoggingMessage({
|
|
631
|
+
data: {
|
|
632
|
+
context,
|
|
633
|
+
message
|
|
634
|
+
},
|
|
635
|
+
level: "debug"
|
|
636
|
+
});
|
|
637
|
+
},
|
|
638
|
+
error: (message, context) => {
|
|
639
|
+
this.#server.sendLoggingMessage({
|
|
640
|
+
data: {
|
|
641
|
+
context,
|
|
642
|
+
message
|
|
643
|
+
},
|
|
644
|
+
level: "error"
|
|
645
|
+
});
|
|
646
|
+
},
|
|
647
|
+
info: (message, context) => {
|
|
648
|
+
this.#server.sendLoggingMessage({
|
|
649
|
+
data: {
|
|
650
|
+
context,
|
|
651
|
+
message
|
|
652
|
+
},
|
|
653
|
+
level: "info"
|
|
654
|
+
});
|
|
655
|
+
},
|
|
656
|
+
warn: (message, context) => {
|
|
657
|
+
this.#server.sendLoggingMessage({
|
|
658
|
+
data: {
|
|
659
|
+
context,
|
|
660
|
+
message
|
|
661
|
+
},
|
|
662
|
+
level: "warning"
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
}
|
|
602
667
|
#formatSchemaIssues(issues) {
|
|
603
668
|
return this.#utils?.formatInvalidParamsErrorMessage ? this.#utils.formatInvalidParamsErrorMessage(issues) : issues.map((issue) => {
|
|
604
669
|
const path = issue.path?.join(".") || "root";
|
|
@@ -812,7 +877,8 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
812
877
|
try {
|
|
813
878
|
result = await prompt.load(
|
|
814
879
|
args,
|
|
815
|
-
this.#auth
|
|
880
|
+
this.#auth,
|
|
881
|
+
this.#createLoadContext(request.params?._meta)
|
|
816
882
|
);
|
|
817
883
|
} catch (error) {
|
|
818
884
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -874,7 +940,11 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
874
940
|
continue;
|
|
875
941
|
}
|
|
876
942
|
const uri = uriTemplate.fill(match);
|
|
877
|
-
const result = await resourceTemplate.load(
|
|
943
|
+
const result = await resourceTemplate.load(
|
|
944
|
+
match,
|
|
945
|
+
this.#auth,
|
|
946
|
+
this.#createLoadContext(request.params?._meta)
|
|
947
|
+
);
|
|
878
948
|
const resources = Array.isArray(result) ? result : [result];
|
|
879
949
|
return {
|
|
880
950
|
contents: resources.map((resource2) => ({
|
|
@@ -896,7 +966,10 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
896
966
|
}
|
|
897
967
|
let maybeArrayResult;
|
|
898
968
|
try {
|
|
899
|
-
maybeArrayResult = await resource.load(
|
|
969
|
+
maybeArrayResult = await resource.load(
|
|
970
|
+
this.#auth,
|
|
971
|
+
this.#createLoadContext(request.params?._meta)
|
|
972
|
+
);
|
|
900
973
|
} catch (error) {
|
|
901
974
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
902
975
|
throw new McpError(
|
|
@@ -1065,44 +1138,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1065
1138
|
);
|
|
1066
1139
|
}
|
|
1067
1140
|
};
|
|
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
|
-
};
|
|
1141
|
+
const log = this.#createLog();
|
|
1106
1142
|
const streamContent = async (content) => {
|
|
1107
1143
|
const contentArray = Array.isArray(content) ? content : [content];
|
|
1108
1144
|
try {
|
|
@@ -1133,6 +1169,7 @@ ${error instanceof Error ? error.stack : JSON.stringify(error)}`
|
|
|
1133
1169
|
client: {
|
|
1134
1170
|
version: this.#server.getClientVersion()
|
|
1135
1171
|
},
|
|
1172
|
+
elicit: (params, options) => this.#server.elicitInput(params, options),
|
|
1136
1173
|
log,
|
|
1137
1174
|
reportProgress,
|
|
1138
1175
|
requestId: typeof request.params?._meta?.requestId === "string" ? request.params._meta.requestId : void 0,
|
|
@@ -2216,4 +2253,4 @@ export {
|
|
|
2216
2253
|
FastMCPSession,
|
|
2217
2254
|
FastMCP
|
|
2218
2255
|
};
|
|
2219
|
-
//# sourceMappingURL=chunk-
|
|
2256
|
+
//# sourceMappingURL=chunk-HSSO6TVV.js.map
|