@prefecthq/fastmcp-ts 0.0.2-alpha.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 +309 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/cli/index.cjs +45522 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/client.d.ts +543 -0
- package/dist/client.js +1758 -0
- package/dist/client.js.map +1 -0
- package/dist/server.d.ts +1023 -0
- package/dist/server.js +2863 -0
- package/dist/server.js.map +1 -0
- package/dist/zod-P5QUYVPB.js +14015 -0
- package/dist/zod-P5QUYVPB.js.map +1 -0
- package/package.json +110 -0
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,1023 @@
|
|
|
1
|
+
import { Transport } from '@modelcontextprotocol/sdk/shared/transport';
|
|
2
|
+
import { OAuthServerProvider, AuthorizationParams } from '@modelcontextprotocol/sdk/server/auth/provider';
|
|
3
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
4
|
+
import { Readable, Writable } from 'node:stream';
|
|
5
|
+
import { Server } from '@modelcontextprotocol/sdk/server';
|
|
6
|
+
import { CallToolResult } from '@modelcontextprotocol/sdk/types';
|
|
7
|
+
import { Response } from 'express';
|
|
8
|
+
import { OAuthClientInformationFull } from '@modelcontextprotocol/sdk/shared/auth';
|
|
9
|
+
import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types';
|
|
10
|
+
|
|
11
|
+
interface AccessToken {
|
|
12
|
+
/** The raw bearer token string. */
|
|
13
|
+
token: string;
|
|
14
|
+
/** The subject/client identifier from the token. */
|
|
15
|
+
clientId?: string;
|
|
16
|
+
/** Scopes granted to the token. */
|
|
17
|
+
scopes: string[];
|
|
18
|
+
/** Unix timestamp (seconds) when the token expires. */
|
|
19
|
+
expiresAt?: number;
|
|
20
|
+
/** All claims from the token payload. */
|
|
21
|
+
claims: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
interface TokenVerifier {
|
|
24
|
+
verify(token: string): Promise<AccessToken>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Thrown by authorization checks to produce a 403 response.
|
|
28
|
+
* Any other error thrown during verification produces a 401.
|
|
29
|
+
*/
|
|
30
|
+
declare class AuthorizationError extends Error {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type AuthCheck = (token: AccessToken) => void | Promise<void>;
|
|
35
|
+
declare function requireScopes(...scopes: string[]): AuthCheck;
|
|
36
|
+
|
|
37
|
+
interface PromptArgument {
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
/** When true, the client must supply this argument. Defaults to false. */
|
|
41
|
+
required?: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface PromptConfig {
|
|
44
|
+
/** Unique prompt identifier. Inferred from the handler function name when omitted. */
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Human-readable display name shown in UIs. */
|
|
47
|
+
title?: string;
|
|
48
|
+
/** Description shown to clients and LLMs. Inferred from name when omitted. */
|
|
49
|
+
description?: string;
|
|
50
|
+
/** Declared arguments. Advertised to clients in prompts/list. */
|
|
51
|
+
arguments?: PromptArgument[];
|
|
52
|
+
/** When true the prompt is hidden from list responses and cannot be invoked. */
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
/** Execution timeout in milliseconds. No timeout by default. */
|
|
55
|
+
timeout?: number;
|
|
56
|
+
/** Arbitrary tags for server-side filtering and transforms. */
|
|
57
|
+
tags?: string[];
|
|
58
|
+
auth?: AuthCheck;
|
|
59
|
+
}
|
|
60
|
+
type TextContent = {
|
|
61
|
+
type: 'text';
|
|
62
|
+
text: string;
|
|
63
|
+
};
|
|
64
|
+
type ImageContent = {
|
|
65
|
+
type: 'image';
|
|
66
|
+
data: string;
|
|
67
|
+
mimeType: string;
|
|
68
|
+
};
|
|
69
|
+
type AudioContent = {
|
|
70
|
+
type: 'audio';
|
|
71
|
+
data: string;
|
|
72
|
+
mimeType: string;
|
|
73
|
+
};
|
|
74
|
+
type ResourceLinkContent = {
|
|
75
|
+
type: 'resource_link';
|
|
76
|
+
uri: string;
|
|
77
|
+
name?: string;
|
|
78
|
+
description?: string;
|
|
79
|
+
mimeType?: string;
|
|
80
|
+
};
|
|
81
|
+
type EmbeddedResource = {
|
|
82
|
+
type: 'resource';
|
|
83
|
+
resource: {
|
|
84
|
+
uri: string;
|
|
85
|
+
mimeType?: string;
|
|
86
|
+
} & ({
|
|
87
|
+
text: string;
|
|
88
|
+
} | {
|
|
89
|
+
blob: string;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
type PromptContent = TextContent | ImageContent | AudioContent | EmbeddedResource | ResourceLinkContent;
|
|
93
|
+
interface PromptMessage {
|
|
94
|
+
role: 'user' | 'assistant';
|
|
95
|
+
content: PromptContent;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Escape hatch for full control over the prompt response.
|
|
99
|
+
* Return this from a prompt handler to set an explicit description and/or
|
|
100
|
+
* supply a custom multi-turn message sequence.
|
|
101
|
+
*/
|
|
102
|
+
declare class PromptResult {
|
|
103
|
+
readonly messages: PromptMessage[];
|
|
104
|
+
readonly description?: string | undefined;
|
|
105
|
+
constructor(messages: PromptMessage[], description?: string | undefined);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type LogLevel = 'debug' | 'info' | 'notice' | 'warning' | 'error' | 'critical' | 'alert' | 'emergency';
|
|
109
|
+
interface SamplingMessage {
|
|
110
|
+
role: 'user' | 'assistant';
|
|
111
|
+
content: {
|
|
112
|
+
type: 'text';
|
|
113
|
+
text: string;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'image';
|
|
116
|
+
data: string;
|
|
117
|
+
mimeType: string;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
interface SamplingParams {
|
|
121
|
+
messages: SamplingMessage[];
|
|
122
|
+
systemPrompt?: string;
|
|
123
|
+
/** Maximum tokens to generate. Defaults to 1024. */
|
|
124
|
+
maxTokens?: number;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
stopSequences?: string[];
|
|
127
|
+
modelPreferences?: {
|
|
128
|
+
hints?: Array<{
|
|
129
|
+
name?: string;
|
|
130
|
+
}>;
|
|
131
|
+
costPriority?: number;
|
|
132
|
+
speedPriority?: number;
|
|
133
|
+
intelligencePriority?: number;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
interface SamplingResult {
|
|
137
|
+
role: 'assistant';
|
|
138
|
+
content: {
|
|
139
|
+
type: 'text';
|
|
140
|
+
text: string;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'image';
|
|
143
|
+
data: string;
|
|
144
|
+
mimeType: string;
|
|
145
|
+
};
|
|
146
|
+
model: string;
|
|
147
|
+
stopReason?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Flat JSON Schema object describing fields to collect from the user.
|
|
151
|
+
* Only primitive property types (string, number, boolean) are allowed per the MCP spec.
|
|
152
|
+
*/
|
|
153
|
+
interface ElicitationSchema {
|
|
154
|
+
type: 'object';
|
|
155
|
+
properties: Record<string, {
|
|
156
|
+
type: 'string' | 'number' | 'boolean';
|
|
157
|
+
title?: string;
|
|
158
|
+
description?: string;
|
|
159
|
+
}>;
|
|
160
|
+
required?: string[];
|
|
161
|
+
}
|
|
162
|
+
interface ElicitationResult {
|
|
163
|
+
/** How the user responded to the elicitation. */
|
|
164
|
+
action: 'accept' | 'decline' | 'cancel';
|
|
165
|
+
/** Submitted form values. Present only when action is 'accept'. */
|
|
166
|
+
content?: Record<string, string | number | boolean>;
|
|
167
|
+
}
|
|
168
|
+
interface Root {
|
|
169
|
+
uri: string;
|
|
170
|
+
name?: string;
|
|
171
|
+
}
|
|
172
|
+
interface McpContext {
|
|
173
|
+
/** Auth token for the current request, if any. */
|
|
174
|
+
auth: AccessToken | undefined;
|
|
175
|
+
/** The MCP request ID for the current call. */
|
|
176
|
+
requestId: string | undefined;
|
|
177
|
+
/** Send a log message to the client at the specified RFC 5424 severity level. */
|
|
178
|
+
log(level: LogLevel, message: string, loggerName?: string): Promise<void>;
|
|
179
|
+
debug(message: string, loggerName?: string): Promise<void>;
|
|
180
|
+
info(message: string, loggerName?: string): Promise<void>;
|
|
181
|
+
notice(message: string, loggerName?: string): Promise<void>;
|
|
182
|
+
warning(message: string, loggerName?: string): Promise<void>;
|
|
183
|
+
error(message: string, loggerName?: string): Promise<void>;
|
|
184
|
+
critical(message: string, loggerName?: string): Promise<void>;
|
|
185
|
+
alert(message: string, loggerName?: string): Promise<void>;
|
|
186
|
+
emergency(message: string, loggerName?: string): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Send a progress notification to the client.
|
|
189
|
+
* No-op if the request did not include a `progressToken` in its `_meta`.
|
|
190
|
+
*/
|
|
191
|
+
reportProgress(progress: number, total?: number, message?: string): Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Ask the client to perform an LLM inference call and return the result.
|
|
194
|
+
* Throws if the client has not advertised the `sampling` capability.
|
|
195
|
+
*/
|
|
196
|
+
sample(params: SamplingParams): Promise<SamplingResult>;
|
|
197
|
+
/**
|
|
198
|
+
* Ask the client to collect input from the user via a form dialog.
|
|
199
|
+
* Throws if the client has not advertised the `elicitation` capability.
|
|
200
|
+
*/
|
|
201
|
+
elicit(message: string, schema: ElicitationSchema): Promise<ElicitationResult>;
|
|
202
|
+
/**
|
|
203
|
+
* Request the list of filesystem roots the client has declared.
|
|
204
|
+
* Throws if the client has not advertised the `roots` capability.
|
|
205
|
+
*/
|
|
206
|
+
listRoots(): Promise<Root[]>;
|
|
207
|
+
/** Retrieve a value from session-scoped state. Returns undefined if not set. */
|
|
208
|
+
getState(key: string): unknown;
|
|
209
|
+
/** Store a value in session-scoped state. Persists for the lifetime of the session. */
|
|
210
|
+
setState(key: string, value: unknown): void;
|
|
211
|
+
/** Remove a value from session-scoped state. */
|
|
212
|
+
deleteState(key: string): void;
|
|
213
|
+
/**
|
|
214
|
+
* Resolve a logical tool name to its current external name, accounting for
|
|
215
|
+
* any namespace prefix applied when the owning FastMCPApp was mounted.
|
|
216
|
+
* Returns the name unchanged when called outside a mounted context.
|
|
217
|
+
*/
|
|
218
|
+
resolveToolName(name: string): string;
|
|
219
|
+
/**
|
|
220
|
+
* Register a callback that runs when the current session closes.
|
|
221
|
+
* Useful for releasing per-session resources (e.g. uploaded files).
|
|
222
|
+
* No-op if called outside an active HTTP session.
|
|
223
|
+
*/
|
|
224
|
+
onClose(callback: () => void): void;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
interface MiddlewareContext<T = unknown> {
|
|
228
|
+
readonly method: string;
|
|
229
|
+
readonly request: T;
|
|
230
|
+
readonly mcpContext: McpContext;
|
|
231
|
+
}
|
|
232
|
+
type Next<R = unknown> = () => Promise<R>;
|
|
233
|
+
interface Middleware {
|
|
234
|
+
/** Called once per Server instance. Use to register notification handlers or other server-level setup. */
|
|
235
|
+
setup?(server: Server): void;
|
|
236
|
+
onRequest?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
237
|
+
onCallTool?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
238
|
+
onListTools?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
239
|
+
onReadResource?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
240
|
+
onListResources?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
241
|
+
onListResourceTemplates?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
242
|
+
onGetPrompt?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
243
|
+
onListPrompts?<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
244
|
+
}
|
|
245
|
+
/** Logs every request with method, outcome, and elapsed time. */
|
|
246
|
+
declare class LoggingMiddleware implements Middleware {
|
|
247
|
+
private readonly emit;
|
|
248
|
+
constructor(emit?: (msg: string) => void);
|
|
249
|
+
onRequest<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Custom cache key function. Receives the full middleware context so callers can
|
|
253
|
+
* incorporate auth identity or any other dimension into the key.
|
|
254
|
+
*
|
|
255
|
+
* **Required when using per-component auth checks.** The default key is
|
|
256
|
+
* `"method:JSON(params)"`, which contains no auth information. If auth-filtered
|
|
257
|
+
* list results (tools, resources, prompts) are cached with the default key, one
|
|
258
|
+
* session's filtered results can be served to a session with different permissions.
|
|
259
|
+
* Pass a `keyFn` that includes the caller identity, e.g.:
|
|
260
|
+
*
|
|
261
|
+
* ```ts
|
|
262
|
+
* new CachingMiddleware(60_000, (ctx) =>
|
|
263
|
+
* `${ctx.method}:${ctx.mcpContext.auth?.clientId ?? ''}:${JSON.stringify(ctx.request)}`
|
|
264
|
+
* )
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
type CacheKeyFn = (ctx: MiddlewareContext) => string;
|
|
268
|
+
/** TTL-based response cache keyed on method + serialised request params by default.
|
|
269
|
+
* Pass a custom `keyFn` when using per-component auth so cached results are
|
|
270
|
+
* partitioned by caller identity. */
|
|
271
|
+
declare class CachingMiddleware implements Middleware {
|
|
272
|
+
readonly ttl: number;
|
|
273
|
+
private readonly _keyFn?;
|
|
274
|
+
private readonly _cache;
|
|
275
|
+
constructor(ttl?: number, _keyFn?: CacheKeyFn | undefined);
|
|
276
|
+
onRequest<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
277
|
+
}
|
|
278
|
+
/** Fixed-window counter rate limiter. Resets to full capacity after every windowMs interval. */
|
|
279
|
+
declare class RateLimitingMiddleware implements Middleware {
|
|
280
|
+
private readonly limit;
|
|
281
|
+
private readonly windowMs;
|
|
282
|
+
private _tokens;
|
|
283
|
+
private _lastRefill;
|
|
284
|
+
constructor(limit: number, windowMs?: number);
|
|
285
|
+
onRequest<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
286
|
+
}
|
|
287
|
+
/** Rejects responses whose JSON serialisation exceeds maxBytes. */
|
|
288
|
+
declare class SizeLimitingMiddleware implements Middleware {
|
|
289
|
+
private readonly maxBytes;
|
|
290
|
+
constructor(maxBytes: number);
|
|
291
|
+
onRequest<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Normalises errors thrown by handlers to proper MCP shapes:
|
|
295
|
+
* - tools/call plain errors → { isError: true, content: [...] } (per MCP spec)
|
|
296
|
+
* - tools/call McpError → re-thrown as a protocol-level error
|
|
297
|
+
* - all other methods → McpError(InternalError, message)
|
|
298
|
+
*
|
|
299
|
+
* Re-throwing McpError from onCallTool ensures that middleware-level errors
|
|
300
|
+
* (e.g. from RateLimitingMiddleware or SizeLimitingMiddleware stacked before
|
|
301
|
+
* this middleware) always propagate as protocol errors and are never silently
|
|
302
|
+
* converted to isError:true tool responses.
|
|
303
|
+
*/
|
|
304
|
+
declare class ErrorNormalizationMiddleware implements Middleware {
|
|
305
|
+
onCallTool<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
306
|
+
onRequest<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Intercepts `notifications/cancelled` from the client and aborts the matching
|
|
310
|
+
* in-flight handler via Promise.race + AbortController.
|
|
311
|
+
*/
|
|
312
|
+
declare class CancellationMiddleware implements Middleware {
|
|
313
|
+
private readonly _inFlight;
|
|
314
|
+
setup(server: Server): void;
|
|
315
|
+
onRequest<T, R>(ctx: MiddlewareContext<T>, next: Next<R>): Promise<R>;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
interface ToolView {
|
|
319
|
+
readonly name: string;
|
|
320
|
+
/** Human-readable display name shown in UIs. Takes precedence over `name` for display purposes. */
|
|
321
|
+
readonly title?: string;
|
|
322
|
+
readonly description: string;
|
|
323
|
+
readonly tags: readonly string[];
|
|
324
|
+
}
|
|
325
|
+
interface ResourceView {
|
|
326
|
+
readonly uri: string;
|
|
327
|
+
readonly name: string;
|
|
328
|
+
readonly tags: readonly string[];
|
|
329
|
+
readonly mimeType?: string;
|
|
330
|
+
readonly title?: string;
|
|
331
|
+
}
|
|
332
|
+
interface PromptView {
|
|
333
|
+
readonly name: string;
|
|
334
|
+
readonly description: string;
|
|
335
|
+
readonly tags: readonly string[];
|
|
336
|
+
}
|
|
337
|
+
interface SynthesizedTool {
|
|
338
|
+
readonly name: string;
|
|
339
|
+
/** Human-readable display name shown in UIs. Takes precedence over `name` for display purposes. */
|
|
340
|
+
readonly title?: string;
|
|
341
|
+
readonly description: string;
|
|
342
|
+
readonly inputSchema?: Record<string, unknown>;
|
|
343
|
+
readonly auth?: AuthCheck;
|
|
344
|
+
readonly timeout?: number;
|
|
345
|
+
readonly handler: (args: any) => unknown;
|
|
346
|
+
}
|
|
347
|
+
interface Transform {
|
|
348
|
+
/**
|
|
349
|
+
* Transform a tool view before it appears in list responses.
|
|
350
|
+
* Return a modified view to rename/redescribe; return null to hide the tool
|
|
351
|
+
* from list responses (it remains callable by its original name).
|
|
352
|
+
*/
|
|
353
|
+
transformTool?(view: ToolView): ToolView | null;
|
|
354
|
+
/** Transform a static resource view. */
|
|
355
|
+
transformResource?(view: ResourceView): ResourceView | null;
|
|
356
|
+
/** Transform a URI-template resource view. */
|
|
357
|
+
transformResourceTemplate?(view: ResourceView): ResourceView | null;
|
|
358
|
+
/** Transform a prompt view. */
|
|
359
|
+
transformPrompt?(view: PromptView): PromptView | null;
|
|
360
|
+
/**
|
|
361
|
+
* Synthesize additional tools derived from the current resource and prompt lists.
|
|
362
|
+
* Called at request time so the snapshot is always fresh.
|
|
363
|
+
*/
|
|
364
|
+
synthesizeTools?(resources: ResourceView[], prompts: PromptView[]): SynthesizedTool[];
|
|
365
|
+
}
|
|
366
|
+
/** Rename a single tool. The original name still resolves at call time. */
|
|
367
|
+
declare function renameTool(originalName: string, newName: string): Transform;
|
|
368
|
+
/** Rewrite the description of a single tool. */
|
|
369
|
+
declare function redescribeTool(toolName: string, description: string): Transform;
|
|
370
|
+
/**
|
|
371
|
+
* Hide components whose predicate returns false.
|
|
372
|
+
* Hidden items are removed from list responses but remain callable by original name.
|
|
373
|
+
*/
|
|
374
|
+
declare class FilterTransform implements Transform {
|
|
375
|
+
private readonly predicates;
|
|
376
|
+
constructor(predicates: {
|
|
377
|
+
tools?: (v: ToolView) => boolean;
|
|
378
|
+
resources?: (v: ResourceView) => boolean;
|
|
379
|
+
/** When omitted, falls back to the `resources` predicate. */
|
|
380
|
+
resourceTemplates?: (v: ResourceView) => boolean;
|
|
381
|
+
prompts?: (v: PromptView) => boolean;
|
|
382
|
+
});
|
|
383
|
+
transformTool(v: ToolView): ToolView | null;
|
|
384
|
+
transformResource(v: ResourceView): ResourceView | null;
|
|
385
|
+
transformResourceTemplate(v: ResourceView): ResourceView | null;
|
|
386
|
+
transformPrompt(v: PromptView): PromptView | null;
|
|
387
|
+
}
|
|
388
|
+
/** Prefix all tool, prompt, and resource names with a string. URIs are left unchanged. */
|
|
389
|
+
declare class NamespaceTransform implements Transform {
|
|
390
|
+
private readonly prefix;
|
|
391
|
+
constructor(prefix: string);
|
|
392
|
+
transformTool(v: ToolView): ToolView;
|
|
393
|
+
transformResource(v: ResourceView): ResourceView;
|
|
394
|
+
transformResourceTemplate(v: ResourceView): ResourceView;
|
|
395
|
+
transformPrompt(v: PromptView): PromptView;
|
|
396
|
+
}
|
|
397
|
+
/** Expose registered resources as a `list_resources` tool. */
|
|
398
|
+
declare class ResourcesAsTools implements Transform {
|
|
399
|
+
synthesizeTools(resources: ResourceView[]): SynthesizedTool[];
|
|
400
|
+
}
|
|
401
|
+
/** Expose registered prompts as a `list_prompts` tool. */
|
|
402
|
+
declare class PromptsAsTools implements Transform {
|
|
403
|
+
synthesizeTools(_resources: ResourceView[], prompts: PromptView[]): SynthesizedTool[];
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Expose only components whose tags include the specified version string.
|
|
407
|
+
* Components with no tags are always excluded.
|
|
408
|
+
*/
|
|
409
|
+
declare class VersionFilter implements Transform {
|
|
410
|
+
private readonly version;
|
|
411
|
+
constructor(version: string);
|
|
412
|
+
private _matches;
|
|
413
|
+
transformTool(v: ToolView): ToolView | null;
|
|
414
|
+
transformResource(v: ResourceView): ResourceView | null;
|
|
415
|
+
transformResourceTemplate(v: ResourceView): ResourceView | null;
|
|
416
|
+
transformPrompt(v: PromptView): PromptView | null;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
type Visibility = 'model' | 'app';
|
|
420
|
+
interface CspPolicy {
|
|
421
|
+
connectDomains?: string[];
|
|
422
|
+
/** Covers img-src, script-src, style-src, font-src, media-src. */
|
|
423
|
+
resourceDomains?: string[];
|
|
424
|
+
frameDomains?: string[];
|
|
425
|
+
baseUriDomains?: string[];
|
|
426
|
+
}
|
|
427
|
+
interface UiToolMeta {
|
|
428
|
+
/** Explicit resource URI. Auto-derived from tool name when omitted. */
|
|
429
|
+
resourceUri?: string;
|
|
430
|
+
/** Who can see this tool. Defaults to ['model']. */
|
|
431
|
+
visibility?: Visibility[];
|
|
432
|
+
}
|
|
433
|
+
interface BrowserPermissions {
|
|
434
|
+
camera?: Record<string, never>;
|
|
435
|
+
microphone?: Record<string, never>;
|
|
436
|
+
geolocation?: Record<string, never>;
|
|
437
|
+
clipboardWrite?: Record<string, never>;
|
|
438
|
+
}
|
|
439
|
+
interface ResourceUiMeta {
|
|
440
|
+
csp?: CspPolicy;
|
|
441
|
+
permissions?: BrowserPermissions;
|
|
442
|
+
domain?: string;
|
|
443
|
+
prefersBorder?: boolean;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
interface ResourceAnnotations {
|
|
447
|
+
/** Intended audience(s) — 'user', 'assistant', or both. */
|
|
448
|
+
audience?: Array<'user' | 'assistant'>;
|
|
449
|
+
/** Importance hint from 0 (least) to 1 (most). */
|
|
450
|
+
priority?: number;
|
|
451
|
+
/** ISO 8601 timestamp of last modification. */
|
|
452
|
+
lastModified?: string;
|
|
453
|
+
}
|
|
454
|
+
interface ResourceConfig {
|
|
455
|
+
/** Static URI (e.g. `file://readme`) or RFC 6570 template (e.g. `user://{id}`). */
|
|
456
|
+
uri: string;
|
|
457
|
+
/** Programmatic identifier. Defaults to the uri. */
|
|
458
|
+
name?: string;
|
|
459
|
+
/** Human-readable display name shown in UIs. Defaults to `name`. */
|
|
460
|
+
title?: string;
|
|
461
|
+
description?: string;
|
|
462
|
+
/** MIME type of the resource content. Defaults to 'text/plain' for strings, 'application/octet-stream' for binary. */
|
|
463
|
+
mimeType?: string;
|
|
464
|
+
/**
|
|
465
|
+
* Size of the resource content in bytes, if known.
|
|
466
|
+
* Only meaningful for static resources; ignored for URI templates.
|
|
467
|
+
*/
|
|
468
|
+
size?: number;
|
|
469
|
+
/** Behavioral hints for clients. */
|
|
470
|
+
annotations?: ResourceAnnotations;
|
|
471
|
+
/** Execution timeout in milliseconds. No timeout by default. */
|
|
472
|
+
timeout?: number;
|
|
473
|
+
/** When true the resource is hidden from list responses and cannot be read. */
|
|
474
|
+
disabled?: boolean;
|
|
475
|
+
/** Arbitrary tags for server-side filtering. */
|
|
476
|
+
tags?: string[];
|
|
477
|
+
auth?: AuthCheck;
|
|
478
|
+
/** Apps extension metadata. Included in _meta.ui in resources/list for UI-capable clients. */
|
|
479
|
+
ui?: ResourceUiMeta;
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Escape hatch for full control over resource response content.
|
|
483
|
+
* Return this from a resource handler to specify content directly.
|
|
484
|
+
*/
|
|
485
|
+
declare class ResourceResult {
|
|
486
|
+
readonly contents: Array<{
|
|
487
|
+
uri: string;
|
|
488
|
+
mimeType?: string;
|
|
489
|
+
text?: string;
|
|
490
|
+
blob?: string;
|
|
491
|
+
}>;
|
|
492
|
+
constructor(contents: Array<{
|
|
493
|
+
uri: string;
|
|
494
|
+
mimeType?: string;
|
|
495
|
+
text?: string;
|
|
496
|
+
blob?: string;
|
|
497
|
+
}>);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
interface OAuthConfig {
|
|
501
|
+
/** OAuth server provider implementing the authorization and token flow. */
|
|
502
|
+
provider: OAuthServerProvider;
|
|
503
|
+
/**
|
|
504
|
+
* Issuer URL for the OAuth server (used in metadata endpoints).
|
|
505
|
+
* Defaults to the HTTP server's bound address when not specified.
|
|
506
|
+
*/
|
|
507
|
+
issuerUrl?: URL;
|
|
508
|
+
/** Scopes supported by this server, advertised in OAuth metadata. */
|
|
509
|
+
scopes?: string[];
|
|
510
|
+
}
|
|
511
|
+
interface FastMCPOptions {
|
|
512
|
+
name: string;
|
|
513
|
+
version?: string;
|
|
514
|
+
/** Simple bearer-token verifier for non-OAuth auth scenarios. */
|
|
515
|
+
auth?: TokenVerifier;
|
|
516
|
+
/** Full OAuth 2.1 server with Dynamic Client Registration support. */
|
|
517
|
+
oauth?: OAuthConfig;
|
|
518
|
+
/** Maximum number of tools returned per listTools page. Default: 50. */
|
|
519
|
+
toolsPageSize?: number;
|
|
520
|
+
/** Maximum number of resources (or templates) returned per page. Default: 50. */
|
|
521
|
+
resourcesPageSize?: number;
|
|
522
|
+
/** Maximum number of prompts returned per prompts/list page. Default: 50. */
|
|
523
|
+
promptsPageSize?: number;
|
|
524
|
+
/** Middleware applied to every request in registration order. */
|
|
525
|
+
middleware?: Middleware[];
|
|
526
|
+
/** Transforms applied to component list responses in registration order. */
|
|
527
|
+
transforms?: Transform[];
|
|
528
|
+
}
|
|
529
|
+
interface RunOptions {
|
|
530
|
+
transport?: 'stdio' | 'http';
|
|
531
|
+
port?: number;
|
|
532
|
+
host?: string;
|
|
533
|
+
path?: string;
|
|
534
|
+
/** Custom stdin stream for the stdio transport. Defaults to process.stdin. */
|
|
535
|
+
stdin?: Readable;
|
|
536
|
+
/** Custom stdout stream for the stdio transport. Defaults to process.stdout. */
|
|
537
|
+
stdout?: Writable;
|
|
538
|
+
}
|
|
539
|
+
interface ServerAddress {
|
|
540
|
+
host: string;
|
|
541
|
+
port: number;
|
|
542
|
+
path: string;
|
|
543
|
+
}
|
|
544
|
+
interface ToolConfig {
|
|
545
|
+
name: string;
|
|
546
|
+
/** Human-readable display name shown in UIs. Takes precedence over `name` for display purposes. */
|
|
547
|
+
title?: string;
|
|
548
|
+
description: string;
|
|
549
|
+
/** Standard Schema validator for the tool's input arguments. Used for runtime validation. */
|
|
550
|
+
input?: StandardSchemaV1;
|
|
551
|
+
/**
|
|
552
|
+
* Explicit JSON Schema advertised to clients as `inputSchema`. Overrides auto-generation from
|
|
553
|
+
* `input`. Use when you need JSON Schema features beyond what your validator auto-generates
|
|
554
|
+
* (e.g. `examples`, `$comment`, per-property descriptions, or custom annotations).
|
|
555
|
+
*/
|
|
556
|
+
inputSchema?: Record<string, unknown>;
|
|
557
|
+
/** Standard Schema validator for the tool's return value. Validated before result conversion. */
|
|
558
|
+
output?: StandardSchemaV1;
|
|
559
|
+
/**
|
|
560
|
+
* Explicit JSON Schema advertised to clients as `outputSchema`. Overrides auto-generation from
|
|
561
|
+
* `output`. Use when you need JSON Schema features beyond what your validator auto-generates.
|
|
562
|
+
*/
|
|
563
|
+
outputSchema?: Record<string, unknown>;
|
|
564
|
+
/** Execution timeout in milliseconds. No timeout by default. */
|
|
565
|
+
timeout?: number;
|
|
566
|
+
/** When true the tool is hidden from listTools and cannot be invoked via tools/call. */
|
|
567
|
+
disabled?: boolean;
|
|
568
|
+
/** Arbitrary tags for server-side filtering. */
|
|
569
|
+
tags?: string[];
|
|
570
|
+
auth?: AuthCheck;
|
|
571
|
+
/** Apps extension — links this tool to a UI resource and controls visibility. */
|
|
572
|
+
ui?: UiToolMeta;
|
|
573
|
+
}
|
|
574
|
+
declare class FastMCP {
|
|
575
|
+
readonly name: string;
|
|
576
|
+
readonly version: string;
|
|
577
|
+
private _auth;
|
|
578
|
+
private _oauth;
|
|
579
|
+
private _toolsPageSize;
|
|
580
|
+
private _resourcesPageSize;
|
|
581
|
+
private _tools;
|
|
582
|
+
private _staticResources;
|
|
583
|
+
private _templateResources;
|
|
584
|
+
private _prompts;
|
|
585
|
+
private _promptsPageSize;
|
|
586
|
+
private _middleware;
|
|
587
|
+
private _transforms;
|
|
588
|
+
private _primaryState;
|
|
589
|
+
private _httpServer;
|
|
590
|
+
private _address;
|
|
591
|
+
private _sessions;
|
|
592
|
+
private _primaryServer;
|
|
593
|
+
private _toolRegisteredCallbacks;
|
|
594
|
+
private _resourceRegisteredCallbacks;
|
|
595
|
+
private _promptRegisteredCallbacks;
|
|
596
|
+
private _proxyCloseCallbacks;
|
|
597
|
+
private _mountedChildren;
|
|
598
|
+
constructor(options: FastMCPOptions);
|
|
599
|
+
private _hasUiComponents;
|
|
600
|
+
/** Create a new Server instance with all request handlers wired up. */
|
|
601
|
+
private _makeServer;
|
|
602
|
+
private _resolveToken;
|
|
603
|
+
private _setupHandlers;
|
|
604
|
+
private _notifyToolListChanged;
|
|
605
|
+
private _notifyResourceListChanged;
|
|
606
|
+
private _notifyPromptListChanged;
|
|
607
|
+
tool<S extends StandardSchemaV1>(config: Omit<ToolConfig, 'input'> & {
|
|
608
|
+
input: S;
|
|
609
|
+
}, handler: (args: StandardSchemaV1.InferOutput<S>) => unknown): void;
|
|
610
|
+
tool(config: ToolConfig, handler: (args: Record<string, unknown>) => unknown): void;
|
|
611
|
+
prompt(config: PromptConfig, handler: (args?: Record<string, string>) => unknown): void;
|
|
612
|
+
resource(config: ResourceConfig, handler: (params?: Record<string, string>) => unknown): void;
|
|
613
|
+
_removeTool(name: string): boolean;
|
|
614
|
+
_removeResource(uri: string): boolean;
|
|
615
|
+
_removePrompt(name: string): boolean;
|
|
616
|
+
/** Add a transform to the pipeline. Applied to list responses in registration order. */
|
|
617
|
+
transform(t: Transform): this;
|
|
618
|
+
/**
|
|
619
|
+
* Dispatch a tool call through this server's middleware chain using an inherited context.
|
|
620
|
+
* Used by parent servers to honour child-level middleware when routing mounted tool calls.
|
|
621
|
+
*/
|
|
622
|
+
_dispatchTool(name: string, rawArgs: unknown, ctx: McpContext): Promise<{
|
|
623
|
+
[x: string]: unknown;
|
|
624
|
+
content: ({
|
|
625
|
+
type: "text";
|
|
626
|
+
text: string;
|
|
627
|
+
annotations?: {
|
|
628
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
629
|
+
priority?: number | undefined;
|
|
630
|
+
lastModified?: string | undefined;
|
|
631
|
+
} | undefined;
|
|
632
|
+
_meta?: {
|
|
633
|
+
[x: string]: unknown;
|
|
634
|
+
} | undefined;
|
|
635
|
+
} | {
|
|
636
|
+
type: "image";
|
|
637
|
+
data: string;
|
|
638
|
+
mimeType: string;
|
|
639
|
+
annotations?: {
|
|
640
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
641
|
+
priority?: number | undefined;
|
|
642
|
+
lastModified?: string | undefined;
|
|
643
|
+
} | undefined;
|
|
644
|
+
_meta?: {
|
|
645
|
+
[x: string]: unknown;
|
|
646
|
+
} | undefined;
|
|
647
|
+
} | {
|
|
648
|
+
type: "audio";
|
|
649
|
+
data: string;
|
|
650
|
+
mimeType: string;
|
|
651
|
+
annotations?: {
|
|
652
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
653
|
+
priority?: number | undefined;
|
|
654
|
+
lastModified?: string | undefined;
|
|
655
|
+
} | undefined;
|
|
656
|
+
_meta?: {
|
|
657
|
+
[x: string]: unknown;
|
|
658
|
+
} | undefined;
|
|
659
|
+
} | {
|
|
660
|
+
uri: string;
|
|
661
|
+
name: string;
|
|
662
|
+
type: "resource_link";
|
|
663
|
+
description?: string | undefined;
|
|
664
|
+
mimeType?: string | undefined;
|
|
665
|
+
size?: number | undefined;
|
|
666
|
+
annotations?: {
|
|
667
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
668
|
+
priority?: number | undefined;
|
|
669
|
+
lastModified?: string | undefined;
|
|
670
|
+
} | undefined;
|
|
671
|
+
_meta?: {
|
|
672
|
+
[x: string]: unknown;
|
|
673
|
+
} | undefined;
|
|
674
|
+
icons?: {
|
|
675
|
+
src: string;
|
|
676
|
+
mimeType?: string | undefined;
|
|
677
|
+
sizes?: string[] | undefined;
|
|
678
|
+
theme?: "light" | "dark" | undefined;
|
|
679
|
+
}[] | undefined;
|
|
680
|
+
title?: string | undefined;
|
|
681
|
+
} | {
|
|
682
|
+
type: "resource";
|
|
683
|
+
resource: {
|
|
684
|
+
uri: string;
|
|
685
|
+
text: string;
|
|
686
|
+
mimeType?: string | undefined;
|
|
687
|
+
_meta?: {
|
|
688
|
+
[x: string]: unknown;
|
|
689
|
+
} | undefined;
|
|
690
|
+
} | {
|
|
691
|
+
uri: string;
|
|
692
|
+
blob: string;
|
|
693
|
+
mimeType?: string | undefined;
|
|
694
|
+
_meta?: {
|
|
695
|
+
[x: string]: unknown;
|
|
696
|
+
} | undefined;
|
|
697
|
+
};
|
|
698
|
+
annotations?: {
|
|
699
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
700
|
+
priority?: number | undefined;
|
|
701
|
+
lastModified?: string | undefined;
|
|
702
|
+
} | undefined;
|
|
703
|
+
_meta?: {
|
|
704
|
+
[x: string]: unknown;
|
|
705
|
+
} | undefined;
|
|
706
|
+
})[];
|
|
707
|
+
_meta?: {
|
|
708
|
+
[x: string]: unknown;
|
|
709
|
+
progressToken?: string | number | undefined;
|
|
710
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
711
|
+
taskId: string;
|
|
712
|
+
} | undefined;
|
|
713
|
+
} | undefined;
|
|
714
|
+
structuredContent?: {
|
|
715
|
+
[x: string]: unknown;
|
|
716
|
+
} | undefined;
|
|
717
|
+
isError?: boolean | undefined;
|
|
718
|
+
}>;
|
|
719
|
+
/**
|
|
720
|
+
* Run a resource read through this server's middleware chain using an inherited context.
|
|
721
|
+
* Returns the raw handler result so the parent can apply convertResourceResult with the
|
|
722
|
+
* actual requested URI (important for template resources).
|
|
723
|
+
*/
|
|
724
|
+
_dispatchResource(uri: string, params: Record<string, string> | undefined, ctx: McpContext): Promise<unknown>;
|
|
725
|
+
/**
|
|
726
|
+
* Dispatch a prompt render through this server's middleware chain using an inherited context.
|
|
727
|
+
*/
|
|
728
|
+
_dispatchPrompt(name: string, args: Record<string, string>, ctx: McpContext): Promise<{
|
|
729
|
+
description?: string;
|
|
730
|
+
messages: PromptMessage[];
|
|
731
|
+
}>;
|
|
732
|
+
private _mirrorTool;
|
|
733
|
+
private _mirrorResource;
|
|
734
|
+
private _mirrorPrompt;
|
|
735
|
+
/** Mount a child server onto this server. All tools, resources, and prompts from the child become accessible via this server. Pass a prefix to namespace names and prevent collisions. */
|
|
736
|
+
mount(child: FastMCP, prefix?: string): this;
|
|
737
|
+
/** Register a callback invoked when this server is closed — used by proxy connections. */
|
|
738
|
+
_addCloseCallback(cb: () => Promise<void>): void;
|
|
739
|
+
/**
|
|
740
|
+
* Register a provider (FastMCPApp or FastMCP) on this server.
|
|
741
|
+
* All tools, resources, and prompts from the provider are mounted without a prefix.
|
|
742
|
+
* For FastMCPApp, pass provider.server; for FastMCP, pass directly.
|
|
743
|
+
*/
|
|
744
|
+
addProvider(provider: FastMCP | {
|
|
745
|
+
server: FastMCP;
|
|
746
|
+
}): this;
|
|
747
|
+
private _applyTransformsToTools;
|
|
748
|
+
private _applyTransformsToResources;
|
|
749
|
+
private _applyTransformsToResourceTemplates;
|
|
750
|
+
private _applyTransformsToPrompts;
|
|
751
|
+
private _buildSynthesizedTools;
|
|
752
|
+
private _getVisibleViews;
|
|
753
|
+
/**
|
|
754
|
+
* Add a middleware to the pipeline.
|
|
755
|
+
*
|
|
756
|
+
* Can be called at any point before the first request arrives. `setup()` is
|
|
757
|
+
* called immediately on the primary server so that notification handlers and
|
|
758
|
+
* other server-level side-effects are active before `connect()` / `run()` is
|
|
759
|
+
* called. HTTP sessions created after `use()` will also have `setup()` called
|
|
760
|
+
* via `_makeServer()`.
|
|
761
|
+
*/
|
|
762
|
+
use(mw: Middleware): this;
|
|
763
|
+
getContext(): McpContext;
|
|
764
|
+
/** The bound address after run() resolves for the http transport. Null for stdio or before run(). */
|
|
765
|
+
get address(): ServerAddress | null;
|
|
766
|
+
connect(transport: Transport): Promise<void>;
|
|
767
|
+
run(options?: RunOptions): Promise<void>;
|
|
768
|
+
private _runHttpOAuth;
|
|
769
|
+
private _runHttpSimple;
|
|
770
|
+
close(): Promise<void>;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
declare class Image {
|
|
774
|
+
readonly buffer: Buffer | Uint8Array;
|
|
775
|
+
readonly mimeType: string;
|
|
776
|
+
constructor(buffer: Buffer | Uint8Array, mimeType: string);
|
|
777
|
+
}
|
|
778
|
+
declare class File {
|
|
779
|
+
readonly buffer: Buffer | Uint8Array;
|
|
780
|
+
readonly name: string;
|
|
781
|
+
readonly mimeType: string;
|
|
782
|
+
constructor(buffer: Buffer | Uint8Array, name: string, mimeType: string);
|
|
783
|
+
}
|
|
784
|
+
declare class ToolResult {
|
|
785
|
+
readonly result: CallToolResult;
|
|
786
|
+
constructor(result: CallToolResult);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
declare function multiAuth(...verifiers: TokenVerifier[]): TokenVerifier;
|
|
790
|
+
|
|
791
|
+
interface JwtVerifierOptions {
|
|
792
|
+
jwksUri: string;
|
|
793
|
+
issuer?: string;
|
|
794
|
+
audience?: string | string[];
|
|
795
|
+
/** Clock skew tolerance in seconds. Default: 0. */
|
|
796
|
+
leeway?: number;
|
|
797
|
+
}
|
|
798
|
+
declare function jwtVerifier(options: JwtVerifierOptions): TokenVerifier;
|
|
799
|
+
|
|
800
|
+
interface IntrospectionVerifierOptions {
|
|
801
|
+
endpoint: string;
|
|
802
|
+
credentials: {
|
|
803
|
+
clientId: string;
|
|
804
|
+
clientSecret: string;
|
|
805
|
+
};
|
|
806
|
+
/** Cache TTL in seconds. Omit or set to 0 to disable caching. */
|
|
807
|
+
cacheTtl?: number;
|
|
808
|
+
}
|
|
809
|
+
declare function introspectionVerifier(options: IntrospectionVerifierOptions): TokenVerifier;
|
|
810
|
+
|
|
811
|
+
declare function staticTokenVerifier(map: Record<string, Partial<Omit<AccessToken, 'token'>>>): TokenVerifier;
|
|
812
|
+
declare function debugTokenVerifier(): TokenVerifier;
|
|
813
|
+
|
|
814
|
+
interface OAuthProviderOptions {
|
|
815
|
+
/**
|
|
816
|
+
* Called during the authorization step. Implementations must eventually redirect
|
|
817
|
+
* to `params.redirectUri` with a `code` query parameter (and `state` if present).
|
|
818
|
+
*
|
|
819
|
+
* If omitted, all authorization requests are auto-approved immediately — suitable
|
|
820
|
+
* for testing and development only.
|
|
821
|
+
*/
|
|
822
|
+
onAuthorize?: (client: OAuthClientInformationFull, params: AuthorizationParams, res: Response) => Promise<void>;
|
|
823
|
+
/** Scopes supported by this server, advertised in OAuth metadata. */
|
|
824
|
+
scopes?: string[];
|
|
825
|
+
/** Access token lifetime in seconds. Default: 3600. */
|
|
826
|
+
tokenTtl?: number;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* Creates an in-memory OAuth 2.1 server provider with Dynamic Client Registration support.
|
|
830
|
+
*
|
|
831
|
+
* Suitable for development, testing, and simple deployments where persistence is not required.
|
|
832
|
+
* All state (clients, codes, tokens) is held in memory and lost on restart.
|
|
833
|
+
*/
|
|
834
|
+
declare function oauthProvider(options?: OAuthProviderOptions): OAuthServerProvider;
|
|
835
|
+
|
|
836
|
+
interface OAuthProxyOptions {
|
|
837
|
+
/** Pre-registered credentials this proxy uses when talking to the upstream server. */
|
|
838
|
+
upstreamCredentials: {
|
|
839
|
+
clientId: string;
|
|
840
|
+
clientSecret?: string;
|
|
841
|
+
};
|
|
842
|
+
/** Upstream OAuth server endpoint URLs. */
|
|
843
|
+
endpoints: {
|
|
844
|
+
authorizationUrl: string;
|
|
845
|
+
tokenUrl: string;
|
|
846
|
+
revocationUrl?: string;
|
|
847
|
+
};
|
|
848
|
+
/**
|
|
849
|
+
* Verifies an access token issued by the upstream and returns information about it.
|
|
850
|
+
* Called for every MCP request to validate the bearer token.
|
|
851
|
+
*/
|
|
852
|
+
verifyAccessToken: (token: string) => Promise<AuthInfo>;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Creates an OAuth provider that proxies to an existing upstream OAuth server using
|
|
856
|
+
* pre-registered credentials.
|
|
857
|
+
*
|
|
858
|
+
* MCP clients interact with this proxy using Dynamic Client Registration. The proxy
|
|
859
|
+
* presents a DCR-compliant interface while internally using its own fixed credentials
|
|
860
|
+
* (`upstreamCredentials`) when communicating with the upstream authorization server.
|
|
861
|
+
*/
|
|
862
|
+
declare function oauthProxy(options: OAuthProxyOptions): OAuthServerProvider;
|
|
863
|
+
|
|
864
|
+
type StdioTransport = {
|
|
865
|
+
type: 'stdio';
|
|
866
|
+
command: string;
|
|
867
|
+
args?: string[];
|
|
868
|
+
env?: Record<string, string>;
|
|
869
|
+
cwd?: string;
|
|
870
|
+
/** How long (ms) before the proxy re-fetches component lists. Default 30 000. Set 0 for notifications-only. */
|
|
871
|
+
cacheTtl?: number;
|
|
872
|
+
};
|
|
873
|
+
type HttpTransport = {
|
|
874
|
+
type: 'http';
|
|
875
|
+
url: string;
|
|
876
|
+
requestInit?: RequestInit;
|
|
877
|
+
/** How long (ms) before the proxy re-fetches component lists. Default 30 000. Set 0 for notifications-only. */
|
|
878
|
+
cacheTtl?: number;
|
|
879
|
+
};
|
|
880
|
+
type ProxyTransport = StdioTransport | HttpTransport;
|
|
881
|
+
/**
|
|
882
|
+
* Create a FastMCP instance that proxies all requests to a remote MCP server.
|
|
883
|
+
* The returned instance can be mounted onto a parent server via `parent.mount(proxy)`.
|
|
884
|
+
*
|
|
885
|
+
* Component lists (tools, resources, prompts) are kept in sync via:
|
|
886
|
+
* - Change notifications from the backend (immediate resync)
|
|
887
|
+
* - TTL-based lazy resync on each list request (configurable via `cacheTtl`, default 30 s)
|
|
888
|
+
*/
|
|
889
|
+
declare function createProxy(config: ProxyTransport, name?: string): Promise<FastMCP>;
|
|
890
|
+
|
|
891
|
+
interface Component {
|
|
892
|
+
type: string;
|
|
893
|
+
props?: Record<string, unknown>;
|
|
894
|
+
children?: Component[];
|
|
895
|
+
}
|
|
896
|
+
interface IfNode extends Component {
|
|
897
|
+
type: 'if';
|
|
898
|
+
branches: Array<{
|
|
899
|
+
condition: string;
|
|
900
|
+
node: Component;
|
|
901
|
+
}>;
|
|
902
|
+
fallback?: Component;
|
|
903
|
+
elif(condition: string, node: Component): IfNode;
|
|
904
|
+
else(node: Component): Component;
|
|
905
|
+
}
|
|
906
|
+
interface CatalogEntry {
|
|
907
|
+
type: string;
|
|
908
|
+
description: string;
|
|
909
|
+
}
|
|
910
|
+
declare function Column(props?: Record<string, unknown>, children?: Component[]): Component;
|
|
911
|
+
declare function Row(props?: Record<string, unknown>, children?: Component[]): Component;
|
|
912
|
+
declare function Grid(props?: Record<string, unknown>, children?: Component[]): Component;
|
|
913
|
+
declare function Text(content: string | Component, extraProps?: Record<string, unknown>): Component;
|
|
914
|
+
declare function Badge(text: string, extraProps?: Record<string, unknown>): Component;
|
|
915
|
+
declare function Table(props: {
|
|
916
|
+
columns: string[];
|
|
917
|
+
rows: string[][];
|
|
918
|
+
[key: string]: unknown;
|
|
919
|
+
}): Component;
|
|
920
|
+
declare function Bar(props: Record<string, unknown>): Component;
|
|
921
|
+
declare function Line(props: Record<string, unknown>): Component;
|
|
922
|
+
declare function Area(props: Record<string, unknown>): Component;
|
|
923
|
+
declare function Pie(props: Record<string, unknown>): Component;
|
|
924
|
+
declare function Input(props: Record<string, unknown>): Component;
|
|
925
|
+
declare function Select(props: Record<string, unknown>): Component;
|
|
926
|
+
declare function Button(props: Record<string, unknown>): Component;
|
|
927
|
+
declare function If(condition: string, then: Component, fallback?: Component): IfNode;
|
|
928
|
+
declare function ForEach(items: string, template: Component): Component;
|
|
929
|
+
declare function Rx(expression: string): Component;
|
|
930
|
+
|
|
931
|
+
interface EntrypointConfig {
|
|
932
|
+
name: string;
|
|
933
|
+
description: string;
|
|
934
|
+
title?: string;
|
|
935
|
+
}
|
|
936
|
+
interface BackendToolConfig {
|
|
937
|
+
name: string;
|
|
938
|
+
description: string;
|
|
939
|
+
title?: string;
|
|
940
|
+
/** Defaults to ['app']. Pass ['model', 'app'] to also expose to the LLM. */
|
|
941
|
+
visibility?: Visibility[];
|
|
942
|
+
}
|
|
943
|
+
interface FastMCPAppOptions {
|
|
944
|
+
name: string;
|
|
945
|
+
version?: string;
|
|
946
|
+
}
|
|
947
|
+
declare class FastMCPApp {
|
|
948
|
+
readonly server: FastMCP;
|
|
949
|
+
constructor(options: FastMCPAppOptions);
|
|
950
|
+
/**
|
|
951
|
+
* Register an entry-point tool.
|
|
952
|
+
* Entry-points are visible to the LLM (visibility: ['model', 'app']) and
|
|
953
|
+
* automatically linked to a generated ui:// resource URI.
|
|
954
|
+
*/
|
|
955
|
+
entrypoint(config: EntrypointConfig, handler: (args?: any) => Component): void;
|
|
956
|
+
/**
|
|
957
|
+
* Register a backend tool.
|
|
958
|
+
* Backend tools are hidden from listTools by default (visibility: ['app']).
|
|
959
|
+
*/
|
|
960
|
+
backendTool(config: BackendToolConfig, handler: (args: any) => unknown): void;
|
|
961
|
+
/**
|
|
962
|
+
* Returns a reference to a tool that resolves to the correct external name
|
|
963
|
+
* (including any mount prefix) when evaluated inside a request handler.
|
|
964
|
+
* Call inside a handler function — not at definition time.
|
|
965
|
+
*/
|
|
966
|
+
toolRef(name: string): string;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Resolve a logical tool name to its current external name inside a request
|
|
971
|
+
* handler, accounting for any mount prefix applied by a parent server.
|
|
972
|
+
*
|
|
973
|
+
* Use this in providers that are built on bare FastMCP (not FastMCPApp) to
|
|
974
|
+
* produce mount-prefix–aware action strings for Button components.
|
|
975
|
+
*/
|
|
976
|
+
declare function actionRef(name: string): string;
|
|
977
|
+
|
|
978
|
+
declare class GenerativeUI {
|
|
979
|
+
readonly server: FastMCP;
|
|
980
|
+
constructor();
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
declare class Approval {
|
|
984
|
+
readonly server: FastMCP;
|
|
985
|
+
constructor();
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
declare class Choice {
|
|
989
|
+
readonly server: FastMCP;
|
|
990
|
+
constructor();
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
interface FileHandle {
|
|
994
|
+
handle: string;
|
|
995
|
+
name: string;
|
|
996
|
+
mimeType: string;
|
|
997
|
+
data: Buffer;
|
|
998
|
+
}
|
|
999
|
+
interface FileStorageAdapter {
|
|
1000
|
+
save(handle: string, file: FileHandle): void;
|
|
1001
|
+
load(handle: string): FileHandle | undefined;
|
|
1002
|
+
delete(handle: string): void;
|
|
1003
|
+
}
|
|
1004
|
+
interface FileUploadOptions {
|
|
1005
|
+
storage?: FileStorageAdapter;
|
|
1006
|
+
}
|
|
1007
|
+
declare class FileUpload {
|
|
1008
|
+
readonly server: FastMCP;
|
|
1009
|
+
private readonly _storage;
|
|
1010
|
+
constructor(options?: FileUploadOptions);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
interface FormInputOptions {
|
|
1014
|
+
name: string;
|
|
1015
|
+
description: string;
|
|
1016
|
+
schema: StandardSchemaV1;
|
|
1017
|
+
}
|
|
1018
|
+
declare class FormInput {
|
|
1019
|
+
readonly server: FastMCP;
|
|
1020
|
+
constructor(options: FormInputOptions);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
export { type AccessToken, Approval, Area, type AuthCheck, AuthorizationError, type BackendToolConfig, Badge, Bar, type BrowserPermissions, Button, type CacheKeyFn, CachingMiddleware, CancellationMiddleware, type CatalogEntry, Choice, Column, type Component, type CspPolicy, type ElicitationResult, type ElicitationSchema, type EntrypointConfig, ErrorNormalizationMiddleware, FastMCP, FastMCPApp, type FastMCPAppOptions, type FastMCPOptions, File, type FileHandle, type FileStorageAdapter, FileUpload, type FileUploadOptions, FilterTransform, ForEach, FormInput, type FormInputOptions, GenerativeUI, Grid, If, type IfNode, Image, Input, Line, type LogLevel, LoggingMiddleware, type McpContext, type Middleware, type MiddlewareContext, NamespaceTransform, type Next, type OAuthConfig, type OAuthProviderOptions, type OAuthProxyOptions, Pie, type PromptArgument, type PromptConfig, type PromptContent, type PromptMessage, PromptResult, type PromptView, PromptsAsTools, type ProxyTransport, RateLimitingMiddleware, type ResourceAnnotations, type ResourceConfig, ResourceResult, type ResourceUiMeta, type ResourceView, ResourcesAsTools, type Root, Row, type RunOptions, Rx, type SamplingMessage, type SamplingParams, type SamplingResult, Select, type ServerAddress, SizeLimitingMiddleware, type SynthesizedTool, Table, Text, type TokenVerifier, type ToolConfig, ToolResult, type ToolView, type Transform, type UiToolMeta, VersionFilter, type Visibility, actionRef, createProxy, debugTokenVerifier, introspectionVerifier, jwtVerifier, multiAuth, oauthProvider, oauthProxy, redescribeTool, renameTool, requireScopes, staticTokenVerifier };
|