@agentailor/create-mcp-server 0.5.2 → 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.
@@ -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
  }
@@ -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 { type Request, type Response } from 'express';
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 app = createMcpExpressApp();
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 || 3000');
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 app = createMcpExpressApp();
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 || 3000');
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', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentailor/create-mcp-server",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Create a new MCP (Model Context Protocol) server project",
5
5
  "type": "module",
6
6
  "bin": {