fastmcp 1.19.0 → 1.19.2
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 +1 -0
- package/jsr.json +1 -1
- package/package.json +5 -5
- package/src/FastMCP.test.ts +168 -0
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ A TypeScript framework for building [MCP](https://modelcontextprotocol.io/) serv
|
|
|
14
14
|
- [Logging](#logging)
|
|
15
15
|
- [Error handling](#errors)
|
|
16
16
|
- [SSE](#sse)
|
|
17
|
+
- CORS (enabled by default)
|
|
17
18
|
- [Progress notifications](#progress)
|
|
18
19
|
- [Typed server events](#typed-server-events)
|
|
19
20
|
- [Prompt argument auto-completion](#prompt-argument-auto-completion)
|
package/jsr.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastmcp",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.2",
|
|
4
4
|
"main": "dist/FastMCP.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@modelcontextprotocol/sdk": "^1.6.0",
|
|
25
25
|
"execa": "^9.5.2",
|
|
26
|
-
"file-type": "^20.
|
|
26
|
+
"file-type": "^20.3.0",
|
|
27
27
|
"fuse.js": "^7.1.0",
|
|
28
|
-
"mcp-proxy": "^2.5.
|
|
28
|
+
"mcp-proxy": "^2.5.1",
|
|
29
29
|
"strict-event-emitter-types": "^2.0.0",
|
|
30
30
|
"uri-templates": "^0.2.0",
|
|
31
31
|
"yargs": "^17.7.2",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"jsr": "^0.13.3",
|
|
60
60
|
"prettier": "^3.5.2",
|
|
61
61
|
"semantic-release": "^24.2.3",
|
|
62
|
-
"tsup": "^8.
|
|
62
|
+
"tsup": "^8.4.0",
|
|
63
63
|
"typescript": "^5.7.3",
|
|
64
|
-
"vitest": "^3.0.
|
|
64
|
+
"vitest": "^3.0.7"
|
|
65
65
|
},
|
|
66
66
|
"tsup": {
|
|
67
67
|
"entry": [
|
package/src/FastMCP.test.ts
CHANGED
|
@@ -1313,3 +1313,171 @@ test("throws ErrorCode.InvalidParams if tool parameters do not match zod schema"
|
|
|
1313
1313
|
},
|
|
1314
1314
|
});
|
|
1315
1315
|
});
|
|
1316
|
+
|
|
1317
|
+
test("server remains usable after InvalidParams error", async () => {
|
|
1318
|
+
await runWithTestServer({
|
|
1319
|
+
server: async () => {
|
|
1320
|
+
const server = new FastMCP({
|
|
1321
|
+
name: "Test",
|
|
1322
|
+
version: "1.0.0",
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
server.addTool({
|
|
1326
|
+
name: "add",
|
|
1327
|
+
description: "Add two numbers",
|
|
1328
|
+
parameters: z.object({
|
|
1329
|
+
a: z.number(),
|
|
1330
|
+
b: z.number(),
|
|
1331
|
+
}),
|
|
1332
|
+
execute: async (args) => {
|
|
1333
|
+
return String(args.a + args.b);
|
|
1334
|
+
},
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
return server;
|
|
1338
|
+
},
|
|
1339
|
+
run: async ({ client }) => {
|
|
1340
|
+
try {
|
|
1341
|
+
await client.callTool({
|
|
1342
|
+
name: "add",
|
|
1343
|
+
arguments: {
|
|
1344
|
+
a: 1,
|
|
1345
|
+
b: "invalid",
|
|
1346
|
+
},
|
|
1347
|
+
});
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
expect(error).toBeInstanceOf(McpError);
|
|
1350
|
+
|
|
1351
|
+
// @ts-expect-error - we know that error is an McpError
|
|
1352
|
+
expect(error.code).toBe(ErrorCode.InvalidParams);
|
|
1353
|
+
|
|
1354
|
+
// @ts-expect-error - we know that error is an McpError
|
|
1355
|
+
expect(error.message).toBe("MCP error -32602: MCP error -32602: Invalid add parameters");
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
expect(
|
|
1359
|
+
await client.callTool({
|
|
1360
|
+
name: "add",
|
|
1361
|
+
arguments: {
|
|
1362
|
+
a: 1,
|
|
1363
|
+
b: 2,
|
|
1364
|
+
},
|
|
1365
|
+
}),
|
|
1366
|
+
).toEqual({
|
|
1367
|
+
content: [{ type: "text", text: "3" }],
|
|
1368
|
+
});
|
|
1369
|
+
},
|
|
1370
|
+
});
|
|
1371
|
+
});
|
|
1372
|
+
|
|
1373
|
+
test("allows new clients to connect after a client disconnects", async () => {
|
|
1374
|
+
const port = await getRandomPort();
|
|
1375
|
+
|
|
1376
|
+
const server = new FastMCP({
|
|
1377
|
+
name: "Test",
|
|
1378
|
+
version: "1.0.0",
|
|
1379
|
+
});
|
|
1380
|
+
|
|
1381
|
+
server.addTool({
|
|
1382
|
+
name: "add",
|
|
1383
|
+
description: "Add two numbers",
|
|
1384
|
+
parameters: z.object({
|
|
1385
|
+
a: z.number(),
|
|
1386
|
+
b: z.number(),
|
|
1387
|
+
}),
|
|
1388
|
+
execute: async (args) => {
|
|
1389
|
+
return String(args.a + args.b);
|
|
1390
|
+
},
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
await server.start({
|
|
1394
|
+
transportType: "sse",
|
|
1395
|
+
sse: {
|
|
1396
|
+
endpoint: "/sse",
|
|
1397
|
+
port,
|
|
1398
|
+
},
|
|
1399
|
+
});
|
|
1400
|
+
|
|
1401
|
+
const client1 = new Client(
|
|
1402
|
+
{
|
|
1403
|
+
name: "example-client",
|
|
1404
|
+
version: "1.0.0",
|
|
1405
|
+
},
|
|
1406
|
+
{
|
|
1407
|
+
capabilities: {},
|
|
1408
|
+
},
|
|
1409
|
+
);
|
|
1410
|
+
|
|
1411
|
+
const transport1 = new SSEClientTransport(
|
|
1412
|
+
new URL(`http://localhost:${port}/sse`),
|
|
1413
|
+
);
|
|
1414
|
+
|
|
1415
|
+
await client1.connect(transport1);
|
|
1416
|
+
|
|
1417
|
+
expect(
|
|
1418
|
+
await client1.callTool({
|
|
1419
|
+
name: "add",
|
|
1420
|
+
arguments: {
|
|
1421
|
+
a: 1,
|
|
1422
|
+
b: 2,
|
|
1423
|
+
},
|
|
1424
|
+
}),
|
|
1425
|
+
).toEqual({
|
|
1426
|
+
content: [{ type: "text", text: "3" }],
|
|
1427
|
+
});
|
|
1428
|
+
|
|
1429
|
+
await client1.close();
|
|
1430
|
+
|
|
1431
|
+
const client2 = new Client(
|
|
1432
|
+
{
|
|
1433
|
+
name: "example-client",
|
|
1434
|
+
version: "1.0.0",
|
|
1435
|
+
},
|
|
1436
|
+
{
|
|
1437
|
+
capabilities: {},
|
|
1438
|
+
},
|
|
1439
|
+
);
|
|
1440
|
+
|
|
1441
|
+
const transport2 = new SSEClientTransport(
|
|
1442
|
+
new URL(`http://localhost:${port}/sse`),
|
|
1443
|
+
);
|
|
1444
|
+
|
|
1445
|
+
await client2.connect(transport2);
|
|
1446
|
+
|
|
1447
|
+
expect(
|
|
1448
|
+
await client2.callTool({
|
|
1449
|
+
name: "add",
|
|
1450
|
+
arguments: {
|
|
1451
|
+
a: 1,
|
|
1452
|
+
b: 2,
|
|
1453
|
+
},
|
|
1454
|
+
}),
|
|
1455
|
+
).toEqual({
|
|
1456
|
+
content: [{ type: "text", text: "3" }],
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
await client2.close();
|
|
1460
|
+
|
|
1461
|
+
await server.stop();
|
|
1462
|
+
});
|
|
1463
|
+
|
|
1464
|
+
test("able to close server immediately after starting it", async () => {
|
|
1465
|
+
const port = await getRandomPort();
|
|
1466
|
+
|
|
1467
|
+
const server = new FastMCP({
|
|
1468
|
+
name: "Test",
|
|
1469
|
+
version: "1.0.0",
|
|
1470
|
+
});
|
|
1471
|
+
|
|
1472
|
+
await server.start({
|
|
1473
|
+
transportType: "sse",
|
|
1474
|
+
sse: {
|
|
1475
|
+
endpoint: "/sse",
|
|
1476
|
+
port,
|
|
1477
|
+
},
|
|
1478
|
+
});
|
|
1479
|
+
|
|
1480
|
+
// We were previously not waiting for the server to start.
|
|
1481
|
+
// Therefore, this would have caused error 'Server is not running.'.
|
|
1482
|
+
await server.stop();
|
|
1483
|
+
});
|