fastmcp 1.23.0 → 1.23.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/dist/FastMCP.d.ts +165 -165
- package/dist/FastMCP.js +275 -275
- package/dist/FastMCP.js.map +1 -1
- package/dist/bin/fastmcp.js +9 -9
- package/dist/bin/fastmcp.js.map +1 -1
- package/eslint.config.ts +14 -0
- package/jsr.json +1 -1
- package/package.json +6 -1
- package/src/FastMCP.test.ts +398 -396
- package/src/FastMCP.ts +498 -498
- package/src/bin/fastmcp.ts +7 -7
- package/src/examples/addition.ts +25 -24
- package/eslint.config.js +0 -3
package/src/bin/fastmcp.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { execa } from "execa";
|
|
3
4
|
import yargs from "yargs";
|
|
4
5
|
import { hideBin } from "yargs/helpers";
|
|
5
|
-
import { execa } from "execa";
|
|
6
6
|
|
|
7
7
|
await yargs(hideBin(process.argv))
|
|
8
8
|
.scriptName("fastmcp")
|
|
@@ -11,17 +11,17 @@ await yargs(hideBin(process.argv))
|
|
|
11
11
|
"Start a development server",
|
|
12
12
|
(yargs) => {
|
|
13
13
|
return yargs.positional("file", {
|
|
14
|
-
type: "string",
|
|
15
|
-
describe: "The path to the server file",
|
|
16
14
|
demandOption: true,
|
|
15
|
+
describe: "The path to the server file",
|
|
16
|
+
type: "string",
|
|
17
17
|
});
|
|
18
18
|
},
|
|
19
19
|
async (argv) => {
|
|
20
20
|
try {
|
|
21
21
|
await execa({
|
|
22
|
+
stderr: "inherit",
|
|
22
23
|
stdin: "inherit",
|
|
23
24
|
stdout: "inherit",
|
|
24
|
-
stderr: "inherit",
|
|
25
25
|
})`npx @wong2/mcp-cli npx tsx ${argv.file}`;
|
|
26
26
|
} catch {
|
|
27
27
|
process.exit(1);
|
|
@@ -33,16 +33,16 @@ await yargs(hideBin(process.argv))
|
|
|
33
33
|
"Inspect a server file",
|
|
34
34
|
(yargs) => {
|
|
35
35
|
return yargs.positional("file", {
|
|
36
|
-
type: "string",
|
|
37
|
-
describe: "The path to the server file",
|
|
38
36
|
demandOption: true,
|
|
37
|
+
describe: "The path to the server file",
|
|
38
|
+
type: "string",
|
|
39
39
|
});
|
|
40
40
|
},
|
|
41
41
|
async (argv) => {
|
|
42
42
|
try {
|
|
43
43
|
await execa({
|
|
44
|
-
stdout: "inherit",
|
|
45
44
|
stderr: "inherit",
|
|
45
|
+
stdout: "inherit",
|
|
46
46
|
})`npx @modelcontextprotocol/inspector npx tsx ${argv.file}`;
|
|
47
47
|
} catch {
|
|
48
48
|
process.exit(1);
|
package/src/examples/addition.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { type } from "arktype";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* This is a complete example of an MCP server.
|
|
3
7
|
*/
|
|
4
8
|
import { FastMCP } from "../FastMCP.js";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
import { type } from "arktype";
|
|
7
|
-
import * as v from "valibot";
|
|
8
9
|
|
|
9
10
|
const server = new FastMCP({
|
|
10
11
|
name: "Addition",
|
|
@@ -18,19 +19,19 @@ const AddParamsZod = z.object({
|
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
server.addTool({
|
|
21
|
-
name: "add-zod",
|
|
22
|
-
description: "Add two numbers (using Zod schema)",
|
|
23
|
-
parameters: AddParamsZod,
|
|
24
22
|
annotations: {
|
|
25
|
-
title: "Addition (Zod)",
|
|
26
|
-
readOnlyHint: true, // This tool doesn't modify anything
|
|
27
23
|
openWorldHint: false, // This tool doesn't interact with external systems
|
|
24
|
+
readOnlyHint: true, // This tool doesn't modify anything
|
|
25
|
+
title: "Addition (Zod)",
|
|
28
26
|
},
|
|
27
|
+
description: "Add two numbers (using Zod schema)",
|
|
29
28
|
execute: async (args) => {
|
|
30
29
|
// args is typed as { a: number, b: number }
|
|
31
30
|
console.log(`[Zod] Adding ${args.a} and ${args.b}`);
|
|
32
31
|
return String(args.a + args.b);
|
|
33
32
|
},
|
|
33
|
+
name: "add-zod",
|
|
34
|
+
parameters: AddParamsZod,
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
// --- ArkType Example ---
|
|
@@ -40,21 +41,21 @@ const AddParamsArkType = type({
|
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
server.addTool({
|
|
43
|
-
name: "add-arktype",
|
|
44
|
-
description: "Add two numbers (using ArkType schema)",
|
|
45
|
-
parameters: AddParamsArkType,
|
|
46
44
|
annotations: {
|
|
47
|
-
title: "Addition (ArkType)",
|
|
48
|
-
readOnlyHint: false, // Example showing a modifying tool
|
|
49
45
|
destructiveHint: true, // This would perform destructive operations
|
|
50
46
|
idempotentHint: true, // But operations can be repeated safely
|
|
51
47
|
openWorldHint: true, // Interacts with external systems
|
|
48
|
+
readOnlyHint: false, // Example showing a modifying tool
|
|
49
|
+
title: "Addition (ArkType)",
|
|
52
50
|
},
|
|
51
|
+
description: "Add two numbers (using ArkType schema)",
|
|
53
52
|
execute: async (args) => {
|
|
54
53
|
// args is typed as { a: number, b: number } based on AddParamsArkType.infer
|
|
55
54
|
console.log(`[ArkType] Adding ${args.a} and ${args.b}`);
|
|
56
55
|
return String(args.a + args.b);
|
|
57
56
|
},
|
|
57
|
+
name: "add-arktype",
|
|
58
|
+
parameters: AddParamsArkType,
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
// --- Valibot Example ---
|
|
@@ -64,44 +65,44 @@ const AddParamsValibot = v.object({
|
|
|
64
65
|
});
|
|
65
66
|
|
|
66
67
|
server.addTool({
|
|
67
|
-
name: "add-valibot",
|
|
68
|
-
description: "Add two numbers (using Valibot schema)",
|
|
69
|
-
parameters: AddParamsValibot,
|
|
70
68
|
annotations: {
|
|
71
|
-
title: "Addition (Valibot)",
|
|
72
|
-
readOnlyHint: true,
|
|
73
69
|
openWorldHint: false,
|
|
70
|
+
readOnlyHint: true,
|
|
71
|
+
title: "Addition (Valibot)",
|
|
74
72
|
},
|
|
73
|
+
description: "Add two numbers (using Valibot schema)",
|
|
75
74
|
execute: async (args) => {
|
|
76
75
|
console.log(`[Valibot] Adding ${args.a} and ${args.b}`);
|
|
77
76
|
return String(args.a + args.b);
|
|
78
77
|
},
|
|
78
|
+
name: "add-valibot",
|
|
79
|
+
parameters: AddParamsValibot,
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
server.addResource({
|
|
82
|
-
uri: "file:///logs/app.log",
|
|
83
|
-
name: "Application Logs",
|
|
84
|
-
mimeType: "text/plain",
|
|
85
83
|
async load() {
|
|
86
84
|
return {
|
|
87
85
|
text: "Example log content",
|
|
88
86
|
};
|
|
89
87
|
},
|
|
88
|
+
mimeType: "text/plain",
|
|
89
|
+
name: "Application Logs",
|
|
90
|
+
uri: "file:///logs/app.log",
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
server.addPrompt({
|
|
93
|
-
name: "git-commit",
|
|
94
|
-
description: "Generate a Git commit message",
|
|
95
94
|
arguments: [
|
|
96
95
|
{
|
|
97
|
-
name: "changes",
|
|
98
96
|
description: "Git diff or description of changes",
|
|
97
|
+
name: "changes",
|
|
99
98
|
required: true,
|
|
100
99
|
},
|
|
101
100
|
],
|
|
101
|
+
description: "Generate a Git commit message",
|
|
102
102
|
load: async (args) => {
|
|
103
103
|
return `Generate a concise but descriptive commit message for these changes:\n\n${args.changes}`;
|
|
104
104
|
},
|
|
105
|
+
name: "git-commit",
|
|
105
106
|
});
|
|
106
107
|
|
|
107
108
|
server.start({
|
package/eslint.config.js
DELETED