@agentailor/create-mcp-server 0.8.0 → 0.10.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 +12 -47
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +20 -10
- package/dist/cli.test.js +32 -20
- package/dist/index.js +0 -2
- package/dist/interactive.js +1 -48
- package/dist/project-generator.d.ts +1 -4
- package/dist/project-generator.js +8 -23
- package/dist/templates/common/agents.md.js +9 -30
- package/dist/templates/common/agents.md.test.js +4 -21
- package/dist/templates/common/env.example.js +2 -5
- package/dist/templates/common/package.json.js +3 -17
- package/dist/templates/common/templates.test.js +9 -44
- package/dist/templates/common/tsconfig.json.d.ts +1 -3
- package/dist/templates/common/tsconfig.json.js +2 -5
- package/dist/templates/common/types.d.ts +0 -11
- package/package.json +1 -1
- package/dist/templates/fastmcp/index.d.ts +0 -5
- package/dist/templates/fastmcp/index.js +0 -32
- package/dist/templates/fastmcp/readme.d.ts +0 -2
- package/dist/templates/fastmcp/readme.js +0 -240
- package/dist/templates/fastmcp/server.d.ts +0 -1
- package/dist/templates/fastmcp/server.js +0 -66
- package/dist/templates/fastmcp/templates.test.d.ts +0 -1
- package/dist/templates/fastmcp/templates.test.js +0 -109
package/README.md
CHANGED
|
@@ -29,10 +29,10 @@ npx @agentailor/create-mcp-server --name=my-server
|
|
|
29
29
|
|--------|-------|---------|-------------|
|
|
30
30
|
| `--name` | `-n` | — | Project name (required in CLI mode) |
|
|
31
31
|
| `--package-manager` | `-p` | `npm` | Package manager: npm, pnpm, yarn |
|
|
32
|
-
| `--framework` | `-f` | `sdk` |
|
|
32
|
+
| `--framework` | `-f` | `sdk` | Accepted for compatibility; `sdk` is the only framework |
|
|
33
33
|
| `--stdio` | — | `false` | Use stdio transport (for local clients) |
|
|
34
34
|
| `--template` | `-t` | `stateless` | Accepted for compatibility; SDK v2 serves both modes through one per-request idiom |
|
|
35
|
-
| `--oauth` | — | `false` | Enable OAuth (
|
|
35
|
+
| `--oauth` | — | `false` | Enable OAuth (HTTP only, incompatible with --stdio) |
|
|
36
36
|
| `--no-git` | — | `false` | Skip git initialization |
|
|
37
37
|
| `--no-skills` | — | `false` | Skip adding the tool-design skill |
|
|
38
38
|
| `--help` | `-h` | — | Show help |
|
|
@@ -47,68 +47,34 @@ npx @agentailor/create-mcp-server --name=my-server
|
|
|
47
47
|
# stdio server (for local clients)
|
|
48
48
|
npx @agentailor/create-mcp-server --name=my-server --stdio
|
|
49
49
|
|
|
50
|
-
# stdio with FastMCP
|
|
51
|
-
npx @agentailor/create-mcp-server --name=my-server --stdio --framework=fastmcp
|
|
52
|
-
|
|
53
50
|
# Full HTTP options
|
|
54
51
|
npx @agentailor/create-mcp-server \
|
|
55
52
|
--name=my-auth-server \
|
|
56
53
|
--package-manager=pnpm \
|
|
57
|
-
--framework=sdk \
|
|
58
54
|
--oauth
|
|
59
55
|
|
|
60
56
|
# Short flags
|
|
61
|
-
npx @agentailor/create-mcp-server -n my-server -p yarn
|
|
57
|
+
npx @agentailor/create-mcp-server -n my-server -p yarn --stdio
|
|
62
58
|
```
|
|
63
59
|
|
|
64
60
|
## Features
|
|
65
61
|
|
|
66
|
-
- **MCP SDK v2** —
|
|
67
|
-
- **Two frameworks** — Official MCP SDK or FastMCP
|
|
62
|
+
- **MCP SDK v2** — projects serve protocol revision `2026-07-28` and still accept 2025-era clients
|
|
68
63
|
- **Two transport types** — HTTP (streamable) or stdio (for local clients)
|
|
69
64
|
- **Stateless by design** — the SDK handler builds a fresh server per request, so HTTP servers scale without sticky sessions
|
|
70
|
-
- **Optional OAuth** — OIDC-compliant authentication (
|
|
65
|
+
- **Optional OAuth** — OIDC-compliant authentication (HTTP only) ([setup guide](docs/oauth-setup.md))
|
|
71
66
|
- **Package manager choice** — npm, pnpm, or yarn
|
|
72
67
|
- **TypeScript ready** — ready to customize
|
|
73
68
|
- **Docker ready** — production Dockerfile included (HTTP transport)
|
|
74
69
|
- **MCP Inspector** — built-in debugging with `npm run inspect`
|
|
75
70
|
|
|
76
|
-
##
|
|
77
|
-
|
|
78
|
-
| Framework | Description |
|
|
79
|
-
|-----------|-------------|
|
|
80
|
-
| **Official MCP SDK** (default) | SDK v2, full control with Express.js, supports OAuth |
|
|
81
|
-
| **FastMCP** | Simpler API with less boilerplate (still on SDK v1) |
|
|
82
|
-
|
|
83
|
-
### Official MCP SDK
|
|
71
|
+
## Official MCP SDK
|
|
84
72
|
|
|
85
|
-
|
|
73
|
+
Projects are generated against the [MCP TypeScript SDK v2](https://ts.sdk.modelcontextprotocol.io/v2/) — the split `@modelcontextprotocol/server`, `@modelcontextprotocol/express`, and `@modelcontextprotocol/node` packages, rather than the v1 `@modelcontextprotocol/sdk` monolith.
|
|
86
74
|
|
|
87
75
|
HTTP servers are built on `createMcpHandler`, which runs the server factory once per request. They serve protocol revision `2026-07-28` and also accept 2025-era clients. stdio servers use `serveStdio`, which negotiates the era per connection.
|
|
88
76
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
[FastMCP](https://github.com/punkpeye/fastmcp) is a TypeScript framework built on top of the official MCP SDK that provides a simpler, more intuitive API for building MCP servers.
|
|
92
|
-
|
|
93
|
-
> **Note:** FastMCP has not migrated to SDK v2 — it still depends on `@modelcontextprotocol/sdk` v1 internally, so FastMCP projects speak the 2025-era protocol. Choose the Official MCP SDK if you need protocol revision `2026-07-28`.
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
import { FastMCP } from "fastmcp";
|
|
97
|
-
import { z } from "zod";
|
|
98
|
-
|
|
99
|
-
const server = new FastMCP({ name: "My Server", version: "1.0.0" });
|
|
100
|
-
|
|
101
|
-
server.addTool({
|
|
102
|
-
name: "add",
|
|
103
|
-
description: "Add two numbers",
|
|
104
|
-
parameters: z.object({ a: z.number(), b: z.number() }),
|
|
105
|
-
execute: async ({ a, b }) => String(a + b),
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
server.start({ transportType: "httpStream", httpStream: { port: 3000 } });
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Learn more: [FastMCP Documentation](https://github.com/punkpeye/fastmcp)
|
|
77
|
+
> **FastMCP was removed in 0.10.0.** It never moved to SDK v2, so FastMCP projects stayed on the 2025-era protocol and shipped without tests. To scaffold one anyway, pin the last release that supports it: `npx @agentailor/create-mcp-server@0.9 --framework=fastmcp`.
|
|
112
78
|
|
|
113
79
|
## Transport Types
|
|
114
80
|
|
|
@@ -116,7 +82,7 @@ Learn more: [FastMCP Documentation](https://github.com/punkpeye/fastmcp)
|
|
|
116
82
|
|---------|------------------------|-------|
|
|
117
83
|
| Use case | Remote access, cloud deployment | Local clients (Claude Desktop) |
|
|
118
84
|
| Protocol | HTTP | stdin/stdout |
|
|
119
|
-
| OAuth support | ✓
|
|
85
|
+
| OAuth support | ✓ | — |
|
|
120
86
|
| Docker deployment | ✓ | — |
|
|
121
87
|
| Port configuration | ✓ | — |
|
|
122
88
|
|
|
@@ -153,9 +119,9 @@ my-mcp-server/
|
|
|
153
119
|
└── README.md
|
|
154
120
|
```
|
|
155
121
|
|
|
156
|
-
|
|
122
|
+
Projects come with a worked example — a small notes server — and a test suite
|
|
157
123
|
that runs green immediately, so there is a working pattern to copy when you add
|
|
158
|
-
your own tools.
|
|
124
|
+
your own tools.
|
|
159
125
|
|
|
160
126
|
Projects also get Agentailor's [tool-design](https://github.com/agentailor/skills)
|
|
161
127
|
skill at `.agents/skills/`, so a coding agent working in the project has the
|
|
@@ -170,7 +136,7 @@ to the protocol over stdio).
|
|
|
170
136
|
|
|
171
137
|
**Scripts:**
|
|
172
138
|
- `npm run dev` — build and start the server
|
|
173
|
-
- `npm test` — run the test suite
|
|
139
|
+
- `npm test` — run the test suite
|
|
174
140
|
- `npm run inspect` — open MCP Inspector (update URL in `package.json` if needed)
|
|
175
141
|
|
|
176
142
|
## Learning Resources
|
|
@@ -179,7 +145,6 @@ to the protocol over stdio).
|
|
|
179
145
|
|-------|-------------|
|
|
180
146
|
| [Create Your First MCP Server in 5 Minutes](https://blog.agentailor.com/posts/create-your-first-mcp-server-in-5-minutes?utm_source=github&utm_medium=readme&utm_campaign=create-mcp-server) | Build your first production-ready MCP server. A complete beginner guide to scaffolding a Fetch MCP server with TypeScript. |
|
|
181
147
|
| [Securing MCP Servers with Keycloak](https://blog.agentailor.com/posts/oauth-for-mcp-servers-practical-guide-keycloak?utm_source=github&utm_medium=readme&utm_campaign=create-mcp-server) | Learn how to secure your MCP servers with OAuth authentication using Keycloak. |
|
|
182
|
-
| [Getting Started with FastMCP](https://blog.agentailor.com/posts/getting-started-with-fastmcp?utm_source=github&utm_medium=readme&utm_campaign=create-mcp-server) | Build MCP servers faster with FastMCP — the TypeScript framework inspired by Python's most popular MCP library. |
|
|
183
148
|
| [OAuth for MCP Clients (Next.js + LangGraph.js)](https://blog.agentailor.com/posts/mcp-client-oauth-nextjs-langgraph?utm_source=github&utm_medium=readme&utm_campaign=create-mcp-server) | Implement OAuth authentication in your MCP client using Next.js and the MCP SDK. |
|
|
184
149
|
|
|
185
150
|
## Need help building MCP servers or agent infrastructure?
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { PackageManager,
|
|
1
|
+
import type { PackageManager, TransportType } from './templates/common/types.js';
|
|
2
2
|
export type TemplateType = 'stateless' | 'stateful';
|
|
3
3
|
export interface CLIOptions {
|
|
4
4
|
name: string;
|
|
5
5
|
packageManager: PackageManager;
|
|
6
|
-
framework: Framework;
|
|
7
6
|
transport: TransportType;
|
|
8
7
|
template: TemplateType;
|
|
9
8
|
oauth: boolean;
|
|
@@ -14,4 +13,5 @@ export interface ParseResult {
|
|
|
14
13
|
mode: 'interactive' | 'cli';
|
|
15
14
|
options?: CLIOptions;
|
|
16
15
|
}
|
|
16
|
+
export declare const FASTMCP_REMOVED_MESSAGE: string;
|
|
17
17
|
export declare function parseArguments(): ParseResult;
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Command, Option, InvalidArgumentError } from 'commander';
|
|
2
2
|
const NAME_REGEX = /^[a-z0-9-_]+$/i;
|
|
3
|
-
const VERSION = '0.
|
|
3
|
+
const VERSION = '0.10.0';
|
|
4
|
+
export const FASTMCP_REMOVED_MESSAGE = [
|
|
5
|
+
'FastMCP support was removed in 0.10.0. New projects use the Official MCP SDK;',
|
|
6
|
+
'drop --framework, or pass --framework=sdk.',
|
|
7
|
+
'To scaffold a FastMCP project, pin the last release that supports it:',
|
|
8
|
+
' npx @agentailor/create-mcp-server@0.9 --framework=fastmcp',
|
|
9
|
+
].join('\n');
|
|
4
10
|
function validateName(value) {
|
|
5
11
|
if (!NAME_REGEX.test(value)) {
|
|
6
12
|
throw new InvalidArgumentError('Project name can only contain letters, numbers, hyphens, and underscores');
|
|
@@ -17,9 +23,10 @@ export function parseArguments() {
|
|
|
17
23
|
.addOption(new Option('-p, --package-manager <manager>', 'Package manager')
|
|
18
24
|
.choices(['npm', 'pnpm', 'yarn'])
|
|
19
25
|
.default('npm'))
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
26
|
+
// Only one framework remains. The flag is still parsed so existing
|
|
27
|
+
// `--framework=sdk` invocations keep working, and so `fastmcp` gets a
|
|
28
|
+
// removal message instead of Commander's generic invalid-choice error.
|
|
29
|
+
.addOption(new Option('-f, --framework <framework>', 'Framework (sdk only; accepted for compatibility)').default('sdk'))
|
|
23
30
|
.addOption(new Option('-t, --template <type>', 'Template type (no effect on SDK projects; both generate the same server)')
|
|
24
31
|
.choices(['stateless', 'stateful'])
|
|
25
32
|
.default('stateless'))
|
|
@@ -36,6 +43,15 @@ export function parseArguments() {
|
|
|
36
43
|
if (!hasExplicitArgs) {
|
|
37
44
|
return { mode: 'interactive' };
|
|
38
45
|
}
|
|
46
|
+
// Checked before --name, so a FastMCP user sees why rather than a missing-name error.
|
|
47
|
+
if (opts.framework === 'fastmcp') {
|
|
48
|
+
console.error(`\nError: ${FASTMCP_REMOVED_MESSAGE}\n`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
if (opts.framework !== 'sdk') {
|
|
52
|
+
console.error(`\nError: unknown --framework "${opts.framework}". The only framework is sdk.\n`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
39
55
|
// CLI mode - validate required args
|
|
40
56
|
if (!opts.name) {
|
|
41
57
|
console.error('\nError: --name is required when using CLI arguments\n');
|
|
@@ -52,17 +68,11 @@ export function parseArguments() {
|
|
|
52
68
|
console.error('\nError: --template=stateful is not applicable with --stdio (stdio is inherently stateless)\n');
|
|
53
69
|
process.exit(1);
|
|
54
70
|
}
|
|
55
|
-
// Validate OAuth constraint
|
|
56
|
-
if (opts.oauth && opts.framework !== 'sdk') {
|
|
57
|
-
console.error('\nError: --oauth is only valid with --framework=sdk\n');
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
71
|
return {
|
|
61
72
|
mode: 'cli',
|
|
62
73
|
options: {
|
|
63
74
|
name: opts.name,
|
|
64
75
|
packageManager: opts.packageManager,
|
|
65
|
-
framework: opts.framework,
|
|
66
76
|
transport: (opts.stdio ? 'stdio' : 'http'),
|
|
67
77
|
template: opts.template,
|
|
68
78
|
oauth: opts.oauth,
|
package/dist/cli.test.js
CHANGED
|
@@ -31,7 +31,6 @@ describe('CLI argument parsing', () => {
|
|
|
31
31
|
const { parseArguments } = await import('./cli.js');
|
|
32
32
|
const result = parseArguments();
|
|
33
33
|
expect(result.options?.packageManager).toBe('npm');
|
|
34
|
-
expect(result.options?.framework).toBe('sdk');
|
|
35
34
|
expect(result.options?.transport).toBe('http');
|
|
36
35
|
expect(result.options?.template).toBe('stateless');
|
|
37
36
|
expect(result.options?.oauth).toBe(false);
|
|
@@ -43,7 +42,7 @@ describe('CLI argument parsing', () => {
|
|
|
43
42
|
'create-mcp-server',
|
|
44
43
|
'--name=test-project',
|
|
45
44
|
'--package-manager=pnpm',
|
|
46
|
-
'--framework=
|
|
45
|
+
'--framework=sdk',
|
|
47
46
|
'--template=stateful',
|
|
48
47
|
'--no-git',
|
|
49
48
|
];
|
|
@@ -52,7 +51,6 @@ describe('CLI argument parsing', () => {
|
|
|
52
51
|
expect(result.options).toEqual({
|
|
53
52
|
name: 'test-project',
|
|
54
53
|
packageManager: 'pnpm',
|
|
55
|
-
framework: 'fastmcp',
|
|
56
54
|
transport: 'http',
|
|
57
55
|
template: 'stateful',
|
|
58
56
|
oauth: false,
|
|
@@ -77,7 +75,6 @@ describe('CLI argument parsing', () => {
|
|
|
77
75
|
const result = parseArguments();
|
|
78
76
|
expect(result.options?.name).toBe('my-project');
|
|
79
77
|
expect(result.options?.packageManager).toBe('yarn');
|
|
80
|
-
expect(result.options?.framework).toBe('sdk');
|
|
81
78
|
expect(result.options?.template).toBe('stateful');
|
|
82
79
|
});
|
|
83
80
|
it('parses oauth flag correctly for sdk+stateful', async () => {
|
|
@@ -92,7 +89,6 @@ describe('CLI argument parsing', () => {
|
|
|
92
89
|
const { parseArguments } = await import('./cli.js');
|
|
93
90
|
const result = parseArguments();
|
|
94
91
|
expect(result.options?.oauth).toBe(true);
|
|
95
|
-
expect(result.options?.framework).toBe('sdk');
|
|
96
92
|
expect(result.options?.template).toBe('stateful');
|
|
97
93
|
});
|
|
98
94
|
// SDK v2 collapsed the stateless/stateful distinction, and OAuth is
|
|
@@ -102,7 +98,6 @@ describe('CLI argument parsing', () => {
|
|
|
102
98
|
const { parseArguments } = await import('./cli.js');
|
|
103
99
|
const result = parseArguments();
|
|
104
100
|
expect(result.options?.oauth).toBe(true);
|
|
105
|
-
expect(result.options?.framework).toBe('sdk');
|
|
106
101
|
expect(result.options?.template).toBe('stateless');
|
|
107
102
|
});
|
|
108
103
|
it('exits with error when --name is missing in CLI mode', async () => {
|
|
@@ -119,8 +114,10 @@ describe('CLI argument parsing', () => {
|
|
|
119
114
|
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('--name is required when using CLI arguments'));
|
|
120
115
|
consoleError.mockRestore();
|
|
121
116
|
});
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
// FastMCP was removed in 0.10.0. The flag value must explain that and say how
|
|
118
|
+
// to get the old behaviour, not fall through to a generic error.
|
|
119
|
+
it('exits with a removal message for --framework=fastmcp', async () => {
|
|
120
|
+
process.argv = ['node', 'create-mcp-server', '--name=test', '--framework=fastmcp'];
|
|
124
121
|
let exitCode;
|
|
125
122
|
process.exit = vi.fn((code) => {
|
|
126
123
|
exitCode = code;
|
|
@@ -130,7 +127,8 @@ describe('CLI argument parsing', () => {
|
|
|
130
127
|
const { parseArguments } = await import('./cli.js');
|
|
131
128
|
expect(() => parseArguments()).toThrow('process.exit called');
|
|
132
129
|
expect(exitCode).toBe(1);
|
|
133
|
-
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('
|
|
130
|
+
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('FastMCP support was removed in 0.10.0'));
|
|
131
|
+
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('@agentailor/create-mcp-server@0.9 --framework=fastmcp'));
|
|
134
132
|
consoleError.mockRestore();
|
|
135
133
|
});
|
|
136
134
|
it('exits with error for invalid project name', async () => {
|
|
@@ -163,18 +161,32 @@ describe('CLI argument parsing', () => {
|
|
|
163
161
|
expect(result.options?.transport).toBe('stdio');
|
|
164
162
|
expect(result.options?.oauth).toBe(false);
|
|
165
163
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
'
|
|
172
|
-
|
|
173
|
-
|
|
164
|
+
// Checked before --name, so the user learns FastMCP is gone rather than
|
|
165
|
+
// fixing --name first and only then hitting the removal.
|
|
166
|
+
it('reports the FastMCP removal even when --name is missing', async () => {
|
|
167
|
+
process.argv = ['node', 'create-mcp-server', '-f', 'fastmcp'];
|
|
168
|
+
process.exit = vi.fn(() => {
|
|
169
|
+
throw new Error('process.exit called');
|
|
170
|
+
});
|
|
171
|
+
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
174
172
|
const { parseArguments } = await import('./cli.js');
|
|
175
|
-
|
|
176
|
-
expect(
|
|
177
|
-
|
|
173
|
+
expect(() => parseArguments()).toThrow('process.exit called');
|
|
174
|
+
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('FastMCP support was removed'));
|
|
175
|
+
consoleError.mockRestore();
|
|
176
|
+
});
|
|
177
|
+
it('exits with error for an unknown --framework', async () => {
|
|
178
|
+
process.argv = ['node', 'create-mcp-server', '--name=test', '--framework=nope'];
|
|
179
|
+
let exitCode;
|
|
180
|
+
process.exit = vi.fn((code) => {
|
|
181
|
+
exitCode = code;
|
|
182
|
+
throw new Error('process.exit called');
|
|
183
|
+
});
|
|
184
|
+
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
185
|
+
const { parseArguments } = await import('./cli.js');
|
|
186
|
+
expect(() => parseArguments()).toThrow('process.exit called');
|
|
187
|
+
expect(exitCode).toBe(1);
|
|
188
|
+
expect(consoleError).toHaveBeenCalledWith(expect.stringContaining('unknown --framework'));
|
|
189
|
+
consoleError.mockRestore();
|
|
178
190
|
});
|
|
179
191
|
it('exits with error when --stdio combined with --oauth', async () => {
|
|
180
192
|
process.argv = [
|
package/dist/index.js
CHANGED
|
@@ -12,9 +12,7 @@ async function main() {
|
|
|
12
12
|
await generateProject({
|
|
13
13
|
projectName: options.name,
|
|
14
14
|
packageManager: options.packageManager,
|
|
15
|
-
framework: options.framework,
|
|
16
15
|
transport: options.transport,
|
|
17
|
-
templateType: options.template,
|
|
18
16
|
withOAuth: options.oauth,
|
|
19
17
|
withGitInit: options.git,
|
|
20
18
|
withSkills: options.skills,
|
package/dist/interactive.js
CHANGED
|
@@ -37,26 +37,6 @@ export async function runInteractiveMode() {
|
|
|
37
37
|
initial: 0,
|
|
38
38
|
}, { onCancel });
|
|
39
39
|
const packageManager = packageManagerResponse.packageManager || 'npm';
|
|
40
|
-
// Framework selection
|
|
41
|
-
const frameworkResponse = await prompts({
|
|
42
|
-
type: 'select',
|
|
43
|
-
name: 'framework',
|
|
44
|
-
message: 'Framework:',
|
|
45
|
-
choices: [
|
|
46
|
-
{
|
|
47
|
-
title: 'Official MCP SDK',
|
|
48
|
-
value: 'sdk',
|
|
49
|
-
description: 'Full control with Express.js',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
title: 'FastMCP',
|
|
53
|
-
value: 'fastmcp',
|
|
54
|
-
description: 'Simpler API, less boilerplate',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
initial: 0,
|
|
58
|
-
}, { onCancel });
|
|
59
|
-
const framework = frameworkResponse.framework || 'sdk';
|
|
60
40
|
// Transport selection
|
|
61
41
|
const transportResponse = await prompts({
|
|
62
42
|
type: 'select',
|
|
@@ -77,34 +57,9 @@ export async function runInteractiveMode() {
|
|
|
77
57
|
initial: 0,
|
|
78
58
|
}, { onCancel });
|
|
79
59
|
const transport = transportResponse.transport || 'http';
|
|
80
|
-
// Only asked for FastMCP HTTP, where it maps to a real `stateless` config
|
|
81
|
-
// flag. SDK projects generate the same server either way, so asking would be
|
|
82
|
-
// a meaningless choice.
|
|
83
|
-
let templateType = 'stateless';
|
|
84
|
-
if (transport === 'http' && framework === 'fastmcp') {
|
|
85
|
-
const templateTypeResponse = await prompts({
|
|
86
|
-
type: 'select',
|
|
87
|
-
name: 'templateType',
|
|
88
|
-
message: 'Server mode:',
|
|
89
|
-
choices: [
|
|
90
|
-
{
|
|
91
|
-
title: 'Stateless',
|
|
92
|
-
value: 'stateless',
|
|
93
|
-
description: 'No session state between requests',
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
title: 'Stateful',
|
|
97
|
-
value: 'stateful',
|
|
98
|
-
description: 'Session-based server with SSE support',
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
initial: 0,
|
|
102
|
-
}, { onCancel });
|
|
103
|
-
templateType = templateTypeResponse.templateType || 'stateless';
|
|
104
|
-
}
|
|
105
60
|
// OAuth prompt - available for any SDK HTTP project
|
|
106
61
|
let withOAuth = false;
|
|
107
|
-
if (transport === 'http'
|
|
62
|
+
if (transport === 'http') {
|
|
108
63
|
const oauthResponse = await prompts({
|
|
109
64
|
type: 'confirm',
|
|
110
65
|
name: 'withOAuth',
|
|
@@ -131,9 +86,7 @@ export async function runInteractiveMode() {
|
|
|
131
86
|
await generateProject({
|
|
132
87
|
projectName,
|
|
133
88
|
packageManager,
|
|
134
|
-
framework,
|
|
135
89
|
transport,
|
|
136
|
-
templateType,
|
|
137
90
|
withOAuth,
|
|
138
91
|
withGitInit,
|
|
139
92
|
withSkills,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TemplateType } from './cli.js';
|
|
1
|
+
import type { PackageManager, TransportType } from './templates/common/types.js';
|
|
3
2
|
export declare const packageManagerCommands: Record<PackageManager, {
|
|
4
3
|
install: string;
|
|
5
4
|
dev: string;
|
|
@@ -7,9 +6,7 @@ export declare const packageManagerCommands: Record<PackageManager, {
|
|
|
7
6
|
export interface ProjectConfig {
|
|
8
7
|
projectName: string;
|
|
9
8
|
packageManager: PackageManager;
|
|
10
|
-
framework: Framework;
|
|
11
9
|
transport: TransportType;
|
|
12
|
-
templateType: TemplateType;
|
|
13
10
|
withOAuth: boolean;
|
|
14
11
|
withGitInit: boolean;
|
|
15
12
|
withSkills: boolean;
|
|
@@ -9,7 +9,6 @@ import { getAgentsMdTemplate } from './templates/common/agents.md.js';
|
|
|
9
9
|
import { copySkill, SKILLS_UPDATE_COMMAND, SKILLS_INSTALL_HINT, SKILLS_DIR } from './skills.js';
|
|
10
10
|
import { getServerTemplate as getSdkStatelessServerTemplate, getIndexTemplate as getSdkStatelessIndexTemplate, getReadmeTemplate as getSdkStatelessReadmeTemplate, getStoreTemplate as getSdkStoreTemplate, getToolsTemplate as getSdkToolsTemplate, getPromptsTemplate as getSdkPromptsTemplate, getResourcesTemplate as getSdkResourcesTemplate, getStoreTestTemplate as getSdkStoreTestTemplate, getServerTestTemplate as getSdkServerTestTemplate, } from './templates/sdk/stateless/index.js';
|
|
11
11
|
import { getAuthTemplate as getSdkAuthTemplate } from './templates/sdk/stateful/index.js';
|
|
12
|
-
import { getServerTemplate as getFastMCPServerTemplate, getIndexTemplate as getFastMCPIndexTemplate, getReadmeTemplate as getFastMCPReadmeTemplate, } from './templates/fastmcp/index.js';
|
|
13
12
|
import { getServerTemplate as getSdkStdioServerTemplate, getIndexTemplate as getSdkStdioIndexTemplate, getReadmeTemplate as getSdkStdioReadmeTemplate, } from './templates/sdk/stdio/index.js';
|
|
14
13
|
import { getDockerfileTemplate, getDockerignoreTemplate } from './templates/deployment/index.js';
|
|
15
14
|
// Auth is keyed off `withOAuth`, never off the template type - see
|
|
@@ -20,23 +19,16 @@ const sdkHttpTemplateFunctions = {
|
|
|
20
19
|
getReadmeTemplate: getSdkStatelessReadmeTemplate,
|
|
21
20
|
getAuthTemplate: getSdkAuthTemplate,
|
|
22
21
|
};
|
|
23
|
-
const fastmcpTemplateFunctions = {
|
|
24
|
-
getServerTemplate: getFastMCPServerTemplate,
|
|
25
|
-
getIndexTemplate: getFastMCPIndexTemplate,
|
|
26
|
-
getReadmeTemplate: getFastMCPReadmeTemplate,
|
|
27
|
-
};
|
|
28
22
|
export const packageManagerCommands = {
|
|
29
23
|
npm: { install: 'npm install', dev: 'npm run dev' },
|
|
30
24
|
pnpm: { install: 'pnpm install', dev: 'pnpm dev' },
|
|
31
25
|
yarn: { install: 'yarn', dev: 'yarn dev' },
|
|
32
26
|
};
|
|
33
27
|
export async function generateProject(config) {
|
|
34
|
-
const { projectName, packageManager,
|
|
28
|
+
const { projectName, packageManager, transport, withOAuth, withGitInit, withSkills } = config;
|
|
35
29
|
const templateOptions = {
|
|
36
30
|
withOAuth: transport === 'http' ? withOAuth : false,
|
|
37
31
|
packageManager,
|
|
38
|
-
framework,
|
|
39
|
-
stateless: transport === 'stdio' ? true : templateType === 'stateless',
|
|
40
32
|
transport,
|
|
41
33
|
};
|
|
42
34
|
const projectPath = join(process.cwd(), projectName);
|
|
@@ -45,11 +37,7 @@ export async function generateProject(config) {
|
|
|
45
37
|
await mkdir(srcPath, { recursive: true });
|
|
46
38
|
// Build list of files to write
|
|
47
39
|
const filesToWrite = [];
|
|
48
|
-
if (
|
|
49
|
-
// FastMCP templates
|
|
50
|
-
filesToWrite.push(writeFile(join(srcPath, 'server.ts'), fastmcpTemplateFunctions.getServerTemplate(projectName)), writeFile(join(srcPath, 'index.ts'), fastmcpTemplateFunctions.getIndexTemplate(templateOptions)), writeFile(join(projectPath, 'README.md'), fastmcpTemplateFunctions.getReadmeTemplate(projectName, templateOptions)));
|
|
51
|
-
}
|
|
52
|
-
else if (transport === 'stdio') {
|
|
40
|
+
if (transport === 'stdio') {
|
|
53
41
|
// SDK stdio templates
|
|
54
42
|
filesToWrite.push(writeFile(join(srcPath, 'server.ts'), getSdkStdioServerTemplate(projectName)), writeFile(join(srcPath, 'index.ts'), getSdkStdioIndexTemplate(templateOptions)), writeFile(join(projectPath, 'README.md'), getSdkStdioReadmeTemplate(projectName, templateOptions)));
|
|
55
43
|
}
|
|
@@ -60,14 +48,12 @@ export async function generateProject(config) {
|
|
|
60
48
|
filesToWrite.push(writeFile(join(srcPath, 'auth.ts'), templates.getAuthTemplate()));
|
|
61
49
|
}
|
|
62
50
|
}
|
|
63
|
-
// server.ts only composes these; they are identical on both
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
writeFile(join(srcPath, 'notes-store.test.ts'), getSdkStoreTestTemplate()), writeFile(join(srcPath, 'server.test.ts'), getSdkServerTestTemplate()));
|
|
68
|
-
}
|
|
51
|
+
// server.ts only composes these; they are identical on both transports.
|
|
52
|
+
filesToWrite.push(writeFile(join(srcPath, 'tools.ts'), getSdkToolsTemplate()), writeFile(join(srcPath, 'prompts.ts'), getSdkPromptsTemplate()), writeFile(join(srcPath, 'resources.ts'), getSdkResourcesTemplate()), writeFile(join(srcPath, 'notes-store.ts'), getSdkStoreTemplate()),
|
|
53
|
+
// Two layers: the store in isolation, and the payload an agent reads.
|
|
54
|
+
writeFile(join(srcPath, 'notes-store.test.ts'), getSdkStoreTestTemplate()), writeFile(join(srcPath, 'server.test.ts'), getSdkServerTestTemplate()));
|
|
69
55
|
// Common files for all templates
|
|
70
|
-
filesToWrite.push(writeFile(join(projectPath, 'package.json'), getPackageJsonTemplate(projectName, templateOptions)), writeFile(join(projectPath, 'tsconfig.json'), getTsconfigTemplate(
|
|
56
|
+
filesToWrite.push(writeFile(join(projectPath, 'package.json'), getPackageJsonTemplate(projectName, templateOptions)), writeFile(join(projectPath, 'tsconfig.json'), getTsconfigTemplate()), writeFile(join(projectPath, '.gitignore'), getGitignoreTemplate()), writeFile(join(projectPath, '.env.example'), getEnvExampleTemplate(templateOptions)), writeFile(join(projectPath, 'AGENTS.md'), getAgentsMdTemplate(projectName, templateOptions)));
|
|
71
57
|
// Deployment files for HTTP transport only (stdio servers are not HTTP services)
|
|
72
58
|
if (transport === 'http') {
|
|
73
59
|
filesToWrite.push(writeFile(join(projectPath, 'Dockerfile'), getDockerfileTemplate(templateOptions)), writeFile(join(projectPath, '.dockerignore'), getDockerignoreTemplate()));
|
|
@@ -95,8 +81,7 @@ export async function generateProject(config) {
|
|
|
95
81
|
}
|
|
96
82
|
}
|
|
97
83
|
const commands = packageManagerCommands[packageManager];
|
|
98
|
-
|
|
99
|
-
console.log(`\nCreated ${projectName} with ${frameworkName} (${transport}) at ${projectPath}`);
|
|
84
|
+
console.log(`\nCreated ${projectName} with MCP SDK (${transport}) at ${projectPath}`);
|
|
100
85
|
console.log(`\nNext steps:`);
|
|
101
86
|
console.log(` cd ${projectName}`);
|
|
102
87
|
console.log(` ${commands.install}`);
|
|
@@ -7,19 +7,16 @@ import { SKILLS_UPDATE_COMMAND, SKILLS_INSTALL_HINT, SKILLS_DIR } from '../../sk
|
|
|
7
7
|
* someone changing it will otherwise get wrong.
|
|
8
8
|
*/
|
|
9
9
|
export function getAgentsMdTemplate(projectName, options) {
|
|
10
|
-
const framework = options?.framework ?? 'sdk';
|
|
11
10
|
const transport = options?.transport ?? 'http';
|
|
12
11
|
const withOAuth = options?.withOAuth ?? false;
|
|
13
12
|
const packageManager = options?.packageManager ?? 'npm';
|
|
14
|
-
const isSdk = framework === 'sdk';
|
|
15
13
|
const isStdio = transport === 'stdio';
|
|
16
14
|
const run = {
|
|
17
15
|
npm: { build: 'npm run build', test: 'npm test', dev: 'npm run dev' },
|
|
18
16
|
pnpm: { build: 'pnpm build', test: 'pnpm test', dev: 'pnpm dev' },
|
|
19
17
|
yarn: { build: 'yarn build', test: 'yarn test', dev: 'yarn dev' },
|
|
20
18
|
}[packageManager];
|
|
21
|
-
const layout =
|
|
22
|
-
? `- \`src/server.ts\` — creates the \`McpServer\` and registers the primitives. It
|
|
19
|
+
const layout = `- \`src/server.ts\` — creates the \`McpServer\` and registers the primitives. It
|
|
23
20
|
should stay a composition root; definitions do not belong here.
|
|
24
21
|
- \`src/tools.ts\`, \`src/prompts.ts\`, \`src/resources.ts\` — one file per MCP
|
|
25
22
|
primitive, each exporting a \`register*(server)\` function.
|
|
@@ -29,13 +26,8 @@ export function getAgentsMdTemplate(projectName, options) {
|
|
|
29
26
|
|
|
30
27
|
The project is generated with a small example so nothing starts empty. It is
|
|
31
28
|
meant to be replaced — delete it once your own tools exist. The guidance below
|
|
32
|
-
applies to whatever replaces it
|
|
33
|
-
|
|
34
|
-
- \`src/index.ts\` — transport startup.
|
|
35
|
-
|
|
36
|
-
The project is generated with a small example so nothing starts empty. It is
|
|
37
|
-
meant to be replaced — delete it once your own tools exist.`;
|
|
38
|
-
const perRequestSection = isSdk && !isStdio
|
|
29
|
+
applies to whatever replaces it.`;
|
|
30
|
+
const perRequestSection = !isStdio
|
|
39
31
|
? `
|
|
40
32
|
## State lives in the module, not the server
|
|
41
33
|
|
|
@@ -80,8 +72,7 @@ server misconfiguration and belongs in the 500 bucket.
|
|
|
80
72
|
line, not inside it.
|
|
81
73
|
`
|
|
82
74
|
: '';
|
|
83
|
-
const testingSection =
|
|
84
|
-
? `
|
|
75
|
+
const testingSection = `
|
|
85
76
|
## Adding a tool means adding a test
|
|
86
77
|
|
|
87
78
|
\`${run.test}\` runs two layers:
|
|
@@ -102,17 +93,8 @@ tests that exercise your data structures; those teach nothing about the tool.
|
|
|
102
93
|
|
|
103
94
|
Assert on the parsed payload rather than on internal calls. It is the surface the
|
|
104
95
|
agent sees, and it survives refactoring underneath.
|
|
105
|
-
`
|
|
106
|
-
: `
|
|
107
|
-
## Testing
|
|
108
|
-
|
|
109
|
-
This project ships without a test setup. If you add one, assert on the **payload
|
|
110
|
-
a tool returns** rather than on internal function calls — that is the surface an
|
|
111
|
-
agent reads, and a tool can be internally correct while returning something
|
|
112
|
-
misleading.
|
|
113
96
|
`;
|
|
114
|
-
const toolDesignSection =
|
|
115
|
-
? `
|
|
97
|
+
const toolDesignSection = `
|
|
116
98
|
## Writing a good tool
|
|
117
99
|
|
|
118
100
|
A tool is a contract with a non-deterministic caller. It cannot ask what you
|
|
@@ -156,8 +138,7 @@ The flat layout here suits a handful of tools. It is not meant to be permanent:
|
|
|
156
138
|
Whichever shape you land on, keep two things: \`server.ts\` stays a composition
|
|
157
139
|
root, and domain logic stays free of MCP imports so it remains testable on its
|
|
158
140
|
own.
|
|
159
|
-
|
|
160
|
-
: '';
|
|
141
|
+
`;
|
|
161
142
|
const skillSection = `
|
|
162
143
|
## The tool-design skill
|
|
163
144
|
|
|
@@ -179,8 +160,7 @@ is missing entirely, add it with \`${SKILLS_INSTALL_HINT}\`.
|
|
|
179
160
|
|
|
180
161
|
Commit \`${SKILLS_DIR}/\` so everyone working on this project gets the same copy.
|
|
181
162
|
`;
|
|
182
|
-
const conventions =
|
|
183
|
-
? `
|
|
163
|
+
const conventions = `
|
|
184
164
|
## Conventions worth keeping
|
|
185
165
|
|
|
186
166
|
- This project uses the **MCP TypeScript SDK v2** split packages
|
|
@@ -191,11 +171,10 @@ Commit \`${SKILLS_DIR}/\` so everyone working on this project gets the same copy
|
|
|
191
171
|
- A tool handler's second argument is \`ctx\` (\`ctx.mcpReq.signal\`,
|
|
192
172
|
\`ctx.http?.authInfo\`), not the v1 \`extra\`.
|
|
193
173
|
- Logging, sampling and roots are deprecated in v2 — avoid \`sendLoggingMessage\`.
|
|
194
|
-
|
|
195
|
-
: '';
|
|
174
|
+
`;
|
|
196
175
|
const commands = [
|
|
197
176
|
[run.dev, 'build and run'],
|
|
198
|
-
|
|
177
|
+
[run.test, 'run the tests'],
|
|
199
178
|
[run.build, 'type-check and compile'],
|
|
200
179
|
];
|
|
201
180
|
const commandWidth = Math.max(...commands.map(([cmd]) => cmd.length));
|