@agentailor/create-mcp-server 0.9.0 → 0.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 +13 -47
- package/dist/cli.d.ts +3 -4
- package/dist/cli.js +29 -16
- package/dist/cli.test.js +60 -67
- 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 +11 -39
- 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 +16 -29
- 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 +1 -12
- package/dist/templates/sdk/{stateless → http}/index.d.ts +2 -1
- package/dist/templates/sdk/{stateless → http}/index.js +2 -1
- package/dist/templates/sdk/{stateless → http}/templates.test.js +90 -1
- package/dist/templates/sdk/stdio/index.d.ts +6 -6
- package/dist/templates/sdk/stdio/index.js +6 -6
- package/dist/templates/sdk/stdio/server.d.ts +1 -1
- package/dist/templates/sdk/stdio/server.js +2 -2
- package/dist/templates/sdk/stdio/templates.test.js +2 -2
- package/package.json +1 -1
- package/dist/deprecations.d.ts +0 -7
- package/dist/deprecations.js +0 -17
- package/dist/deprecations.test.d.ts +0 -1
- package/dist/deprecations.test.js +0 -24
- 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.js +0 -66
- package/dist/templates/fastmcp/templates.test.js +0 -109
- package/dist/templates/sdk/stateful/index.d.ts +0 -11
- package/dist/templates/sdk/stateful/index.js +0 -12
- package/dist/templates/sdk/stateful/readme.d.ts +0 -1
- package/dist/templates/sdk/stateful/readme.js +0 -3
- package/dist/templates/sdk/stateful/server.d.ts +0 -1
- package/dist/templates/sdk/stateful/server.js +0 -2
- package/dist/templates/sdk/stateful/templates.test.d.ts +0 -1
- package/dist/templates/sdk/stateful/templates.test.js +0 -198
- package/dist/templates/sdk/stateless/server.d.ts +0 -1
- package/dist/templates/sdk/stateless/templates.test.d.ts +0 -1
- /package/dist/templates/sdk/{stateful → http}/auth.d.ts +0 -0
- /package/dist/templates/sdk/{stateful → http}/auth.js +0 -0
- /package/dist/templates/sdk/{stateful → http}/auth.test.d.ts +0 -0
- /package/dist/templates/sdk/{stateful → http}/auth.test.js +0 -0
- /package/dist/templates/sdk/{stateless → http}/prompts.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/prompts.js +0 -0
- /package/dist/templates/sdk/{stateless → http}/readme.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/readme.js +0 -0
- /package/dist/templates/sdk/{stateless → http}/resources.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/resources.js +0 -0
- /package/dist/templates/sdk/{stateless → http}/server-test.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/server-test.js +0 -0
- /package/dist/templates/{fastmcp → sdk/http}/server.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/server.js +0 -0
- /package/dist/templates/sdk/{stateless → http}/store-test.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/store-test.js +0 -0
- /package/dist/templates/sdk/{stateless → http}/store.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/store.js +0 -0
- /package/dist/templates/{fastmcp → sdk/http}/templates.test.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/tools.d.ts +0 -0
- /package/dist/templates/sdk/{stateless → http}/tools.js +0 -0
|
@@ -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));
|
|
@@ -2,16 +2,15 @@ import { describe, it, expect } from 'vitest';
|
|
|
2
2
|
import { getAgentsMdTemplate } from './agents.md.js';
|
|
3
3
|
describe('getAgentsMdTemplate', () => {
|
|
4
4
|
const projectName = 'test-project';
|
|
5
|
-
const sdkHttp = {
|
|
6
|
-
const sdkStdio = {
|
|
7
|
-
const fastmcp = { framework: 'fastmcp', transport: 'http' };
|
|
5
|
+
const sdkHttp = { transport: 'http' };
|
|
6
|
+
const sdkStdio = { transport: 'stdio' };
|
|
8
7
|
it('should title the document with the project name', () => {
|
|
9
8
|
expect(getAgentsMdTemplate(projectName, sdkHttp)).toContain(`# ${projectName}`);
|
|
10
9
|
});
|
|
11
10
|
// The shipped example is meant to be deleted once real tools exist, but
|
|
12
11
|
// AGENTS.md stays. Anything naming the example rots the moment it goes.
|
|
13
12
|
it('should not reference the shipped example', () => {
|
|
14
|
-
for (const options of [sdkHttp, sdkStdio
|
|
13
|
+
for (const options of [sdkHttp, sdkStdio]) {
|
|
15
14
|
const template = getAgentsMdTemplate(projectName, options);
|
|
16
15
|
expect(template).not.toContain('notes-store');
|
|
17
16
|
expect(template).not.toContain('list_notes');
|
|
@@ -21,7 +20,7 @@ describe('getAgentsMdTemplate', () => {
|
|
|
21
20
|
}
|
|
22
21
|
});
|
|
23
22
|
it('should say the example is meant to be replaced', () => {
|
|
24
|
-
for (const options of [sdkHttp,
|
|
23
|
+
for (const options of [sdkHttp, sdkStdio]) {
|
|
25
24
|
expect(getAgentsMdTemplate(projectName, options)).toContain('meant to be replaced');
|
|
26
25
|
}
|
|
27
26
|
});
|
|
@@ -84,12 +83,6 @@ describe('getAgentsMdTemplate', () => {
|
|
|
84
83
|
expect(template).toContain('not a quota to match');
|
|
85
84
|
expect(template).toContain('src/server.test.ts');
|
|
86
85
|
});
|
|
87
|
-
it('should not promise tests FastMCP projects do not ship', () => {
|
|
88
|
-
const template = getAgentsMdTemplate(projectName, fastmcp);
|
|
89
|
-
expect(template).toContain('ships without a test setup');
|
|
90
|
-
expect(template).not.toContain('src/server.test.ts');
|
|
91
|
-
expect(template).not.toContain('npm test');
|
|
92
|
-
});
|
|
93
86
|
});
|
|
94
87
|
describe('layout', () => {
|
|
95
88
|
it('should describe the split primitives for SDK projects', () => {
|
|
@@ -98,11 +91,6 @@ describe('getAgentsMdTemplate', () => {
|
|
|
98
91
|
expect(template).toContain('MCP imports');
|
|
99
92
|
expect(template).toContain('Keep that seam');
|
|
100
93
|
});
|
|
101
|
-
it('should describe the single-file layout for FastMCP projects', () => {
|
|
102
|
-
const template = getAgentsMdTemplate(projectName, fastmcp);
|
|
103
|
-
expect(template).toContain('the FastMCP server and its tools');
|
|
104
|
-
expect(template).not.toContain('src/tools.ts');
|
|
105
|
-
});
|
|
106
94
|
});
|
|
107
95
|
describe('commands', () => {
|
|
108
96
|
it('should use the selected package manager', () => {
|
|
@@ -111,11 +99,6 @@ describe('getAgentsMdTemplate', () => {
|
|
|
111
99
|
expect(template).toContain('yarn build');
|
|
112
100
|
expect(template).not.toContain('npm run');
|
|
113
101
|
});
|
|
114
|
-
it('should omit the test command for FastMCP projects', () => {
|
|
115
|
-
const template = getAgentsMdTemplate(projectName, fastmcp);
|
|
116
|
-
expect(template).toContain('npm run build');
|
|
117
|
-
expect(template).not.toContain('npm test');
|
|
118
|
-
});
|
|
119
102
|
});
|
|
120
103
|
describe('tool-design skill', () => {
|
|
121
104
|
it('should point at the installed skill and how to update it', () => {
|
|
@@ -4,13 +4,10 @@ export function getEnvExampleTemplate(options) {
|
|
|
4
4
|
return `# No environment variables required for stdio transport\n`;
|
|
5
5
|
}
|
|
6
6
|
const withOAuth = options?.withOAuth ?? false;
|
|
7
|
-
const
|
|
8
|
-
const allowedHostsVar = isSdk
|
|
9
|
-
? `
|
|
7
|
+
const allowedHostsVar = `
|
|
10
8
|
# Comma-separated list of additional allowed hosts (for deployment behind reverse proxies)
|
|
11
9
|
# ALLOWED_HOSTS=my-server.example.com,my-server.us-central1.run.app
|
|
12
|
-
|
|
13
|
-
: '';
|
|
10
|
+
`;
|
|
14
11
|
const oauthVars = withOAuth
|
|
15
12
|
? `
|
|
16
13
|
# OAuth Configuration
|
|
@@ -1,40 +1,25 @@
|
|
|
1
1
|
export function getPackageJsonTemplate(projectName, options) {
|
|
2
2
|
const withOAuth = options?.withOAuth ?? false;
|
|
3
|
-
const framework = options?.framework ?? 'sdk';
|
|
4
3
|
const transport = options?.transport ?? 'http';
|
|
5
|
-
// Tests ship with SDK projects only; FastMCP has no test setup yet.
|
|
6
|
-
const withTests = framework === 'sdk';
|
|
7
4
|
let dependencies;
|
|
8
5
|
let devDependencies;
|
|
9
6
|
const commonDevDependencies = {
|
|
10
7
|
typescript: '^7.0.2',
|
|
11
|
-
'@modelcontextprotocol/inspector': '^2.
|
|
12
|
-
'@types/node': '^26.6.
|
|
8
|
+
'@modelcontextprotocol/inspector': '^2.9.0',
|
|
9
|
+
'@types/node': '^26.6.4',
|
|
13
10
|
};
|
|
14
11
|
const zodDependency = { zod: '^4.6.5' };
|
|
15
|
-
const dotEnvDependency = { dotenv: '^18.0.
|
|
12
|
+
const dotEnvDependency = { dotenv: '^18.0.5' };
|
|
16
13
|
// The client drives the server over an in-memory transport in the generated
|
|
17
14
|
// tests, so it must track @modelcontextprotocol/server's major.
|
|
18
15
|
const testDevDependencies = {
|
|
19
|
-
vitest: '^5.0.
|
|
20
|
-
'@modelcontextprotocol/client': '^2.
|
|
16
|
+
vitest: '^5.0.3',
|
|
17
|
+
'@modelcontextprotocol/client': '^2.3.0',
|
|
21
18
|
};
|
|
22
|
-
if (
|
|
23
|
-
// FastMCP pulls in @modelcontextprotocol/sdk v1 itself, so this branch
|
|
24
|
-
// stays on v1 and must not gain the v2 packages.
|
|
25
|
-
dependencies = {
|
|
26
|
-
fastmcp: '^4.20.14',
|
|
27
|
-
...zodDependency,
|
|
28
|
-
...dotEnvDependency,
|
|
29
|
-
};
|
|
30
|
-
devDependencies = {
|
|
31
|
-
...commonDevDependencies,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
else if (transport === 'stdio') {
|
|
19
|
+
if (transport === 'stdio') {
|
|
35
20
|
// Official SDK v2 stdio - no express needed
|
|
36
21
|
dependencies = {
|
|
37
|
-
'@modelcontextprotocol/server': '^2.
|
|
22
|
+
'@modelcontextprotocol/server': '^2.3.0',
|
|
38
23
|
...zodDependency,
|
|
39
24
|
...dotEnvDependency,
|
|
40
25
|
};
|
|
@@ -47,11 +32,11 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
47
32
|
// hono is a peer dependency of @modelcontextprotocol/node, so the generated
|
|
48
33
|
// project must declare it even though no template code imports it.
|
|
49
34
|
dependencies = {
|
|
50
|
-
'@modelcontextprotocol/server': '^2.
|
|
51
|
-
'@modelcontextprotocol/express': '^2.0.
|
|
52
|
-
'@modelcontextprotocol/node': '^2.
|
|
35
|
+
'@modelcontextprotocol/server': '^2.3.0',
|
|
36
|
+
'@modelcontextprotocol/express': '^2.0.2',
|
|
37
|
+
'@modelcontextprotocol/node': '^2.1.1',
|
|
53
38
|
express: '^5.2.1',
|
|
54
|
-
hono: '^4.13.
|
|
39
|
+
hono: '^4.13.13',
|
|
55
40
|
...zodDependency,
|
|
56
41
|
...dotEnvDependency,
|
|
57
42
|
};
|
|
@@ -80,14 +65,16 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
80
65
|
build: 'tsc',
|
|
81
66
|
dev: 'tsc && node dist/index.js',
|
|
82
67
|
start: 'node dist/index.js',
|
|
83
|
-
|
|
68
|
+
test: 'vitest run',
|
|
69
|
+
'test:watch': 'vitest',
|
|
84
70
|
...inspectScripts,
|
|
85
71
|
},
|
|
86
72
|
dependencies,
|
|
87
73
|
devDependencies,
|
|
88
74
|
engines: {
|
|
89
|
-
// Floor set by @modelcontextprotocol/inspector, which requires >=22.19.0
|
|
90
|
-
// The SDK v2 packages
|
|
75
|
+
// Floor set by @modelcontextprotocol/inspector, which requires >=22.19.0
|
|
76
|
+
// (vitest 5 alone needs ^22.12.0). The SDK v2 packages only need >=20.
|
|
77
|
+
// Node 20 is end-of-life, so this floor costs no supported user anything.
|
|
91
78
|
node: '>=22.19.0',
|
|
92
79
|
},
|
|
93
80
|
};
|
|
@@ -31,44 +31,18 @@ describe('common templates', () => {
|
|
|
31
31
|
const pkg = JSON.parse(template);
|
|
32
32
|
expect(pkg.dependencies['dotenv']).toBeDefined();
|
|
33
33
|
});
|
|
34
|
-
it('should use FastMCP package when framework is fastmcp', () => {
|
|
35
|
-
const template = getPackageJsonTemplate(projectName, { framework: 'fastmcp' });
|
|
36
|
-
const pkg = JSON.parse(template);
|
|
37
|
-
expect(pkg.dependencies['fastmcp']).toBeDefined();
|
|
38
|
-
// FastMCP depends on the v1 SDK transitively, never directly
|
|
39
|
-
expect(pkg.dependencies['@modelcontextprotocol/sdk']).toBeUndefined();
|
|
40
|
-
expect(pkg.dependencies['express']).toBeUndefined();
|
|
41
|
-
});
|
|
42
|
-
it('should NOT pull SDK v2 packages into FastMCP projects', () => {
|
|
43
|
-
const template = getPackageJsonTemplate(projectName, { framework: 'fastmcp' });
|
|
44
|
-
const pkg = JSON.parse(template);
|
|
45
|
-
expect(pkg.dependencies['@modelcontextprotocol/server']).toBeUndefined();
|
|
46
|
-
expect(pkg.dependencies['@modelcontextprotocol/express']).toBeUndefined();
|
|
47
|
-
expect(pkg.dependencies['@modelcontextprotocol/node']).toBeUndefined();
|
|
48
|
-
});
|
|
49
|
-
it('should include dotenv for FastMCP', () => {
|
|
50
|
-
const template = getPackageJsonTemplate(projectName, { framework: 'fastmcp' });
|
|
51
|
-
const pkg = JSON.parse(template);
|
|
52
|
-
expect(pkg.dependencies['dotenv']).toBeDefined();
|
|
53
|
-
});
|
|
54
34
|
it('should include jose dependency when withOAuth is true for SDK', () => {
|
|
55
|
-
const template = getPackageJsonTemplate(projectName, {
|
|
35
|
+
const template = getPackageJsonTemplate(projectName, { withOAuth: true });
|
|
56
36
|
const pkg = JSON.parse(template);
|
|
57
37
|
expect(pkg.dependencies['jose']).toBeDefined();
|
|
58
38
|
});
|
|
59
|
-
it('should not include @types/express for FastMCP', () => {
|
|
60
|
-
const template = getPackageJsonTemplate(projectName, { framework: 'fastmcp' });
|
|
61
|
-
const pkg = JSON.parse(template);
|
|
62
|
-
expect(pkg.devDependencies['@types/express']).toBeUndefined();
|
|
63
|
-
});
|
|
64
39
|
it('should include @types/express for SDK', () => {
|
|
65
|
-
const template = getPackageJsonTemplate(projectName, {
|
|
40
|
+
const template = getPackageJsonTemplate(projectName, {});
|
|
66
41
|
const pkg = JSON.parse(template);
|
|
67
42
|
expect(pkg.devDependencies['@types/express']).toBeDefined();
|
|
68
43
|
});
|
|
69
44
|
it('should NOT include express or @types/express for SDK stdio', () => {
|
|
70
45
|
const template = getPackageJsonTemplate(projectName, {
|
|
71
|
-
framework: 'sdk',
|
|
72
46
|
transport: 'stdio',
|
|
73
47
|
});
|
|
74
48
|
const pkg = JSON.parse(template);
|
|
@@ -81,7 +55,6 @@ describe('common templates', () => {
|
|
|
81
55
|
});
|
|
82
56
|
it('should use inspect:tools, inspect:prompts, inspect:resources scripts for stdio transport', () => {
|
|
83
57
|
const template = getPackageJsonTemplate(projectName, {
|
|
84
|
-
framework: 'sdk',
|
|
85
58
|
transport: 'stdio',
|
|
86
59
|
});
|
|
87
60
|
const pkg = JSON.parse(template);
|
|
@@ -91,18 +64,14 @@ describe('common templates', () => {
|
|
|
91
64
|
expect(pkg.scripts['inspect']).toBeUndefined();
|
|
92
65
|
});
|
|
93
66
|
it('should use http inspect script for http transport (default)', () => {
|
|
94
|
-
const template = getPackageJsonTemplate(projectName, {
|
|
67
|
+
const template = getPackageJsonTemplate(projectName, { transport: 'http' });
|
|
95
68
|
const pkg = JSON.parse(template);
|
|
96
69
|
expect(pkg.scripts.inspect).toContain('http://localhost:3000/mcp');
|
|
97
70
|
});
|
|
98
71
|
// The inspector devDependency requires >=22.19.0; a lower floor makes npm
|
|
99
72
|
// emit an EBADENGINE warning on install.
|
|
100
73
|
it('should declare a node engine satisfying the inspector requirement', () => {
|
|
101
|
-
for (const options of [
|
|
102
|
-
{ framework: 'sdk', transport: 'http' },
|
|
103
|
-
{ framework: 'sdk', transport: 'stdio' },
|
|
104
|
-
{ framework: 'fastmcp' },
|
|
105
|
-
]) {
|
|
74
|
+
for (const options of [{ transport: 'http' }, { transport: 'stdio' }]) {
|
|
106
75
|
const pkg = JSON.parse(getPackageJsonTemplate(projectName, options));
|
|
107
76
|
expect(pkg.engines.node).toBe('>=22.19.0');
|
|
108
77
|
}
|
|
@@ -124,6 +93,10 @@ describe('common templates', () => {
|
|
|
124
93
|
const template = getTsconfigTemplate();
|
|
125
94
|
expect(() => JSON.parse(template)).not.toThrow();
|
|
126
95
|
});
|
|
96
|
+
it('should keep test files out of the build', () => {
|
|
97
|
+
const config = JSON.parse(getTsconfigTemplate());
|
|
98
|
+
expect(config.exclude).toContain('src/**/*.test.ts');
|
|
99
|
+
});
|
|
127
100
|
it('should target ES2022 with NodeNext modules', () => {
|
|
128
101
|
const template = getTsconfigTemplate();
|
|
129
102
|
const config = JSON.parse(template);
|
|
@@ -147,18 +120,10 @@ describe('common templates', () => {
|
|
|
147
120
|
const template = getEnvExampleTemplate();
|
|
148
121
|
expect(template).toContain('PORT=');
|
|
149
122
|
});
|
|
150
|
-
it('should include ALLOWED_HOSTS hint for
|
|
151
|
-
const template = getEnvExampleTemplate({ framework: 'sdk' });
|
|
152
|
-
expect(template).toContain('ALLOWED_HOSTS');
|
|
153
|
-
});
|
|
154
|
-
it('should include ALLOWED_HOSTS hint by default (no framework specified)', () => {
|
|
123
|
+
it('should include ALLOWED_HOSTS hint for HTTP transport', () => {
|
|
155
124
|
const template = getEnvExampleTemplate();
|
|
156
125
|
expect(template).toContain('ALLOWED_HOSTS');
|
|
157
126
|
});
|
|
158
|
-
it('should NOT include ALLOWED_HOSTS for FastMCP framework', () => {
|
|
159
|
-
const template = getEnvExampleTemplate({ framework: 'fastmcp' });
|
|
160
|
-
expect(template).not.toContain('ALLOWED_HOSTS');
|
|
161
|
-
});
|
|
162
127
|
it('should NOT include PORT for stdio transport', () => {
|
|
163
128
|
const template = getEnvExampleTemplate({ transport: 'stdio' });
|
|
164
129
|
expect(template).not.toContain('PORT=');
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
export function getTsconfigTemplate(
|
|
2
|
-
const withTests = options?.withTests ?? false;
|
|
1
|
+
export function getTsconfigTemplate() {
|
|
3
2
|
// Test files are type-checked by the editor and by vitest, but kept out of
|
|
4
3
|
// the build so they never reach dist/ or the production Docker image.
|
|
5
|
-
const exclude =
|
|
6
|
-
? ['node_modules', 'dist', 'src/**/*.test.ts']
|
|
7
|
-
: ['node_modules', 'dist'];
|
|
4
|
+
const exclude = ['node_modules', 'dist', 'src/**/*.test.ts'];
|
|
8
5
|
const tsconfig = {
|
|
9
6
|
compilerOptions: {
|
|
10
7
|
target: 'ES2022',
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export type PackageManager = 'npm' | 'pnpm' | 'yarn';
|
|
2
|
-
export type Framework = 'sdk' | 'fastmcp';
|
|
3
2
|
export type TransportType = 'http' | 'stdio';
|
|
4
3
|
/**
|
|
5
4
|
* Base template options shared across all templates
|
|
@@ -8,26 +7,16 @@ export interface BaseTemplateOptions {
|
|
|
8
7
|
packageManager?: PackageManager;
|
|
9
8
|
}
|
|
10
9
|
/**
|
|
11
|
-
* Template options for SDK templates (
|
|
10
|
+
* Template options for SDK templates (http and stdio)
|
|
12
11
|
*/
|
|
13
12
|
export interface SdkTemplateOptions extends BaseTemplateOptions {
|
|
14
13
|
withOAuth?: boolean;
|
|
15
14
|
transport?: TransportType;
|
|
16
15
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Template options for FastMCP templates
|
|
19
|
-
*/
|
|
20
|
-
export interface FastMCPTemplateOptions extends BaseTemplateOptions {
|
|
21
|
-
stateless?: boolean;
|
|
22
|
-
transport?: TransportType;
|
|
23
|
-
}
|
|
24
16
|
/**
|
|
25
17
|
* Template options for common templates (package.json, env.example)
|
|
26
|
-
* Includes all options since these are used across all frameworks
|
|
27
18
|
*/
|
|
28
19
|
export interface CommonTemplateOptions extends BaseTemplateOptions {
|
|
29
20
|
withOAuth?: boolean;
|
|
30
|
-
framework?: Framework;
|
|
31
|
-
stateless?: boolean;
|
|
32
21
|
transport?: TransportType;
|
|
33
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { SdkTemplateOptions as TemplateOptions } from '../../common/types.js';
|
|
2
2
|
import type { SdkTemplateOptions } from '../../common/types.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* HTTP entrypoint template.
|
|
5
5
|
* Varies only by `options.withOAuth`.
|
|
6
6
|
*/
|
|
7
7
|
export declare function getIndexTemplate(options?: SdkTemplateOptions): string;
|
|
@@ -13,3 +13,4 @@ export { getPromptsTemplate } from './prompts.js';
|
|
|
13
13
|
export { getResourcesTemplate } from './resources.js';
|
|
14
14
|
export { getStoreTestTemplate } from './store-test.js';
|
|
15
15
|
export { getServerTestTemplate } from './server-test.js';
|
|
16
|
+
export { getAuthTemplate } from './auth.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* HTTP entrypoint template.
|
|
3
3
|
* Varies only by `options.withOAuth`.
|
|
4
4
|
*/
|
|
5
5
|
export function getIndexTemplate(options) {
|
|
@@ -99,3 +99,4 @@ export { getPromptsTemplate } from './prompts.js';
|
|
|
99
99
|
export { getResourcesTemplate } from './resources.js';
|
|
100
100
|
export { getStoreTestTemplate } from './store-test.js';
|
|
101
101
|
export { getServerTestTemplate } from './server-test.js';
|
|
102
|
+
export { getAuthTemplate } from './auth.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { getServerTemplate, getIndexTemplate, getReadmeTemplate, getStoreTemplate, getToolsTemplate, getPromptsTemplate, getResourcesTemplate, getStoreTestTemplate, getServerTestTemplate, } from './index.js';
|
|
3
|
-
describe('sdk/
|
|
3
|
+
describe('sdk/http templates', () => {
|
|
4
4
|
const projectName = 'test-project';
|
|
5
5
|
describe('getServerTemplate', () => {
|
|
6
6
|
it('should include project name in server config', () => {
|
|
@@ -284,4 +284,93 @@ describe('sdk/stateless templates', () => {
|
|
|
284
284
|
}
|
|
285
285
|
});
|
|
286
286
|
});
|
|
287
|
+
describe('getIndexTemplate with OAuth', () => {
|
|
288
|
+
it('should include auth imports when OAuth enabled', () => {
|
|
289
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
290
|
+
expect(template).toContain("from './auth.js'");
|
|
291
|
+
expect(template).toContain('setupAuthMetadataRouter');
|
|
292
|
+
expect(template).toContain('authMiddleware');
|
|
293
|
+
expect(template).toContain('getOAuthMetadataUrl');
|
|
294
|
+
});
|
|
295
|
+
it('should import validateOAuthConfig when OAuth enabled', () => {
|
|
296
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
297
|
+
expect(template).toContain('validateOAuthConfig');
|
|
298
|
+
});
|
|
299
|
+
it('should setup auth metadata router when OAuth enabled', () => {
|
|
300
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
301
|
+
expect(template).toContain('setupAuthMetadataRouter(app)');
|
|
302
|
+
});
|
|
303
|
+
it('should apply auth middleware to the /mcp route when OAuth enabled', () => {
|
|
304
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
305
|
+
expect(template).toContain("app.all('/mcp', authMiddleware,");
|
|
306
|
+
});
|
|
307
|
+
it('should log OAuth metadata URL on startup when OAuth enabled', () => {
|
|
308
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
309
|
+
expect(template).toContain('getOAuthMetadataUrl()');
|
|
310
|
+
});
|
|
311
|
+
it('should call validateOAuthConfig before starting server when OAuth enabled', () => {
|
|
312
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
313
|
+
expect(template).toContain('await validateOAuthConfig()');
|
|
314
|
+
});
|
|
315
|
+
it('should wrap server startup in async main function when OAuth enabled', () => {
|
|
316
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
317
|
+
expect(template).toContain('async function main()');
|
|
318
|
+
expect(template).toContain('main().catch');
|
|
319
|
+
});
|
|
320
|
+
it('should exit with error if OAuth validation fails', () => {
|
|
321
|
+
const template = getIndexTemplate({ withOAuth: true });
|
|
322
|
+
expect(template).toContain('Failed to start server');
|
|
323
|
+
expect(template).toContain('process.exit(1)');
|
|
324
|
+
});
|
|
325
|
+
it('should NOT include auth imports when OAuth disabled', () => {
|
|
326
|
+
const template = getIndexTemplate({ withOAuth: false });
|
|
327
|
+
expect(template).not.toContain("from './auth.js'");
|
|
328
|
+
expect(template).not.toContain('authMiddleware');
|
|
329
|
+
});
|
|
330
|
+
it('should NOT include auth imports by default', () => {
|
|
331
|
+
const template = getIndexTemplate();
|
|
332
|
+
expect(template).not.toContain("from './auth.js'");
|
|
333
|
+
});
|
|
334
|
+
it('should NOT wrap in async main when OAuth disabled', () => {
|
|
335
|
+
const template = getIndexTemplate({ withOAuth: false });
|
|
336
|
+
expect(template).not.toContain('async function main()');
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
describe('getReadmeTemplate with OAuth', () => {
|
|
340
|
+
it('should include OAuth section when enabled', () => {
|
|
341
|
+
const template = getReadmeTemplate(projectName, { withOAuth: true });
|
|
342
|
+
expect(template).toContain('## OAuth Authentication');
|
|
343
|
+
expect(template).toContain('OAUTH_ISSUER_URL');
|
|
344
|
+
expect(template).toContain('OAUTH_AUDIENCE');
|
|
345
|
+
expect(template).toContain('Bearer token');
|
|
346
|
+
});
|
|
347
|
+
it('should list supported OAuth providers', () => {
|
|
348
|
+
const template = getReadmeTemplate(projectName, { withOAuth: true });
|
|
349
|
+
expect(template).toContain('Auth0');
|
|
350
|
+
expect(template).toContain('Keycloak');
|
|
351
|
+
expect(template).toContain('Azure AD');
|
|
352
|
+
expect(template).toContain('Okta');
|
|
353
|
+
});
|
|
354
|
+
it('should document JWKS-based JWT validation', () => {
|
|
355
|
+
const template = getReadmeTemplate(projectName, { withOAuth: true });
|
|
356
|
+
expect(template).toContain('JWT');
|
|
357
|
+
expect(template).toContain('.well-known/jwks.json');
|
|
358
|
+
});
|
|
359
|
+
it('should document where auth info surfaces to handlers', () => {
|
|
360
|
+
const template = getReadmeTemplate(projectName, { withOAuth: true });
|
|
361
|
+
expect(template).toContain('ctx.http.authInfo');
|
|
362
|
+
});
|
|
363
|
+
it('should include auth.ts in project structure when OAuth enabled', () => {
|
|
364
|
+
const template = getReadmeTemplate(projectName, { withOAuth: true });
|
|
365
|
+
expect(template).toContain('auth.ts');
|
|
366
|
+
});
|
|
367
|
+
it('should NOT include OAuth section when disabled', () => {
|
|
368
|
+
const template = getReadmeTemplate(projectName, { withOAuth: false });
|
|
369
|
+
expect(template).not.toContain('## OAuth Authentication');
|
|
370
|
+
});
|
|
371
|
+
it('should NOT include OAuth section by default', () => {
|
|
372
|
+
const template = getReadmeTemplate(projectName);
|
|
373
|
+
expect(template).not.toContain('## OAuth Authentication');
|
|
374
|
+
});
|
|
375
|
+
});
|
|
287
376
|
});
|
|
@@ -3,9 +3,9 @@ import type { SdkTemplateOptions } from '../../common/types.js';
|
|
|
3
3
|
export declare function getIndexTemplate(_options?: SdkTemplateOptions): string;
|
|
4
4
|
export { getServerTemplate } from './server.js';
|
|
5
5
|
export { getReadmeTemplate } from './readme.js';
|
|
6
|
-
export { getStoreTemplate } from '../
|
|
7
|
-
export { getToolsTemplate } from '../
|
|
8
|
-
export { getPromptsTemplate } from '../
|
|
9
|
-
export { getResourcesTemplate } from '../
|
|
10
|
-
export { getStoreTestTemplate } from '../
|
|
11
|
-
export { getServerTestTemplate } from '../
|
|
6
|
+
export { getStoreTemplate } from '../http/store.js';
|
|
7
|
+
export { getToolsTemplate } from '../http/tools.js';
|
|
8
|
+
export { getPromptsTemplate } from '../http/prompts.js';
|
|
9
|
+
export { getResourcesTemplate } from '../http/resources.js';
|
|
10
|
+
export { getStoreTestTemplate } from '../http/store-test.js';
|
|
11
|
+
export { getServerTestTemplate } from '../http/server-test.js';
|
|
@@ -12,9 +12,9 @@ console.error('MCP Server running on stdio');
|
|
|
12
12
|
}
|
|
13
13
|
export { getServerTemplate } from './server.js';
|
|
14
14
|
export { getReadmeTemplate } from './readme.js';
|
|
15
|
-
export { getStoreTemplate } from '../
|
|
16
|
-
export { getToolsTemplate } from '../
|
|
17
|
-
export { getPromptsTemplate } from '../
|
|
18
|
-
export { getResourcesTemplate } from '../
|
|
19
|
-
export { getStoreTestTemplate } from '../
|
|
20
|
-
export { getServerTestTemplate } from '../
|
|
15
|
+
export { getStoreTemplate } from '../http/store.js';
|
|
16
|
+
export { getToolsTemplate } from '../http/tools.js';
|
|
17
|
+
export { getPromptsTemplate } from '../http/prompts.js';
|
|
18
|
+
export { getResourcesTemplate } from '../http/resources.js';
|
|
19
|
+
export { getStoreTestTemplate } from '../http/store-test.js';
|
|
20
|
+
export { getServerTestTemplate } from '../http/server-test.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getServerTemplate } from '../
|
|
1
|
+
export { getServerTemplate } from '../http/server.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Re-export from
|
|
2
|
-
export { getServerTemplate } from '../
|
|
1
|
+
// Re-export from the HTTP template - server logic is identical for stdio
|
|
2
|
+
export { getServerTemplate } from '../http/server.js';
|
|
@@ -12,8 +12,8 @@ describe('sdk/stdio templates', () => {
|
|
|
12
12
|
expect(template).toContain("from '@modelcontextprotocol/server'");
|
|
13
13
|
expect(template).not.toContain('@modelcontextprotocol/sdk');
|
|
14
14
|
});
|
|
15
|
-
// The server is re-exported from
|
|
16
|
-
// same composition arrives here - its detail is tested in
|
|
15
|
+
// The server is re-exported from http/, so this only checks that the
|
|
16
|
+
// same composition arrives here - its detail is tested in http/.
|
|
17
17
|
it('should compose the shared primitives', () => {
|
|
18
18
|
const template = getServerTemplate(projectName);
|
|
19
19
|
expect(template).toContain('registerTools(server)');
|
package/package.json
CHANGED
package/dist/deprecations.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Framework } from './templates/common/types.js';
|
|
2
|
-
export declare const FASTMCP_DEPRECATION_WARNING: string;
|
|
3
|
-
/**
|
|
4
|
-
* Prints a deprecation warning for the chosen framework, if it has one.
|
|
5
|
-
* Writes to stderr so it never mixes with output a script might parse.
|
|
6
|
-
*/
|
|
7
|
-
export declare function warnIfDeprecated(framework: Framework): void;
|
package/dist/deprecations.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// FastMCP is still on SDK v1 and the 2025-era protocol, and generated FastMCP
|
|
2
|
-
// projects ship without tests. It still works, but is on its way out.
|
|
3
|
-
export const FASTMCP_DEPRECATION_WARNING = [
|
|
4
|
-
'Warning: the FastMCP framework is deprecated and will be removed in a future release.',
|
|
5
|
-
'FastMCP projects stay on MCP SDK v1 and ship without tests. New projects should use',
|
|
6
|
-
'the default Official MCP SDK (--framework=sdk). Pin @agentailor/create-mcp-server@0.9',
|
|
7
|
-
'if you need to keep scaffolding FastMCP projects after it is removed.',
|
|
8
|
-
].join('\n ');
|
|
9
|
-
/**
|
|
10
|
-
* Prints a deprecation warning for the chosen framework, if it has one.
|
|
11
|
-
* Writes to stderr so it never mixes with output a script might parse.
|
|
12
|
-
*/
|
|
13
|
-
export function warnIfDeprecated(framework) {
|
|
14
|
-
if (framework === 'fastmcp') {
|
|
15
|
-
console.warn(`\n ${FASTMCP_DEPRECATION_WARNING}\n`);
|
|
16
|
-
}
|
|
17
|
-
}
|