@agentailor/create-mcp-server 0.5.1 → 0.5.3
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/templates/common/env.example.js +8 -1
- package/dist/templates/common/package.json.js +6 -6
- package/dist/templates/common/templates.test.js +12 -0
- package/dist/templates/sdk/stateful/index.js +7 -2
- package/dist/templates/sdk/stateful/readme.js +1 -1
- package/dist/templates/sdk/stateful/templates.test.js +7 -2
- package/dist/templates/sdk/stateless/index.js +5 -1
- package/dist/templates/sdk/stateless/readme.js +1 -1
- package/dist/templates/sdk/stateless/templates.test.js +7 -2
- package/package.json +1 -1
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export function getEnvExampleTemplate(options) {
|
|
2
2
|
const withOAuth = options?.withOAuth ?? false;
|
|
3
|
+
const isSdk = options?.framework === 'sdk' || !options?.framework;
|
|
4
|
+
const allowedHostsVar = isSdk
|
|
5
|
+
? `
|
|
6
|
+
# Comma-separated list of additional allowed hosts (for deployment behind reverse proxies)
|
|
7
|
+
# ALLOWED_HOSTS=my-server.example.com,my-server.us-central1.run.app
|
|
8
|
+
`
|
|
9
|
+
: '';
|
|
3
10
|
const oauthVars = withOAuth
|
|
4
11
|
? `
|
|
5
12
|
# OAuth Configuration
|
|
@@ -15,5 +22,5 @@ OAUTH_AUDIENCE=https://your-mcp-server.com
|
|
|
15
22
|
`
|
|
16
23
|
: '';
|
|
17
24
|
return `PORT=3000
|
|
18
|
-
${oauthVars}`;
|
|
25
|
+
${allowedHostsVar}${oauthVars}`;
|
|
19
26
|
}
|
|
@@ -5,15 +5,15 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
5
5
|
let devDependencies;
|
|
6
6
|
const commonDevDependencies = {
|
|
7
7
|
typescript: '^5.9.3',
|
|
8
|
-
'@modelcontextprotocol/inspector': '^0.
|
|
9
|
-
'@types/node': '^25.0
|
|
8
|
+
'@modelcontextprotocol/inspector': '^0.20.0',
|
|
9
|
+
'@types/node': '^25.3.0',
|
|
10
10
|
};
|
|
11
|
-
const zodDependency = { zod: '^4.3.
|
|
12
|
-
const dotEnvDependency = { dotenv: '^17.
|
|
11
|
+
const zodDependency = { zod: '^4.3.6' };
|
|
12
|
+
const dotEnvDependency = { dotenv: '^17.3.1' };
|
|
13
13
|
if (framework === 'fastmcp') {
|
|
14
14
|
// FastMCP dependencies - simpler setup
|
|
15
15
|
dependencies = {
|
|
16
|
-
fastmcp: '^3.
|
|
16
|
+
fastmcp: '^3.33.0',
|
|
17
17
|
...zodDependency,
|
|
18
18
|
...dotEnvDependency,
|
|
19
19
|
};
|
|
@@ -24,7 +24,7 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
24
24
|
else {
|
|
25
25
|
// Official SDK dependencies
|
|
26
26
|
dependencies = {
|
|
27
|
-
'@modelcontextprotocol/sdk': '^1.
|
|
27
|
+
'@modelcontextprotocol/sdk': '^1.26.0',
|
|
28
28
|
express: '^5.2.1',
|
|
29
29
|
...zodDependency,
|
|
30
30
|
...dotEnvDependency,
|
|
@@ -89,5 +89,17 @@ describe('common templates', () => {
|
|
|
89
89
|
const template = getEnvExampleTemplate();
|
|
90
90
|
expect(template).toContain('PORT=');
|
|
91
91
|
});
|
|
92
|
+
it('should include ALLOWED_HOSTS hint for SDK framework', () => {
|
|
93
|
+
const template = getEnvExampleTemplate({ framework: 'sdk' });
|
|
94
|
+
expect(template).toContain('ALLOWED_HOSTS');
|
|
95
|
+
});
|
|
96
|
+
it('should include ALLOWED_HOSTS hint by default (no framework specified)', () => {
|
|
97
|
+
const template = getEnvExampleTemplate();
|
|
98
|
+
expect(template).toContain('ALLOWED_HOSTS');
|
|
99
|
+
});
|
|
100
|
+
it('should NOT include ALLOWED_HOSTS for FastMCP framework', () => {
|
|
101
|
+
const template = getEnvExampleTemplate({ framework: 'fastmcp' });
|
|
102
|
+
expect(template).not.toContain('ALLOWED_HOSTS');
|
|
103
|
+
});
|
|
92
104
|
});
|
|
93
105
|
});
|
|
@@ -14,13 +14,18 @@ import {
|
|
|
14
14
|
getOAuthMetadataUrl,
|
|
15
15
|
validateOAuthConfig,
|
|
16
16
|
} from './auth.js';`
|
|
17
|
-
: `import
|
|
17
|
+
: `import 'dotenv/config';
|
|
18
|
+
import { type Request, type Response } from 'express';
|
|
18
19
|
import { randomUUID } from 'node:crypto';
|
|
19
20
|
import { createMcpExpressApp } from '@modelcontextprotocol/sdk/server/express.js';
|
|
20
21
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
21
22
|
import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
22
23
|
import { getServer } from './server.js';`;
|
|
23
|
-
const appSetup = `const
|
|
24
|
+
const appSetup = `const allowedHosts = process.env.ALLOWED_HOSTS?.split(',') ?? [];
|
|
25
|
+
|
|
26
|
+
const app = createMcpExpressApp({
|
|
27
|
+
allowedHosts: ['localhost', '127.0.0.1', '[::1]', ...allowedHosts],
|
|
28
|
+
});
|
|
24
29
|
|
|
25
30
|
// Health check endpoint for container orchestration
|
|
26
31
|
app.get('/health', (_, res) => res.sendStatus(200));`;
|
|
@@ -133,7 +133,7 @@ ${commands.build}
|
|
|
133
133
|
${commands.start}
|
|
134
134
|
\`\`\`
|
|
135
135
|
|
|
136
|
-
The server will start on port 3000 by default. You can change this by setting the \`PORT\` environment variable.
|
|
136
|
+
The server will start on port 3000 by default. You can change this by setting the \`PORT\` environment variable. To allow additional hosts (e.g. when deploying behind a reverse proxy), set \`ALLOWED_HOSTS\` as a comma-separated list.
|
|
137
137
|
|
|
138
138
|
## Testing with MCP Inspector
|
|
139
139
|
|
|
@@ -36,7 +36,7 @@ describe('sdk/stateful templates', () => {
|
|
|
36
36
|
it('should use createMcpExpressApp', () => {
|
|
37
37
|
const template = getIndexTemplate();
|
|
38
38
|
expect(template).toContain('createMcpExpressApp');
|
|
39
|
-
expect(template).toContain('const app = createMcpExpressApp(
|
|
39
|
+
expect(template).toContain('const app = createMcpExpressApp({');
|
|
40
40
|
});
|
|
41
41
|
it('should configure /mcp endpoint', () => {
|
|
42
42
|
const template = getIndexTemplate();
|
|
@@ -46,7 +46,12 @@ describe('sdk/stateful templates', () => {
|
|
|
46
46
|
});
|
|
47
47
|
it('should use PORT from environment variable', () => {
|
|
48
48
|
const template = getIndexTemplate();
|
|
49
|
-
expect(template).toContain('process.env.PORT
|
|
49
|
+
expect(template).toContain('process.env.PORT');
|
|
50
|
+
});
|
|
51
|
+
it('should pass allowedHosts to createMcpExpressApp', () => {
|
|
52
|
+
const template = getIndexTemplate();
|
|
53
|
+
expect(template).toContain('allowedHosts');
|
|
54
|
+
expect(template).toContain("ALLOWED_HOSTS?.split(',')");
|
|
50
55
|
});
|
|
51
56
|
// Stateful-specific tests
|
|
52
57
|
it('should use session ID header', () => {
|
|
@@ -7,7 +7,11 @@ import { createMcpExpressApp } from '@modelcontextprotocol/sdk/server/express.js
|
|
|
7
7
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
8
8
|
import { getServer } from './server.js';
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const allowedHosts = process.env.ALLOWED_HOSTS?.split(',') ?? [];
|
|
11
|
+
|
|
12
|
+
const app = createMcpExpressApp({
|
|
13
|
+
allowedHosts: ['localhost', '127.0.0.1', '[::1]', ...allowedHosts],
|
|
14
|
+
});
|
|
11
15
|
|
|
12
16
|
// Health check endpoint for container orchestration
|
|
13
17
|
app.get('/health', (_, res) => res.sendStatus(200));
|
|
@@ -45,7 +45,7 @@ ${commands.build}
|
|
|
45
45
|
${commands.start}
|
|
46
46
|
\`\`\`
|
|
47
47
|
|
|
48
|
-
The server will start on port 3000 by default. You can change this by setting the \`PORT\` environment variable.
|
|
48
|
+
The server will start on port 3000 by default. You can change this by setting the \`PORT\` environment variable. To allow additional hosts (e.g. when deploying behind a reverse proxy), set \`ALLOWED_HOSTS\` as a comma-separated list.
|
|
49
49
|
|
|
50
50
|
## Testing with MCP Inspector
|
|
51
51
|
|
|
@@ -36,7 +36,7 @@ describe('sdk/stateless templates', () => {
|
|
|
36
36
|
it('should use createMcpExpressApp', () => {
|
|
37
37
|
const template = getIndexTemplate();
|
|
38
38
|
expect(template).toContain('createMcpExpressApp');
|
|
39
|
-
expect(template).toContain('const app = createMcpExpressApp(
|
|
39
|
+
expect(template).toContain('const app = createMcpExpressApp({');
|
|
40
40
|
});
|
|
41
41
|
it('should configure /mcp endpoint', () => {
|
|
42
42
|
const template = getIndexTemplate();
|
|
@@ -46,7 +46,12 @@ describe('sdk/stateless templates', () => {
|
|
|
46
46
|
});
|
|
47
47
|
it('should use PORT from environment variable', () => {
|
|
48
48
|
const template = getIndexTemplate();
|
|
49
|
-
expect(template).toContain('process.env.PORT
|
|
49
|
+
expect(template).toContain('process.env.PORT');
|
|
50
|
+
});
|
|
51
|
+
it('should pass allowedHosts to createMcpExpressApp', () => {
|
|
52
|
+
const template = getIndexTemplate();
|
|
53
|
+
expect(template).toContain('allowedHosts');
|
|
54
|
+
expect(template).toContain("ALLOWED_HOSTS?.split(',')");
|
|
50
55
|
});
|
|
51
56
|
// Stateless-specific tests
|
|
52
57
|
it('should use undefined sessionIdGenerator for stateless mode', () => {
|