fastmcp 1.9.0 → 1.11.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 +60 -0
- package/dist/FastMCP.d.ts +33 -6
- package/dist/FastMCP.js +111 -12
- package/dist/FastMCP.js.map +1 -1
- package/jsr.json +1 -1
- package/package.json +3 -2
- package/src/FastMCP.test.ts +236 -115
- package/src/FastMCP.ts +171 -18
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ A TypeScript framework for building [MCP](https://modelcontextprotocol.io/) serv
|
|
|
15
15
|
- [SSE](#sse)
|
|
16
16
|
- [Progress notifications](#progress)
|
|
17
17
|
- [Typed server events](#typed-server-events)
|
|
18
|
+
- [Prompt argument auto-completion](#prompt-argument-auto-completion)
|
|
19
|
+
- Automated SSE pings
|
|
18
20
|
- Roots
|
|
19
21
|
- CLI for [testing](#test-with-mcp-cli) and [debugging](#inspect-with-mcp-inspector)
|
|
20
22
|
|
|
@@ -392,6 +394,60 @@ server.addPrompt({
|
|
|
392
394
|
});
|
|
393
395
|
```
|
|
394
396
|
|
|
397
|
+
#### Prompt argument auto-completion
|
|
398
|
+
|
|
399
|
+
Prompts can provide auto-completion for their arguments:
|
|
400
|
+
|
|
401
|
+
```js
|
|
402
|
+
server.addPrompt({
|
|
403
|
+
name: "countryPoem",
|
|
404
|
+
description: "Writes a poem about a country",
|
|
405
|
+
load: async ({ name }) => {
|
|
406
|
+
return `Hello, ${name}!`;
|
|
407
|
+
},
|
|
408
|
+
arguments: [
|
|
409
|
+
{
|
|
410
|
+
name: "name",
|
|
411
|
+
description: "Name of the country",
|
|
412
|
+
required: true,
|
|
413
|
+
complete: async (value) => {
|
|
414
|
+
if (value === "Germ") {
|
|
415
|
+
return {
|
|
416
|
+
values: ["Germany"],
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return {
|
|
421
|
+
values: [],
|
|
422
|
+
};
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
],
|
|
426
|
+
});
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
#### Automatic prompt argument completion
|
|
430
|
+
|
|
431
|
+
If you provide an `enum` array for an argument, the server will automatically provide completions for the argument.
|
|
432
|
+
|
|
433
|
+
```js
|
|
434
|
+
server.addPrompt({
|
|
435
|
+
name: "countryPoem",
|
|
436
|
+
description: "Writes a poem about a country",
|
|
437
|
+
load: async ({ name }) => {
|
|
438
|
+
return `Hello, ${name}!`;
|
|
439
|
+
},
|
|
440
|
+
arguments: [
|
|
441
|
+
{
|
|
442
|
+
name: "name",
|
|
443
|
+
description: "Name of the country",
|
|
444
|
+
required: true,
|
|
445
|
+
enum: ["Germany", "France", "Italy"],
|
|
446
|
+
},
|
|
447
|
+
],
|
|
448
|
+
});
|
|
449
|
+
```
|
|
450
|
+
|
|
395
451
|
### Sessions
|
|
396
452
|
|
|
397
453
|
The `session` object is an instance of `FastMCPSession` and it describes active client sessions.
|
|
@@ -462,6 +518,10 @@ You can listen to events emitted by the session using the `on` method:
|
|
|
462
518
|
session.on("rootsChanged", (event) => {
|
|
463
519
|
console.log("Roots changed:", event.roots);
|
|
464
520
|
});
|
|
521
|
+
|
|
522
|
+
session.on("error", (event) => {
|
|
523
|
+
console.error("Error:", event.error);
|
|
524
|
+
});
|
|
465
525
|
```
|
|
466
526
|
|
|
467
527
|
## Running Your Server
|
package/dist/FastMCP.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ type FastMCPSessionEvents = {
|
|
|
20
20
|
rootsChanged: (event: {
|
|
21
21
|
roots: Root[];
|
|
22
22
|
}) => void;
|
|
23
|
+
error: (event: {
|
|
24
|
+
error: Error;
|
|
25
|
+
}) => void;
|
|
23
26
|
};
|
|
24
27
|
/**
|
|
25
28
|
* Generates an image content object from a URL, file path, or buffer.
|
|
@@ -83,6 +86,11 @@ type ContentResult = {
|
|
|
83
86
|
content: Content[];
|
|
84
87
|
isError?: boolean;
|
|
85
88
|
};
|
|
89
|
+
type Completion = {
|
|
90
|
+
values: string[];
|
|
91
|
+
total?: number;
|
|
92
|
+
hasMore?: boolean;
|
|
93
|
+
};
|
|
86
94
|
type Tool<Params extends ToolParameters = ToolParameters> = {
|
|
87
95
|
name: string;
|
|
88
96
|
description?: string;
|
|
@@ -100,22 +108,39 @@ type Resource = {
|
|
|
100
108
|
blob: string;
|
|
101
109
|
}>;
|
|
102
110
|
};
|
|
103
|
-
type
|
|
111
|
+
type ArgumentValueCompleter = (value: string) => Promise<Completion>;
|
|
112
|
+
type InputPromptArgument = Readonly<{
|
|
104
113
|
name: string;
|
|
105
114
|
description?: string;
|
|
106
115
|
required?: boolean;
|
|
116
|
+
complete?: ArgumentValueCompleter;
|
|
117
|
+
enum?: string[];
|
|
107
118
|
}>;
|
|
108
|
-
type ArgumentsToObject<T extends
|
|
119
|
+
type ArgumentsToObject<T extends InputPromptArgument[]> = {
|
|
109
120
|
[K in T[number]["name"]]: Extract<T[number], {
|
|
110
121
|
name: K;
|
|
111
122
|
}>["required"] extends true ? string : string | undefined;
|
|
112
123
|
};
|
|
113
|
-
type
|
|
124
|
+
type InputPrompt<Arguments extends InputPromptArgument[] = InputPromptArgument[], Args = ArgumentsToObject<Arguments>> = {
|
|
114
125
|
name: string;
|
|
115
126
|
description?: string;
|
|
116
|
-
arguments?:
|
|
127
|
+
arguments?: InputPromptArgument[];
|
|
117
128
|
load: (args: Args) => Promise<string>;
|
|
118
129
|
};
|
|
130
|
+
type PromptArgument = Readonly<{
|
|
131
|
+
name: string;
|
|
132
|
+
description?: string;
|
|
133
|
+
required?: boolean;
|
|
134
|
+
complete?: ArgumentValueCompleter;
|
|
135
|
+
enum?: string[];
|
|
136
|
+
}>;
|
|
137
|
+
type Prompt<Arguments extends PromptArgument[] = PromptArgument[], Args = ArgumentsToObject<Arguments>> = {
|
|
138
|
+
arguments?: PromptArgument[];
|
|
139
|
+
complete?: (name: string, value: string) => Promise<Completion>;
|
|
140
|
+
description?: string;
|
|
141
|
+
load: (args: Args) => Promise<string>;
|
|
142
|
+
name: string;
|
|
143
|
+
};
|
|
119
144
|
type ServerOptions = {
|
|
120
145
|
name: string;
|
|
121
146
|
version: `${number}.${number}.${number}`;
|
|
@@ -135,6 +160,7 @@ declare class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
135
160
|
resources: Resource[];
|
|
136
161
|
prompts: Prompt[];
|
|
137
162
|
});
|
|
163
|
+
private addPrompt;
|
|
138
164
|
get clientCapabilities(): ClientCapabilities | null;
|
|
139
165
|
get server(): Server;
|
|
140
166
|
connect(transport: Transport): Promise<void>;
|
|
@@ -142,6 +168,7 @@ declare class FastMCPSession extends FastMCPSessionEventEmitter {
|
|
|
142
168
|
close(): Promise<void>;
|
|
143
169
|
private setupErrorHandling;
|
|
144
170
|
get loggingLevel(): LoggingLevel;
|
|
171
|
+
private setupCompleteHandlers;
|
|
145
172
|
private setupRootsHandlers;
|
|
146
173
|
private setupLoggingHandlers;
|
|
147
174
|
private setupToolHandlers;
|
|
@@ -169,7 +196,7 @@ declare class FastMCP extends FastMCPEventEmitter {
|
|
|
169
196
|
/**
|
|
170
197
|
* Adds a prompt to the server.
|
|
171
198
|
*/
|
|
172
|
-
addPrompt<const Args extends
|
|
199
|
+
addPrompt<const Args extends InputPromptArgument[]>(prompt: InputPrompt<Args>): void;
|
|
173
200
|
/**
|
|
174
201
|
* Starts the server.
|
|
175
202
|
*/
|
|
@@ -188,4 +215,4 @@ declare class FastMCP extends FastMCPEventEmitter {
|
|
|
188
215
|
stop(): Promise<void>;
|
|
189
216
|
}
|
|
190
217
|
|
|
191
|
-
export { FastMCP, FastMCPSession, type SSEServer, UserError, imageContent };
|
|
218
|
+
export { FastMCP, FastMCPSession, type SSEServer, UnexpectedStateError, UserError, imageContent };
|
package/dist/FastMCP.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import {
|
|
5
5
|
CallToolRequestSchema,
|
|
6
|
+
CompleteRequestSchema,
|
|
6
7
|
ErrorCode,
|
|
7
8
|
GetPromptRequestSchema,
|
|
8
9
|
ListPromptsRequestSchema,
|
|
@@ -19,6 +20,7 @@ import { setTimeout as delay } from "timers/promises";
|
|
|
19
20
|
import { readFile } from "fs/promises";
|
|
20
21
|
import { fileTypeFromBuffer } from "file-type";
|
|
21
22
|
import { EventEmitter } from "events";
|
|
23
|
+
import Fuse from "fuse.js";
|
|
22
24
|
import { startSSEServer } from "mcp-proxy";
|
|
23
25
|
var imageContent = async (input) => {
|
|
24
26
|
let rawData;
|
|
@@ -87,6 +89,20 @@ var ContentResultZodSchema = z.object({
|
|
|
87
89
|
content: ContentZodSchema.array(),
|
|
88
90
|
isError: z.boolean().optional()
|
|
89
91
|
}).strict();
|
|
92
|
+
var CompletionZodSchema = z.object({
|
|
93
|
+
/**
|
|
94
|
+
* An array of completion values. Must not exceed 100 items.
|
|
95
|
+
*/
|
|
96
|
+
values: z.array(z.string()).max(100),
|
|
97
|
+
/**
|
|
98
|
+
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
99
|
+
*/
|
|
100
|
+
total: z.optional(z.number().int()),
|
|
101
|
+
/**
|
|
102
|
+
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
103
|
+
*/
|
|
104
|
+
hasMore: z.optional(z.boolean())
|
|
105
|
+
});
|
|
90
106
|
var FastMCPSessionEventEmitterBase = EventEmitter;
|
|
91
107
|
var FastMCPSessionEventEmitter = class extends FastMCPSessionEventEmitterBase {
|
|
92
108
|
};
|
|
@@ -96,6 +112,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
96
112
|
#server;
|
|
97
113
|
#clientCapabilities;
|
|
98
114
|
#roots = [];
|
|
115
|
+
#prompts = [];
|
|
99
116
|
constructor({
|
|
100
117
|
name,
|
|
101
118
|
version,
|
|
@@ -111,6 +128,9 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
111
128
|
this.#capabilities.resources = {};
|
|
112
129
|
}
|
|
113
130
|
if (prompts.length) {
|
|
131
|
+
for (const prompt of prompts) {
|
|
132
|
+
this.addPrompt(prompt);
|
|
133
|
+
}
|
|
114
134
|
this.#capabilities.prompts = {};
|
|
115
135
|
}
|
|
116
136
|
this.#capabilities.logging = {};
|
|
@@ -121,6 +141,7 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
121
141
|
this.setupErrorHandling();
|
|
122
142
|
this.setupLoggingHandlers();
|
|
123
143
|
this.setupRootsHandlers();
|
|
144
|
+
this.setupCompleteHandlers();
|
|
124
145
|
if (tools.length) {
|
|
125
146
|
this.setupToolHandlers(tools);
|
|
126
147
|
}
|
|
@@ -131,12 +152,47 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
131
152
|
this.setupPromptHandlers(prompts);
|
|
132
153
|
}
|
|
133
154
|
}
|
|
155
|
+
addPrompt(inputPrompt) {
|
|
156
|
+
const completers = {};
|
|
157
|
+
const enums = {};
|
|
158
|
+
for (const argument of inputPrompt.arguments ?? []) {
|
|
159
|
+
if (argument.complete) {
|
|
160
|
+
completers[argument.name] = argument.complete;
|
|
161
|
+
}
|
|
162
|
+
if (argument.enum) {
|
|
163
|
+
enums[argument.name] = argument.enum;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const prompt = {
|
|
167
|
+
...inputPrompt,
|
|
168
|
+
complete: async (name, value) => {
|
|
169
|
+
if (completers[name]) {
|
|
170
|
+
return await completers[name](value);
|
|
171
|
+
}
|
|
172
|
+
if (enums[name]) {
|
|
173
|
+
const fuse = new Fuse(enums[name], {
|
|
174
|
+
keys: ["value"]
|
|
175
|
+
});
|
|
176
|
+
const result = fuse.search(value);
|
|
177
|
+
return {
|
|
178
|
+
values: result.map((item) => item.item),
|
|
179
|
+
total: result.length
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
values: []
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
this.#prompts.push(prompt);
|
|
188
|
+
}
|
|
134
189
|
get clientCapabilities() {
|
|
135
190
|
return this.#clientCapabilities ?? null;
|
|
136
191
|
}
|
|
137
192
|
get server() {
|
|
138
193
|
return this.#server;
|
|
139
194
|
}
|
|
195
|
+
#pingInterval = null;
|
|
140
196
|
async connect(transport) {
|
|
141
197
|
if (this.#server.transport) {
|
|
142
198
|
throw new UnexpectedStateError("Server is already connected");
|
|
@@ -151,18 +207,30 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
151
207
|
}
|
|
152
208
|
await delay(100);
|
|
153
209
|
}
|
|
210
|
+
if (!this.#clientCapabilities) {
|
|
211
|
+
throw new UnexpectedStateError("Server did not connect");
|
|
212
|
+
}
|
|
154
213
|
if (this.#clientCapabilities?.roots) {
|
|
155
214
|
const roots = await this.#server.listRoots();
|
|
156
215
|
this.#roots = roots.roots;
|
|
157
216
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
217
|
+
this.#pingInterval = setInterval(async () => {
|
|
218
|
+
try {
|
|
219
|
+
await this.#server.ping();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
this.emit("error", {
|
|
222
|
+
error
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}, 1e3);
|
|
161
226
|
}
|
|
162
227
|
get roots() {
|
|
163
228
|
return this.#roots;
|
|
164
229
|
}
|
|
165
230
|
async close() {
|
|
231
|
+
if (this.#pingInterval) {
|
|
232
|
+
clearInterval(this.#pingInterval);
|
|
233
|
+
}
|
|
166
234
|
await this.#server.close();
|
|
167
235
|
}
|
|
168
236
|
setupErrorHandling() {
|
|
@@ -173,6 +241,37 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
173
241
|
get loggingLevel() {
|
|
174
242
|
return this.#loggingLevel;
|
|
175
243
|
}
|
|
244
|
+
setupCompleteHandlers() {
|
|
245
|
+
this.#server.setRequestHandler(CompleteRequestSchema, async (request) => {
|
|
246
|
+
if (request.params.ref.type === "ref/prompt") {
|
|
247
|
+
const prompt = this.#prompts.find(
|
|
248
|
+
(prompt2) => prompt2.name === request.params.ref.name
|
|
249
|
+
);
|
|
250
|
+
if (!prompt) {
|
|
251
|
+
throw new UnexpectedStateError("Unknown prompt", {
|
|
252
|
+
request
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (!prompt.complete) {
|
|
256
|
+
throw new UnexpectedStateError("Prompt does not support completion", {
|
|
257
|
+
request
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const completion = CompletionZodSchema.parse(
|
|
261
|
+
await prompt.complete(
|
|
262
|
+
request.params.argument.name,
|
|
263
|
+
request.params.argument.value
|
|
264
|
+
)
|
|
265
|
+
);
|
|
266
|
+
return {
|
|
267
|
+
completion
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
throw new UnexpectedStateError("Unexpected completion request", {
|
|
271
|
+
request
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
}
|
|
176
275
|
setupRootsHandlers() {
|
|
177
276
|
this.#server.setNotificationHandler(
|
|
178
277
|
RootsListChangedNotificationSchema,
|
|
@@ -358,7 +457,8 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
358
457
|
return {
|
|
359
458
|
name: prompt.name,
|
|
360
459
|
description: prompt.description,
|
|
361
|
-
arguments: prompt.arguments
|
|
460
|
+
arguments: prompt.arguments,
|
|
461
|
+
complete: prompt.complete
|
|
362
462
|
};
|
|
363
463
|
})
|
|
364
464
|
};
|
|
@@ -374,14 +474,12 @@ var FastMCPSession = class extends FastMCPSessionEventEmitter {
|
|
|
374
474
|
);
|
|
375
475
|
}
|
|
376
476
|
const args = request.params.arguments;
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
);
|
|
384
|
-
}
|
|
477
|
+
for (const arg of prompt.arguments ?? []) {
|
|
478
|
+
if (arg.required && !(args && arg.name in args)) {
|
|
479
|
+
throw new McpError(
|
|
480
|
+
ErrorCode.InvalidRequest,
|
|
481
|
+
`Missing required argument: ${arg.name}`
|
|
482
|
+
);
|
|
385
483
|
}
|
|
386
484
|
}
|
|
387
485
|
let result;
|
|
@@ -506,6 +604,7 @@ var FastMCP = class extends FastMCPEventEmitter {
|
|
|
506
604
|
export {
|
|
507
605
|
FastMCP,
|
|
508
606
|
FastMCPSession,
|
|
607
|
+
UnexpectedStateError,
|
|
509
608
|
UserError,
|
|
510
609
|
imageContent
|
|
511
610
|
};
|
package/dist/FastMCP.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/FastMCP.ts"],"sourcesContent":["import { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport {\n CallToolRequestSchema,\n ClientCapabilities,\n ErrorCode,\n GetPromptRequestSchema,\n ListPromptsRequestSchema,\n ListResourcesRequestSchema,\n ListToolsRequestSchema,\n McpError,\n ReadResourceRequestSchema,\n Root,\n RootsListChangedNotificationSchema,\n ServerCapabilities,\n SetLevelRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { z } from \"zod\";\nimport { setTimeout as delay } from \"timers/promises\";\nimport { readFile } from \"fs/promises\";\nimport { fileTypeFromBuffer } from \"file-type\";\nimport { StrictEventEmitter } from \"strict-event-emitter-types\";\nimport { EventEmitter } from \"events\";\nimport { startSSEServer } from \"mcp-proxy\";\nimport { Transport } from \"@modelcontextprotocol/sdk/shared/transport.js\";\n\nexport type SSEServer = {\n close: () => Promise<void>;\n};\n\ntype FastMCPEvents = {\n connect: (event: { session: FastMCPSession }) => void;\n disconnect: (event: { session: FastMCPSession }) => void;\n};\n\ntype FastMCPSessionEvents = {\n rootsChanged: (event: { roots: Root[] }) => void;\n};\n\n/**\n * Generates an image content object from a URL, file path, or buffer.\n */\nexport const imageContent = async (\n input: { url: string } | { path: string } | { buffer: Buffer },\n): Promise<ImageContent> => {\n let rawData: Buffer;\n\n if (\"url\" in input) {\n const response = await fetch(input.url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch image from URL: ${response.statusText}`);\n }\n\n rawData = Buffer.from(await response.arrayBuffer());\n } else if (\"path\" in input) {\n rawData = await readFile(input.path);\n } else if (\"buffer\" in input) {\n rawData = input.buffer;\n } else {\n throw new Error(\n \"Invalid input: Provide a valid 'url', 'path', or 'buffer'\",\n );\n }\n\n const mimeType = await fileTypeFromBuffer(rawData);\n\n const base64Data = rawData.toString(\"base64\");\n\n return {\n type: \"image\",\n data: base64Data,\n mimeType: mimeType?.mime ?? \"image/png\",\n } as const;\n};\n\nabstract class FastMCPError extends Error {\n public constructor(message?: string) {\n super(message);\n this.name = new.target.name;\n }\n}\n\ntype Extra = unknown;\n\ntype Extras = Record<string, Extra>;\n\nclass UnexpectedStateError extends FastMCPError {\n public extras?: Extras;\n\n public constructor(message: string, extras?: Extras) {\n super(message);\n this.name = new.target.name;\n this.extras = extras;\n }\n}\n\n/**\n * An error that is meant to be surfaced to the user.\n */\nexport class UserError extends UnexpectedStateError {}\n\ntype ToolParameters = z.ZodTypeAny;\n\ntype Literal = boolean | null | number | string | undefined;\n\ntype SerializableValue =\n | Literal\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\ntype Progress = {\n /**\n * The progress thus far. This should increase every time progress is made, even if the total is unknown.\n */\n progress: number;\n /**\n * Total number of items to process (or total progress required), if known.\n */\n total?: number;\n};\n\ntype Context = {\n reportProgress: (progress: Progress) => Promise<void>;\n log: {\n debug: (message: string, data?: SerializableValue) => void;\n error: (message: string, data?: SerializableValue) => void;\n info: (message: string, data?: SerializableValue) => void;\n warn: (message: string, data?: SerializableValue) => void;\n };\n};\n\ntype TextContent = {\n type: \"text\";\n text: string;\n};\n\nconst TextContentZodSchema = z\n .object({\n type: z.literal(\"text\"),\n /**\n * The text content of the message.\n */\n text: z.string(),\n })\n .strict() satisfies z.ZodType<TextContent>;\n\ntype ImageContent = {\n type: \"image\";\n data: string;\n mimeType: string;\n};\n\nconst ImageContentZodSchema = z\n .object({\n type: z.literal(\"image\"),\n /**\n * The base64-encoded image data.\n */\n data: z.string().base64(),\n /**\n * The MIME type of the image. Different providers may support different image types.\n */\n mimeType: z.string(),\n })\n .strict() satisfies z.ZodType<ImageContent>;\n\ntype Content = TextContent | ImageContent;\n\nconst ContentZodSchema = z.discriminatedUnion(\"type\", [\n TextContentZodSchema,\n ImageContentZodSchema,\n]) satisfies z.ZodType<Content>;\n\ntype ContentResult = {\n content: Content[];\n isError?: boolean;\n};\n\nconst ContentResultZodSchema = z\n .object({\n content: ContentZodSchema.array(),\n isError: z.boolean().optional(),\n })\n .strict() satisfies z.ZodType<ContentResult>;\n\ntype Tool<Params extends ToolParameters = ToolParameters> = {\n name: string;\n description?: string;\n parameters?: Params;\n execute: (\n args: z.infer<Params>,\n context: Context,\n ) => Promise<string | ContentResult | TextContent | ImageContent>;\n};\n\ntype Resource = {\n uri: string;\n name: string;\n description?: string;\n mimeType?: string;\n load: () => Promise<{ text: string } | { blob: string }>;\n};\n\ntype PromptArgument = Readonly<{\n name: string;\n description?: string;\n required?: boolean;\n}>;\n\ntype ArgumentsToObject<T extends PromptArgument[]> = {\n [K in T[number][\"name\"]]: Extract<\n T[number],\n { name: K }\n >[\"required\"] extends true\n ? string\n : string | undefined;\n};\n\ntype Prompt<\n Arguments extends PromptArgument[] = PromptArgument[],\n Args = ArgumentsToObject<Arguments>,\n> = {\n name: string;\n description?: string;\n arguments?: Arguments;\n load: (args: Args) => Promise<string>;\n};\n\ntype ServerOptions = {\n name: string;\n version: `${number}.${number}.${number}`;\n};\n\ntype LoggingLevel =\n | \"debug\"\n | \"info\"\n | \"notice\"\n | \"warning\"\n | \"error\"\n | \"critical\"\n | \"alert\"\n | \"emergency\";\n\nconst FastMCPSessionEventEmitterBase: {\n new (): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;\n} = EventEmitter;\n\nclass FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {}\n\nexport class FastMCPSession extends FastMCPSessionEventEmitter {\n #capabilities: ServerCapabilities = {};\n #loggingLevel: LoggingLevel = \"info\";\n #server: Server;\n #clientCapabilities?: ClientCapabilities;\n #roots: Root[] = [];\n\n constructor({\n name,\n version,\n tools,\n resources,\n prompts,\n }: {\n name: string;\n version: string;\n tools: Tool[];\n resources: Resource[];\n prompts: Prompt[];\n }) {\n super();\n\n if (tools.length) {\n this.#capabilities.tools = {};\n }\n\n if (resources.length) {\n this.#capabilities.resources = {};\n }\n\n if (prompts.length) {\n this.#capabilities.prompts = {};\n }\n\n this.#capabilities.logging = {};\n\n this.#server = new Server(\n { name: name, version: version },\n { capabilities: this.#capabilities },\n );\n\n this.setupErrorHandling();\n this.setupLoggingHandlers();\n this.setupRootsHandlers();\n\n if (tools.length) {\n this.setupToolHandlers(tools);\n }\n\n if (resources.length) {\n this.setupResourceHandlers(resources);\n }\n\n if (prompts.length) {\n this.setupPromptHandlers(prompts);\n }\n }\n\n public get clientCapabilities(): ClientCapabilities | null {\n return this.#clientCapabilities ?? null;\n }\n\n public get server(): Server {\n return this.#server;\n }\n\n public async connect(transport: Transport) {\n if (this.#server.transport) {\n throw new UnexpectedStateError(\"Server is already connected\");\n }\n\n await this.#server.connect(transport);\n\n let attempt = 0;\n\n while (attempt++ < 10) {\n const capabilities = await this.#server.getClientCapabilities();\n\n if (capabilities) {\n this.#clientCapabilities = capabilities;\n\n break;\n }\n\n await delay(100);\n }\n\n if (this.#clientCapabilities?.roots) {\n const roots = await this.#server.listRoots();\n\n this.#roots = roots.roots;\n }\n\n if (!this.#clientCapabilities) {\n throw new UnexpectedStateError(\"Server did not connect\");\n }\n }\n\n public get roots(): Root[] {\n return this.#roots;\n }\n\n public async close() {\n await this.#server.close();\n }\n\n private setupErrorHandling() {\n this.#server.onerror = (error) => {\n console.error(\"[MCP Error]\", error);\n };\n }\n\n public get loggingLevel(): LoggingLevel {\n return this.#loggingLevel;\n }\n\n private setupRootsHandlers() {\n this.#server.setNotificationHandler(\n RootsListChangedNotificationSchema,\n () => {\n this.#server.listRoots().then((roots) => {\n this.#roots = roots.roots;\n\n this.emit(\"rootsChanged\", {\n roots: roots.roots,\n });\n });\n },\n );\n }\n\n private setupLoggingHandlers() {\n this.#server.setRequestHandler(SetLevelRequestSchema, (request) => {\n this.#loggingLevel = request.params.level;\n\n return {};\n });\n }\n\n private setupToolHandlers(tools: Tool[]) {\n this.#server.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: tools.map((tool) => {\n return {\n name: tool.name,\n description: tool.description,\n inputSchema: tool.parameters\n ? zodToJsonSchema(tool.parameters)\n : undefined,\n };\n }),\n };\n });\n\n this.#server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const tool = tools.find((tool) => tool.name === request.params.name);\n\n if (!tool) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown tool: ${request.params.name}`,\n );\n }\n\n let args: any = undefined;\n\n if (tool.parameters) {\n const parsed = tool.parameters.safeParse(request.params.arguments);\n\n if (!parsed.success) {\n throw new McpError(\n ErrorCode.InvalidRequest,\n `Invalid ${request.params.name} arguments`,\n );\n }\n\n args = parsed.data;\n }\n\n const progressToken = request.params?._meta?.progressToken;\n\n let result: ContentResult;\n\n try {\n const reportProgress = async (progress: Progress) => {\n await this.#server.notification({\n method: \"notifications/progress\",\n params: {\n ...progress,\n progressToken,\n },\n });\n };\n\n const log = {\n debug: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"debug\",\n data: {\n message,\n context,\n },\n });\n },\n error: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"error\",\n data: {\n message,\n context,\n },\n });\n },\n info: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"info\",\n data: {\n message,\n context,\n },\n });\n },\n warn: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"warning\",\n data: {\n message,\n context,\n },\n });\n },\n };\n\n const maybeStringResult = await tool.execute(args, {\n reportProgress,\n log,\n });\n\n if (typeof maybeStringResult === \"string\") {\n result = ContentResultZodSchema.parse({\n content: [{ type: \"text\", text: maybeStringResult }],\n });\n } else if (\"type\" in maybeStringResult) {\n result = ContentResultZodSchema.parse({\n content: [maybeStringResult],\n });\n } else {\n result = ContentResultZodSchema.parse(maybeStringResult);\n }\n } catch (error) {\n if (error instanceof UserError) {\n return {\n content: [{ type: \"text\", text: error.message }],\n isError: true,\n };\n }\n\n return {\n content: [{ type: \"text\", text: `Error: ${error}` }],\n isError: true,\n };\n }\n\n return result;\n });\n }\n\n private setupResourceHandlers(resources: Resource[]) {\n this.#server.setRequestHandler(ListResourcesRequestSchema, async () => {\n return {\n resources: resources.map((resource) => {\n return {\n uri: resource.uri,\n name: resource.name,\n mimeType: resource.mimeType,\n };\n }),\n };\n });\n\n this.#server.setRequestHandler(\n ReadResourceRequestSchema,\n async (request) => {\n const resource = resources.find(\n (resource) => resource.uri === request.params.uri,\n );\n\n if (!resource) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown resource: ${request.params.uri}`,\n );\n }\n\n let result: Awaited<ReturnType<Resource[\"load\"]>>;\n\n try {\n result = await resource.load();\n } catch (error) {\n throw new McpError(\n ErrorCode.InternalError,\n `Error reading resource: ${error}`,\n {\n uri: resource.uri,\n },\n );\n }\n\n return {\n contents: [\n {\n uri: resource.uri,\n mimeType: resource.mimeType,\n ...result,\n },\n ],\n };\n },\n );\n }\n\n private setupPromptHandlers(prompts: Prompt[]) {\n this.#server.setRequestHandler(ListPromptsRequestSchema, async () => {\n return {\n prompts: prompts.map((prompt) => {\n return {\n name: prompt.name,\n description: prompt.description,\n arguments: prompt.arguments,\n };\n }),\n };\n });\n\n this.#server.setRequestHandler(GetPromptRequestSchema, async (request) => {\n const prompt = prompts.find(\n (prompt) => prompt.name === request.params.name,\n );\n\n if (!prompt) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown prompt: ${request.params.name}`,\n );\n }\n\n const args = request.params.arguments;\n\n if (prompt.arguments) {\n for (const arg of prompt.arguments) {\n if (arg.required && !(args && arg.name in args)) {\n throw new McpError(\n ErrorCode.InvalidRequest,\n `Missing required argument: ${arg.name}`,\n );\n }\n }\n }\n\n let result: Awaited<ReturnType<Prompt[\"load\"]>>;\n\n try {\n result = await prompt.load(args as Record<string, string | undefined>);\n } catch (error) {\n throw new McpError(\n ErrorCode.InternalError,\n `Error loading prompt: ${error}`,\n );\n }\n\n return {\n description: prompt.description,\n messages: [\n {\n role: \"user\",\n content: { type: \"text\", text: result },\n },\n ],\n };\n });\n }\n}\n\nconst FastMCPEventEmitterBase: {\n new (): StrictEventEmitter<EventEmitter, FastMCPEvents>;\n} = EventEmitter;\n\nclass FastMCPEventEmitter extends FastMCPEventEmitterBase {}\n\nexport class FastMCP extends FastMCPEventEmitter {\n #options: ServerOptions;\n #prompts: Prompt[] = [];\n #resources: Resource[] = [];\n #sessions: FastMCPSession[] = [];\n #sseServer: SSEServer | null = null;\n #tools: Tool[] = [];\n\n constructor(public options: ServerOptions) {\n super();\n\n this.#options = options;\n }\n\n public get sessions(): FastMCPSession[] {\n return this.#sessions;\n }\n\n /**\n * Adds a tool to the server.\n */\n public addTool<Params extends ToolParameters>(tool: Tool<Params>) {\n this.#tools.push(tool as unknown as Tool);\n }\n\n /**\n * Adds a resource to the server.\n */\n public addResource(resource: Resource) {\n this.#resources.push(resource);\n }\n\n /**\n * Adds a prompt to the server.\n */\n public addPrompt<const Args extends PromptArgument[]>(prompt: Prompt<Args>) {\n this.#prompts.push(prompt);\n }\n\n /**\n * Starts the server.\n */\n public async start(\n options:\n | { transportType: \"stdio\" }\n | {\n transportType: \"sse\";\n sse: { endpoint: `/${string}`; port: number };\n } = {\n transportType: \"stdio\",\n },\n ) {\n if (options.transportType === \"stdio\") {\n const transport = new StdioServerTransport();\n\n const session = new FastMCPSession({\n name: this.#options.name,\n version: this.#options.version,\n tools: this.#tools,\n resources: this.#resources,\n prompts: this.#prompts,\n });\n\n await session.connect(transport);\n\n this.#sessions.push(session);\n\n this.emit(\"connect\", {\n session,\n });\n\n console.error(`server is running on stdio`);\n } else if (options.transportType === \"sse\") {\n this.#sseServer = await startSSEServer<FastMCPSession>({\n endpoint: options.sse.endpoint as `/${string}`,\n port: options.sse.port,\n createServer: async () => {\n return new FastMCPSession({\n name: this.#options.name,\n version: this.#options.version,\n tools: this.#tools,\n resources: this.#resources,\n prompts: this.#prompts,\n });\n },\n onClose: (session) => {\n this.emit(\"disconnect\", {\n session,\n });\n },\n onConnect: async (session) => {\n this.#sessions.push(session);\n\n this.emit(\"connect\", {\n session,\n });\n },\n });\n\n console.error(\n `server is running on SSE at http://localhost:${options.sse.port}${options.sse.endpoint}`,\n );\n } else {\n throw new Error(\"Invalid transport type\");\n }\n }\n\n /**\n * Stops the server.\n */\n public async stop() {\n if (this.#sseServer) {\n this.#sseServer.close();\n }\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAClB,SAAS,cAAc,aAAa;AACpC,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AAEnC,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAmBxB,IAAM,eAAe,OAC1B,UAC0B;AAC1B,MAAI;AAEJ,MAAI,SAAS,OAAO;AAClB,UAAM,WAAW,MAAM,MAAM,MAAM,GAAG;AAEtC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,mCAAmC,SAAS,UAAU,EAAE;AAAA,IAC1E;AAEA,c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;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,OAAO;AAClB,QAAI,KAAK,YAAY;AACnB,WAAK,WAAW,MAAM;AAAA,IACxB;AAAA,EACF;AACF;","names":["tool","resource","prompt"]}
|
|
1
|
+
{"version":3,"sources":["../src/FastMCP.ts"],"sourcesContent":["import { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport {\n CallToolRequestSchema,\n ClientCapabilities,\n CompleteRequestSchema,\n ErrorCode,\n GetPromptRequestSchema,\n ListPromptsRequestSchema,\n ListResourcesRequestSchema,\n ListToolsRequestSchema,\n McpError,\n ReadResourceRequestSchema,\n Root,\n RootsListChangedNotificationSchema,\n ServerCapabilities,\n SetLevelRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { z } from \"zod\";\nimport { setTimeout as delay } from \"timers/promises\";\nimport { readFile } from \"fs/promises\";\nimport { fileTypeFromBuffer } from \"file-type\";\nimport { StrictEventEmitter } from \"strict-event-emitter-types\";\nimport { EventEmitter } from \"events\";\nimport Fuse from \"fuse.js\";\nimport { startSSEServer } from \"mcp-proxy\";\nimport { Transport } from \"@modelcontextprotocol/sdk/shared/transport.js\";\n\nexport type SSEServer = {\n close: () => Promise<void>;\n};\n\ntype FastMCPEvents = {\n connect: (event: { session: FastMCPSession }) => void;\n disconnect: (event: { session: FastMCPSession }) => void;\n};\n\ntype FastMCPSessionEvents = {\n rootsChanged: (event: { roots: Root[] }) => void;\n error: (event: { error: Error }) => void;\n};\n\n/**\n * Generates an image content object from a URL, file path, or buffer.\n */\nexport const imageContent = async (\n input: { url: string } | { path: string } | { buffer: Buffer },\n): Promise<ImageContent> => {\n let rawData: Buffer;\n\n if (\"url\" in input) {\n const response = await fetch(input.url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch image from URL: ${response.statusText}`);\n }\n\n rawData = Buffer.from(await response.arrayBuffer());\n } else if (\"path\" in input) {\n rawData = await readFile(input.path);\n } else if (\"buffer\" in input) {\n rawData = input.buffer;\n } else {\n throw new Error(\n \"Invalid input: Provide a valid 'url', 'path', or 'buffer'\",\n );\n }\n\n const mimeType = await fileTypeFromBuffer(rawData);\n\n const base64Data = rawData.toString(\"base64\");\n\n return {\n type: \"image\",\n data: base64Data,\n mimeType: mimeType?.mime ?? \"image/png\",\n } as const;\n};\n\nabstract class FastMCPError extends Error {\n public constructor(message?: string) {\n super(message);\n this.name = new.target.name;\n }\n}\n\ntype Extra = unknown;\n\ntype Extras = Record<string, Extra>;\n\nexport class UnexpectedStateError extends FastMCPError {\n public extras?: Extras;\n\n public constructor(message: string, extras?: Extras) {\n super(message);\n this.name = new.target.name;\n this.extras = extras;\n }\n}\n\n/**\n * An error that is meant to be surfaced to the user.\n */\nexport class UserError extends UnexpectedStateError {}\n\ntype ToolParameters = z.ZodTypeAny;\n\ntype Literal = boolean | null | number | string | undefined;\n\ntype SerializableValue =\n | Literal\n | SerializableValue[]\n | { [key: string]: SerializableValue };\n\ntype Progress = {\n /**\n * The progress thus far. This should increase every time progress is made, even if the total is unknown.\n */\n progress: number;\n /**\n * Total number of items to process (or total progress required), if known.\n */\n total?: number;\n};\n\ntype Context = {\n reportProgress: (progress: Progress) => Promise<void>;\n log: {\n debug: (message: string, data?: SerializableValue) => void;\n error: (message: string, data?: SerializableValue) => void;\n info: (message: string, data?: SerializableValue) => void;\n warn: (message: string, data?: SerializableValue) => void;\n };\n};\n\ntype TextContent = {\n type: \"text\";\n text: string;\n};\n\nconst TextContentZodSchema = z\n .object({\n type: z.literal(\"text\"),\n /**\n * The text content of the message.\n */\n text: z.string(),\n })\n .strict() satisfies z.ZodType<TextContent>;\n\ntype ImageContent = {\n type: \"image\";\n data: string;\n mimeType: string;\n};\n\nconst ImageContentZodSchema = z\n .object({\n type: z.literal(\"image\"),\n /**\n * The base64-encoded image data.\n */\n data: z.string().base64(),\n /**\n * The MIME type of the image. Different providers may support different image types.\n */\n mimeType: z.string(),\n })\n .strict() satisfies z.ZodType<ImageContent>;\n\ntype Content = TextContent | ImageContent;\n\nconst ContentZodSchema = z.discriminatedUnion(\"type\", [\n TextContentZodSchema,\n ImageContentZodSchema,\n]) satisfies z.ZodType<Content>;\n\ntype ContentResult = {\n content: Content[];\n isError?: boolean;\n};\n\nconst ContentResultZodSchema = z\n .object({\n content: ContentZodSchema.array(),\n isError: z.boolean().optional(),\n })\n .strict() satisfies z.ZodType<ContentResult>;\n\ntype Completion = {\n values: string[];\n total?: number;\n hasMore?: boolean;\n};\n\n/**\n * https://github.com/modelcontextprotocol/typescript-sdk/blob/3164da64d085ec4e022ae881329eee7b72f208d4/src/types.ts#L983-L1003\n */\nconst CompletionZodSchema = z.object({\n /**\n * An array of completion values. Must not exceed 100 items.\n */\n values: z.array(z.string()).max(100),\n /**\n * The total number of completion options available. This can exceed the number of values actually sent in the response.\n */\n total: z.optional(z.number().int()),\n /**\n * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.\n */\n hasMore: z.optional(z.boolean()),\n}) satisfies z.ZodType<Completion>;\n\ntype Tool<Params extends ToolParameters = ToolParameters> = {\n name: string;\n description?: string;\n parameters?: Params;\n execute: (\n args: z.infer<Params>,\n context: Context,\n ) => Promise<string | ContentResult | TextContent | ImageContent>;\n};\n\ntype Resource = {\n uri: string;\n name: string;\n description?: string;\n mimeType?: string;\n load: () => Promise<{ text: string } | { blob: string }>;\n};\n\ntype ArgumentValueCompleter = (value: string) => Promise<Completion>;\n\ntype InputPromptArgument = Readonly<{\n name: string;\n description?: string;\n required?: boolean;\n complete?: ArgumentValueCompleter;\n enum?: string[];\n}>;\n\ntype ArgumentsToObject<T extends InputPromptArgument[]> = {\n [K in T[number][\"name\"]]: Extract<\n T[number],\n { name: K }\n >[\"required\"] extends true\n ? string\n : string | undefined;\n};\n\ntype InputPrompt<\n Arguments extends InputPromptArgument[] = InputPromptArgument[],\n Args = ArgumentsToObject<Arguments>,\n> = {\n name: string;\n description?: string;\n arguments?: InputPromptArgument[];\n load: (args: Args) => Promise<string>;\n};\n\ntype PromptArgument = Readonly<{\n name: string;\n description?: string;\n required?: boolean;\n complete?: ArgumentValueCompleter;\n enum?: string[];\n}>;\n\ntype Prompt<\n Arguments extends PromptArgument[] = PromptArgument[],\n Args = ArgumentsToObject<Arguments>,\n> = {\n arguments?: PromptArgument[];\n complete?: (name: string, value: string) => Promise<Completion>;\n description?: string;\n load: (args: Args) => Promise<string>;\n name: string;\n};\n\ntype ServerOptions = {\n name: string;\n version: `${number}.${number}.${number}`;\n};\n\ntype LoggingLevel =\n | \"debug\"\n | \"info\"\n | \"notice\"\n | \"warning\"\n | \"error\"\n | \"critical\"\n | \"alert\"\n | \"emergency\";\n\nconst FastMCPSessionEventEmitterBase: {\n new (): StrictEventEmitter<EventEmitter, FastMCPSessionEvents>;\n} = EventEmitter;\n\nclass FastMCPSessionEventEmitter extends FastMCPSessionEventEmitterBase {}\n\nexport class FastMCPSession extends FastMCPSessionEventEmitter {\n #capabilities: ServerCapabilities = {};\n #loggingLevel: LoggingLevel = \"info\";\n #server: Server;\n #clientCapabilities?: ClientCapabilities;\n #roots: Root[] = [];\n #prompts: Prompt[] = [];\n\n constructor({\n name,\n version,\n tools,\n resources,\n prompts,\n }: {\n name: string;\n version: string;\n tools: Tool[];\n resources: Resource[];\n prompts: Prompt[];\n }) {\n super();\n\n if (tools.length) {\n this.#capabilities.tools = {};\n }\n\n if (resources.length) {\n this.#capabilities.resources = {};\n }\n\n if (prompts.length) {\n for (const prompt of prompts) {\n this.addPrompt(prompt);\n }\n\n this.#capabilities.prompts = {};\n }\n\n this.#capabilities.logging = {};\n\n this.#server = new Server(\n { name: name, version: version },\n { capabilities: this.#capabilities },\n );\n\n this.setupErrorHandling();\n this.setupLoggingHandlers();\n this.setupRootsHandlers();\n this.setupCompleteHandlers();\n\n if (tools.length) {\n this.setupToolHandlers(tools);\n }\n\n if (resources.length) {\n this.setupResourceHandlers(resources);\n }\n\n if (prompts.length) {\n this.setupPromptHandlers(prompts);\n }\n }\n\n private addPrompt(inputPrompt: InputPrompt) {\n const completers: Record<string, ArgumentValueCompleter> = {};\n const enums: Record<string, string[]> = {};\n\n for (const argument of inputPrompt.arguments ?? []) {\n if (argument.complete) {\n completers[argument.name] = argument.complete;\n }\n\n if (argument.enum) {\n enums[argument.name] = argument.enum;\n }\n }\n\n const prompt = {\n ...inputPrompt,\n complete: async (name: string, value: string) => {\n if (completers[name]) {\n return await completers[name](value);\n }\n\n if (enums[name]) {\n const fuse = new Fuse(enums[name], {\n keys: [\"value\"],\n });\n\n const result = fuse.search(value);\n\n return {\n values: result.map((item) => item.item),\n total: result.length,\n };\n }\n\n return {\n values: [],\n };\n },\n };\n\n this.#prompts.push(prompt);\n }\n\n public get clientCapabilities(): ClientCapabilities | null {\n return this.#clientCapabilities ?? null;\n }\n\n public get server(): Server {\n return this.#server;\n }\n\n #pingInterval: ReturnType<typeof setInterval> | null = null;\n\n public async connect(transport: Transport) {\n if (this.#server.transport) {\n throw new UnexpectedStateError(\"Server is already connected\");\n }\n\n await this.#server.connect(transport);\n\n let attempt = 0;\n\n while (attempt++ < 10) {\n const capabilities = await this.#server.getClientCapabilities();\n\n if (capabilities) {\n this.#clientCapabilities = capabilities;\n\n break;\n }\n\n await delay(100);\n }\n\n if (!this.#clientCapabilities) {\n throw new UnexpectedStateError(\"Server did not connect\");\n }\n\n if (this.#clientCapabilities?.roots) {\n const roots = await this.#server.listRoots();\n\n this.#roots = roots.roots;\n }\n\n this.#pingInterval = setInterval(async () => {\n try {\n await this.#server.ping();\n } catch (error) {\n this.emit(\"error\", {\n error: error as Error,\n });\n }\n }, 1000);\n }\n\n public get roots(): Root[] {\n return this.#roots;\n }\n\n public async close() {\n if (this.#pingInterval) {\n clearInterval(this.#pingInterval);\n }\n\n await this.#server.close();\n }\n\n private setupErrorHandling() {\n this.#server.onerror = (error) => {\n console.error(\"[MCP Error]\", error);\n };\n }\n\n public get loggingLevel(): LoggingLevel {\n return this.#loggingLevel;\n }\n\n private setupCompleteHandlers() {\n this.#server.setRequestHandler(CompleteRequestSchema, async (request) => {\n if (request.params.ref.type === \"ref/prompt\") {\n const prompt = this.#prompts.find(\n (prompt) => prompt.name === request.params.ref.name,\n );\n\n if (!prompt) {\n throw new UnexpectedStateError(\"Unknown prompt\", {\n request,\n });\n }\n\n if (!prompt.complete) {\n throw new UnexpectedStateError(\"Prompt does not support completion\", {\n request,\n });\n }\n\n const completion = CompletionZodSchema.parse(\n await prompt.complete(\n request.params.argument.name,\n request.params.argument.value,\n ),\n );\n\n return {\n completion,\n };\n }\n\n throw new UnexpectedStateError(\"Unexpected completion request\", {\n request,\n });\n });\n }\n\n private setupRootsHandlers() {\n this.#server.setNotificationHandler(\n RootsListChangedNotificationSchema,\n () => {\n this.#server.listRoots().then((roots) => {\n this.#roots = roots.roots;\n\n this.emit(\"rootsChanged\", {\n roots: roots.roots,\n });\n });\n },\n );\n }\n\n private setupLoggingHandlers() {\n this.#server.setRequestHandler(SetLevelRequestSchema, (request) => {\n this.#loggingLevel = request.params.level;\n\n return {};\n });\n }\n\n private setupToolHandlers(tools: Tool[]) {\n this.#server.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: tools.map((tool) => {\n return {\n name: tool.name,\n description: tool.description,\n inputSchema: tool.parameters\n ? zodToJsonSchema(tool.parameters)\n : undefined,\n };\n }),\n };\n });\n\n this.#server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const tool = tools.find((tool) => tool.name === request.params.name);\n\n if (!tool) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown tool: ${request.params.name}`,\n );\n }\n\n let args: any = undefined;\n\n if (tool.parameters) {\n const parsed = tool.parameters.safeParse(request.params.arguments);\n\n if (!parsed.success) {\n throw new McpError(\n ErrorCode.InvalidRequest,\n `Invalid ${request.params.name} arguments`,\n );\n }\n\n args = parsed.data;\n }\n\n const progressToken = request.params?._meta?.progressToken;\n\n let result: ContentResult;\n\n try {\n const reportProgress = async (progress: Progress) => {\n await this.#server.notification({\n method: \"notifications/progress\",\n params: {\n ...progress,\n progressToken,\n },\n });\n };\n\n const log = {\n debug: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"debug\",\n data: {\n message,\n context,\n },\n });\n },\n error: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"error\",\n data: {\n message,\n context,\n },\n });\n },\n info: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"info\",\n data: {\n message,\n context,\n },\n });\n },\n warn: (message: string, context?: SerializableValue) => {\n this.#server.sendLoggingMessage({\n level: \"warning\",\n data: {\n message,\n context,\n },\n });\n },\n };\n\n const maybeStringResult = await tool.execute(args, {\n reportProgress,\n log,\n });\n\n if (typeof maybeStringResult === \"string\") {\n result = ContentResultZodSchema.parse({\n content: [{ type: \"text\", text: maybeStringResult }],\n });\n } else if (\"type\" in maybeStringResult) {\n result = ContentResultZodSchema.parse({\n content: [maybeStringResult],\n });\n } else {\n result = ContentResultZodSchema.parse(maybeStringResult);\n }\n } catch (error) {\n if (error instanceof UserError) {\n return {\n content: [{ type: \"text\", text: error.message }],\n isError: true,\n };\n }\n\n return {\n content: [{ type: \"text\", text: `Error: ${error}` }],\n isError: true,\n };\n }\n\n return result;\n });\n }\n\n private setupResourceHandlers(resources: Resource[]) {\n this.#server.setRequestHandler(ListResourcesRequestSchema, async () => {\n return {\n resources: resources.map((resource) => {\n return {\n uri: resource.uri,\n name: resource.name,\n mimeType: resource.mimeType,\n };\n }),\n };\n });\n\n this.#server.setRequestHandler(\n ReadResourceRequestSchema,\n async (request) => {\n const resource = resources.find(\n (resource) => resource.uri === request.params.uri,\n );\n\n if (!resource) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown resource: ${request.params.uri}`,\n );\n }\n\n let result: Awaited<ReturnType<Resource[\"load\"]>>;\n\n try {\n result = await resource.load();\n } catch (error) {\n throw new McpError(\n ErrorCode.InternalError,\n `Error reading resource: ${error}`,\n {\n uri: resource.uri,\n },\n );\n }\n\n return {\n contents: [\n {\n uri: resource.uri,\n mimeType: resource.mimeType,\n ...result,\n },\n ],\n };\n },\n );\n }\n\n private setupPromptHandlers(prompts: Prompt[]) {\n this.#server.setRequestHandler(ListPromptsRequestSchema, async () => {\n return {\n prompts: prompts.map((prompt) => {\n return {\n name: prompt.name,\n description: prompt.description,\n arguments: prompt.arguments,\n complete: prompt.complete,\n };\n }),\n };\n });\n\n this.#server.setRequestHandler(GetPromptRequestSchema, async (request) => {\n const prompt = prompts.find(\n (prompt) => prompt.name === request.params.name,\n );\n\n if (!prompt) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown prompt: ${request.params.name}`,\n );\n }\n\n const args = request.params.arguments;\n\n for (const arg of prompt.arguments ?? []) {\n if (arg.required && !(args && arg.name in args)) {\n throw new McpError(\n ErrorCode.InvalidRequest,\n `Missing required argument: ${arg.name}`,\n );\n }\n }\n\n let result: Awaited<ReturnType<Prompt[\"load\"]>>;\n\n try {\n result = await prompt.load(args as Record<string, string | undefined>);\n } catch (error) {\n throw new McpError(\n ErrorCode.InternalError,\n `Error loading prompt: ${error}`,\n );\n }\n\n return {\n description: prompt.description,\n messages: [\n {\n role: \"user\",\n content: { type: \"text\", text: result },\n },\n ],\n };\n });\n }\n}\n\nconst FastMCPEventEmitterBase: {\n new (): StrictEventEmitter<EventEmitter, FastMCPEvents>;\n} = EventEmitter;\n\nclass FastMCPEventEmitter extends FastMCPEventEmitterBase {}\n\nexport class FastMCP extends FastMCPEventEmitter {\n #options: ServerOptions;\n #prompts: InputPrompt[] = [];\n #resources: Resource[] = [];\n #sessions: FastMCPSession[] = [];\n #sseServer: SSEServer | null = null;\n #tools: Tool[] = [];\n\n constructor(public options: ServerOptions) {\n super();\n\n this.#options = options;\n }\n\n public get sessions(): FastMCPSession[] {\n return this.#sessions;\n }\n\n /**\n * Adds a tool to the server.\n */\n public addTool<Params extends ToolParameters>(tool: Tool<Params>) {\n this.#tools.push(tool as unknown as Tool);\n }\n\n /**\n * Adds a resource to the server.\n */\n public addResource(resource: Resource) {\n this.#resources.push(resource);\n }\n\n /**\n * Adds a prompt to the server.\n */\n public addPrompt<const Args extends InputPromptArgument[]>(\n prompt: InputPrompt<Args>,\n ) {\n this.#prompts.push(prompt);\n }\n\n /**\n * Starts the server.\n */\n public async start(\n options:\n | { transportType: \"stdio\" }\n | {\n transportType: \"sse\";\n sse: { endpoint: `/${string}`; port: number };\n } = {\n transportType: \"stdio\",\n },\n ) {\n if (options.transportType === \"stdio\") {\n const transport = new StdioServerTransport();\n\n const session = new FastMCPSession({\n name: this.#options.name,\n version: this.#options.version,\n tools: this.#tools,\n resources: this.#resources,\n prompts: this.#prompts,\n });\n\n await session.connect(transport);\n\n this.#sessions.push(session);\n\n this.emit(\"connect\", {\n session,\n });\n\n console.error(`server is running on stdio`);\n } else if (options.transportType === \"sse\") {\n this.#sseServer = await startSSEServer<FastMCPSession>({\n endpoint: options.sse.endpoint as `/${string}`,\n port: options.sse.port,\n createServer: async () => {\n return new FastMCPSession({\n name: this.#options.name,\n version: this.#options.version,\n tools: this.#tools,\n resources: this.#resources,\n prompts: this.#prompts,\n });\n },\n onClose: (session) => {\n this.emit(\"disconnect\", {\n session,\n });\n },\n onConnect: async (session) => {\n this.#sessions.push(session);\n\n this.emit(\"connect\", {\n session,\n });\n },\n });\n\n console.error(\n `server is running on SSE at http://localhost:${options.sse.port}${options.sse.endpoint}`,\n );\n } else {\n throw new Error(\"Invalid transport type\");\n }\n }\n\n /**\n * Stops the server.\n */\n public async stop() {\n if (this.#sseServer) {\n this.#sseServer.close();\n }\n }\n}\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AA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I,GAAG,QAAQ,IAAI,QAAQ;AAAA,MACzF;AAAA,IACF,OAAO;AACL,YAAM,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAa,OAAO;AAClB,QAAI,KAAK,YAAY;AACnB,WAAK,WAAW,MAAM;AAAA,IACxB;AAAA,EACF;AACF;","names":["prompt","tool","resource"]}
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastmcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"main": "dist/FastMCP.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
25
25
|
"execa": "^9.5.2",
|
|
26
26
|
"file-type": "^19.6.0",
|
|
27
|
-
"
|
|
27
|
+
"fuse.js": "^7.0.0",
|
|
28
|
+
"mcp-proxy": "^2.4.0",
|
|
28
29
|
"strict-event-emitter-types": "^2.0.0",
|
|
29
30
|
"yargs": "^17.7.2",
|
|
30
31
|
"zod": "^3.24.1",
|