@agentailor/create-mcp-server 0.6.1 → 0.7.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.
@@ -1,11 +1,47 @@
1
- // Options parameter added for type consistency with stateful template (OAuth not supported in stateless)
2
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1
+ /**
2
+ * Shared HTTP entrypoint template, used by both SDK HTTP template types.
3
+ * Varies only by `options.withOAuth`.
4
+ */
3
5
  export function getIndexTemplate(options) {
6
+ const withOAuth = options?.withOAuth ?? false;
7
+ const authImports = withOAuth
8
+ ? `
9
+ import {
10
+ setupAuthMetadataRouter,
11
+ authMiddleware,
12
+ getOAuthMetadataUrl,
13
+ validateOAuthConfig,
14
+ } from './auth.js';`
15
+ : '';
16
+ const mcpRoute = withOAuth
17
+ ? `app.all('/mcp', authMiddleware, (req: Request, res: Response) => void node(req, res, req.body));`
18
+ : `app.all('/mcp', (req: Request, res: Response) => void node(req, res, req.body));`;
19
+ const startup = withOAuth
20
+ ? `async function main() {
21
+ // Validate OAuth configuration and fetch OIDC discovery document
22
+ await validateOAuthConfig();
23
+
24
+ // Setup OAuth metadata routes (must be after validateOAuthConfig)
25
+ setupAuthMetadataRouter(app);
26
+
27
+ startServer(PORT);
28
+ }
29
+
30
+ main().catch((error) => {
31
+ console.error('Failed to start server:', error.message);
32
+ process.exit(1);
33
+ });`
34
+ : `startServer(PORT);`;
35
+ const oauthMetadataLog = withOAuth
36
+ ? `
37
+ console.log(\`OAuth metadata available at \${getOAuthMetadataUrl()}\`);`
38
+ : '';
4
39
  return `import 'dotenv/config';
5
- import { type Request, type Response } from 'express';
6
- import { createMcpExpressApp } from '@modelcontextprotocol/sdk/server/express.js';
7
- import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
8
- import { getServer } from './server.js';
40
+ import { type Request, type Response } from 'express';
41
+ import { createMcpHandler } from '@modelcontextprotocol/server';
42
+ import { createMcpExpressApp } from '@modelcontextprotocol/express';
43
+ import { toNodeHandler } from '@modelcontextprotocol/node';
44
+ import { getServer } from './server.js';${authImports}
9
45
 
10
46
  const allowedHosts = process.env.ALLOWED_HOSTS?.split(',') ?? [];
11
47
 
@@ -16,68 +52,19 @@ const app = createMcpExpressApp({
16
52
  // Health check endpoint for container orchestration
17
53
  app.get('/health', (_, res) => res.sendStatus(200));
18
54
 
19
- app.post('/mcp', async (req: Request, res: Response) => {
20
- const server = getServer();
21
- try {
22
- const transport: StreamableHTTPServerTransport = new StreamableHTTPServerTransport({
23
- sessionIdGenerator: undefined,
24
- });
25
- await server.connect(transport);
26
- await transport.handleRequest(req, res, req.body);
27
- res.on('close', () => {
28
- console.log('Request closed');
29
- transport.close();
30
- server.close();
31
- });
32
- } catch (error) {
33
- console.error('Error handling MCP request:', error);
34
- if (!res.headersSent) {
35
- res.status(500).json({
36
- jsonrpc: '2.0',
37
- error: {
38
- code: -32603,
39
- message: 'Internal server error',
40
- },
41
- id: null,
42
- });
43
- }
44
- }
45
- });
46
-
47
- app.get('/mcp', async (req: Request, res: Response) => {
48
- console.log('Received GET MCP request');
49
- res.writeHead(405).end(
50
- JSON.stringify({
51
- jsonrpc: '2.0',
52
- error: {
53
- code: -32000,
54
- message: 'Method not allowed.',
55
- },
56
- id: null,
57
- })
58
- );
59
- });
55
+ // The factory runs once per request, so a fresh McpServer serves every call.
56
+ const handler = createMcpHandler(() => getServer());
57
+ const node = toNodeHandler(handler);
60
58
 
61
- app.delete('/mcp', async (req: Request, res: Response) => {
62
- console.log('Received DELETE MCP request');
63
- res.writeHead(405).end(
64
- JSON.stringify({
65
- jsonrpc: '2.0',
66
- error: {
67
- code: -32000,
68
- message: 'Method not allowed.',
69
- },
70
- id: null,
71
- })
72
- );
73
- });
59
+ // The handler owns method dispatch (POST/GET/DELETE) for the MCP endpoint.
60
+ ${mcpRoute}
74
61
 
75
62
  // Start the server
76
63
  const PORT = process.env.PORT || 3000;
77
64
 
78
65
  function startServer(port: number | string): void {
79
66
  const server = app.listen(port, () => {
80
- console.log(\`MCP Streamable HTTP Server listening on port \${port}\`);
67
+ console.log(\`MCP HTTP Server listening on port \${port}\`);${oauthMetadataLog}
81
68
  });
82
69
 
83
70
  server.on('error', (error: NodeJS.ErrnoException) => {
@@ -92,7 +79,7 @@ function startServer(port: number | string): void {
92
79
  });
93
80
  }
94
81
 
95
- startServer(PORT);
82
+ ${startup}
96
83
 
97
84
  // Handle server shutdown
98
85
  process.on('SIGINT', async () => {
@@ -1,2 +1,6 @@
1
1
  import type { TemplateOptions } from './index.js';
2
+ /**
3
+ * Shared README template, used by both SDK HTTP template types.
4
+ * Varies only by `options.withOAuth`.
5
+ */
2
6
  export declare function getReadmeTemplate(projectName: string, options?: TemplateOptions): string;
@@ -1,4 +1,9 @@
1
+ /**
2
+ * Shared README template, used by both SDK HTTP template types.
3
+ * Varies only by `options.withOAuth`.
4
+ */
1
5
  export function getReadmeTemplate(projectName, options) {
6
+ const withOAuth = options?.withOAuth ?? false;
2
7
  const packageManager = options?.packageManager ?? 'npm';
3
8
  const commands = {
4
9
  npm: {
@@ -23,14 +28,94 @@ export function getReadmeTemplate(projectName, options) {
23
28
  inspect: 'yarn inspect',
24
29
  },
25
30
  }[packageManager];
31
+ const description = withOAuth
32
+ ? 'A streamable HTTP MCP (Model Context Protocol) server with OAuth authentication, built on the official MCP TypeScript SDK v2.'
33
+ : 'A streamable HTTP MCP (Model Context Protocol) server built on the official MCP TypeScript SDK v2.';
34
+ const oauthSection = withOAuth
35
+ ? `
36
+ ## OAuth Authentication
37
+
38
+ This server uses OAuth 2.0 with JWT tokens for authentication. It works with any OIDC-compliant provider including:
39
+ - Auth0
40
+ - Keycloak
41
+ - Azure AD / Entra ID
42
+ - Okta
43
+ - And more...
44
+
45
+ ### Environment Variables
46
+
47
+ | Variable | Description | Example |
48
+ |----------|-------------|---------|
49
+ | \`OAUTH_ISSUER_URL\` | Base URL of your OAuth provider | \`https://your-tenant.auth0.com\` |
50
+ | \`OAUTH_AUDIENCE\` | API identifier / audience claim (optional) | \`https://your-api.com\` |
51
+
52
+ ### Provider-Specific Issuer URLs
53
+
54
+ | Provider | Issuer URL Format |
55
+ |----------|-------------------|
56
+ | Auth0 | \`https://{tenant}.auth0.com\` |
57
+ | Keycloak | \`http://{host}:{port}/realms/{realm}\` |
58
+ | Azure AD | \`https://login.microsoftonline.com/{tenant}/v2.0\` |
59
+ | Okta | \`https://{domain}.okta.com/oauth2/default\` |
60
+
61
+ ### How It Works
62
+
63
+ 1. The server fetches public keys from \`{OAUTH_ISSUER_URL}/.well-known/jwks.json\`
64
+ 2. Incoming JWT tokens are verified locally using these keys
65
+ 3. The token's \`iss\` (issuer) and optionally \`aud\` (audience) claims are validated
66
+ 4. The validated token is attached to \`req.auth\` and surfaced to MCP handlers as \`ctx.http.authInfo\`
67
+
68
+ ### Protected Resource Metadata
69
+
70
+ - **GET /.well-known/oauth-protected-resource** - OAuth protected resource metadata
71
+
72
+ ### Token Requirements
73
+
74
+ - All MCP endpoints require a valid JWT Bearer token in the \`Authorization\` header
75
+ - Tokens must be signed by the configured OAuth provider
76
+ - If \`OAUTH_AUDIENCE\` is set, the token's \`aud\` claim must match
77
+ `
78
+ : '';
79
+ const apiEndpointsOAuthNote = withOAuth
80
+ ? '\n - Requires valid Bearer token in Authorization header'
81
+ : '';
82
+ const projectStructure = withOAuth
83
+ ? `\`\`\`
84
+ ${projectName}/
85
+ ├── src/
86
+ │ ├── server.ts # MCP server definition (tools, prompts, resources)
87
+ │ ├── index.ts # Express app and MCP HTTP handler setup
88
+ │ └── auth.ts # OAuth configuration and middleware
89
+ ├── Dockerfile # Multi-stage Docker build
90
+ ├── package.json
91
+ ├── tsconfig.json
92
+ └── README.md
93
+ \`\`\``
94
+ : `\`\`\`
95
+ ${projectName}/
96
+ ├── src/
97
+ │ ├── server.ts # MCP server definition (tools, prompts, resources)
98
+ │ └── index.ts # Express app and MCP HTTP handler setup
99
+ ├── Dockerfile # Multi-stage Docker build
100
+ ├── package.json
101
+ ├── tsconfig.json
102
+ └── README.md
103
+ \`\`\``;
104
+ const customizationOAuthNote = withOAuth
105
+ ? '\n- Configure OAuth scopes and token verification in `src/auth.ts`'
106
+ : '';
26
107
  return `# ${projectName}
27
108
 
28
- A stateless streamable HTTP MCP (Model Context Protocol) server.
109
+ ${description}
29
110
 
30
111
  ## About
31
112
 
32
113
  This project was created with [@agentailor/create-mcp-server](https://www.npmjs.com/package/@agentailor/create-mcp-server).
33
114
 
115
+ The server is built on \`createMcpHandler\`, which runs the server factory once per request — a fresh \`McpServer\` serves every call, so the server is stateless and scales horizontally without sticky sessions.
116
+
117
+ It serves MCP protocol revision **2026-07-28** and also accepts 2025-era clients through the same per-request path.
118
+
34
119
  ## Getting Started
35
120
 
36
121
  \`\`\`bash
@@ -62,10 +147,10 @@ Then, in another terminal, launch the inspector:
62
147
  \`\`\`bash
63
148
  ${commands.inspect}
64
149
  \`\`\`
65
-
150
+ ${oauthSection}
66
151
  ## API Endpoints
67
152
 
68
- - **POST /mcp** - Main MCP endpoint for JSON-RPC messages
153
+ - **/mcp** - Main MCP endpoint. The SDK handler owns method dispatch, so the route is mounted with \`app.all\`.${apiEndpointsOAuthNote}
69
154
  - **GET /health** - Health check endpoint (returns 200 OK)
70
155
 
71
156
  ## Included Examples
@@ -78,9 +163,8 @@ This server comes with example implementations to help you get started:
78
163
 
79
164
  ### Tools
80
165
 
81
- - **start-notification-stream** - Sends periodic notifications for testing. Parameters:
82
- - \`interval\`: Milliseconds between notifications (default: 100)
83
- - \`count\`: Number of notifications to send (default: 10, use 0 for unlimited)
166
+ - **greet** - Greets a user by name. Parameters:
167
+ - \`name\`: Name of the person to greet
84
168
 
85
169
  ### Resources
86
170
 
@@ -88,16 +172,7 @@ This server comes with example implementations to help you get started:
88
172
 
89
173
  ## Project Structure
90
174
 
91
- \`\`\`
92
- ${projectName}/
93
- ├── src/
94
- │ ├── server.ts # MCP server definition (tools, prompts, resources)
95
- │ └── index.ts # Express app and HTTP transport setup
96
- ├── Dockerfile # Multi-stage Docker build
97
- ├── package.json
98
- ├── tsconfig.json
99
- └── README.md
100
- \`\`\`
175
+ ${projectStructure}
101
176
 
102
177
  ## Deployment
103
178
 
@@ -113,11 +188,11 @@ docker run -p 3000:3000 ${projectName}
113
188
  ## Customization
114
189
 
115
190
  - Add new tools, prompts, and resources in \`src/server.ts\`
116
- - Modify the HTTP transport configuration in \`src/index.ts\`
191
+ - Modify the HTTP handler and Express configuration in \`src/index.ts\`${customizationOAuthNote}
117
192
 
118
193
  ## Learn More
119
194
 
120
195
  - [Model Context Protocol](https://modelcontextprotocol.io/)
121
- - [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
196
+ - [MCP TypeScript SDK v2](https://ts.sdk.modelcontextprotocol.io/v2/)
122
197
  `;
123
198
  }
@@ -1,26 +1,27 @@
1
1
  export function getServerTemplate(projectName) {
2
- return `import type { CallToolResult, GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
3
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ return `import type {
3
+ CallToolResult,
4
+ GetPromptResult,
5
+ ReadResourceResult,
6
+ } from '@modelcontextprotocol/server';
7
+ import { McpServer } from '@modelcontextprotocol/server';
4
8
  import { z } from 'zod';
5
9
 
6
10
  export function getServer() {
7
11
  // Create an MCP server with implementation details
8
- const server = new McpServer(
9
- {
10
- name: '${projectName}',
11
- version: '1.0.0',
12
- },
13
- { capabilities: { logging: {} } }
14
- );
12
+ const server = new McpServer({
13
+ name: '${projectName}',
14
+ version: '1.0.0',
15
+ });
15
16
 
16
17
  // Register a simple prompt
17
18
  server.registerPrompt(
18
19
  'greeting-template',
19
20
  {
20
21
  description: 'A simple greeting prompt template',
21
- argsSchema: {
22
+ argsSchema: z.object({
22
23
  name: z.string().describe('Name to include in greeting'),
23
- },
24
+ }),
24
25
  },
25
26
  async ({ name }): Promise<GetPromptResult> => {
26
27
  return {
@@ -37,45 +38,20 @@ export function getServer() {
37
38
  }
38
39
  );
39
40
 
40
- // Register a tool for testing resumability
41
41
  server.registerTool(
42
- 'start-notification-stream',
42
+ 'greet',
43
43
  {
44
- description: 'Starts sending periodic notifications for testing resumability',
45
- inputSchema: {
46
- interval: z
47
- .number()
48
- .describe('Interval in milliseconds between notifications')
49
- .default(100),
50
- count: z.number().describe('Number of notifications to send (0 for 100)').default(10),
51
- },
44
+ description: 'Greet a user by name',
45
+ inputSchema: z.object({
46
+ name: z.string().describe('Name of the person to greet'),
47
+ }),
52
48
  },
53
- async ({ interval, count }, extra): Promise<CallToolResult> => {
54
- const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
55
- let counter = 0;
56
-
57
- while (count === 0 || counter < count) {
58
- counter++;
59
- try {
60
- await server.sendLoggingMessage(
61
- {
62
- level: 'info',
63
- data: \`Periodic notification #\${counter} at \${new Date().toISOString()}\`,
64
- },
65
- extra.sessionId
66
- );
67
- } catch (error) {
68
- console.error('Error sending notification:', error);
69
- }
70
- // Wait for the specified interval
71
- await sleep(interval);
72
- }
73
-
49
+ async ({ name }): Promise<CallToolResult> => {
74
50
  return {
75
51
  content: [
76
52
  {
77
53
  type: 'text',
78
- text: \`Started sending periodic notifications every \${interval}ms\`,
54
+ text: \`Hello, \${name}!\`,
79
55
  },
80
56
  ],
81
57
  };
@@ -7,10 +7,13 @@ describe('sdk/stateless templates', () => {
7
7
  const template = getServerTemplate(projectName);
8
8
  expect(template).toContain(`name: '${projectName}'`);
9
9
  });
10
- it('should use correct SDK imports', () => {
10
+ it('should use SDK v2 imports', () => {
11
11
  const template = getServerTemplate(projectName);
12
- expect(template).toContain("from '@modelcontextprotocol/sdk/types.js'");
13
- expect(template).toContain("from '@modelcontextprotocol/sdk/server/mcp.js'");
12
+ expect(template).toContain("from '@modelcontextprotocol/server'");
13
+ });
14
+ it('should not use v1 SDK import paths', () => {
15
+ const template = getServerTemplate(projectName);
16
+ expect(template).not.toContain('@modelcontextprotocol/sdk');
14
17
  });
15
18
  it('should include example prompt', () => {
16
19
  const template = getServerTemplate(projectName);
@@ -19,9 +22,19 @@ describe('sdk/stateless templates', () => {
19
22
  });
20
23
  it('should include example tool', () => {
21
24
  const template = getServerTemplate(projectName);
22
- expect(template).toContain('start-notification-stream');
25
+ expect(template).toContain('greet');
23
26
  expect(template).toContain('registerTool');
24
27
  });
28
+ it('should declare schemas as Standard Schema via z.object', () => {
29
+ const template = getServerTemplate(projectName);
30
+ expect(template).toContain('inputSchema: z.object(');
31
+ expect(template).toContain('argsSchema: z.object(');
32
+ });
33
+ it('should not use the deprecated logging subsystem', () => {
34
+ const template = getServerTemplate(projectName);
35
+ expect(template).not.toContain('sendLoggingMessage');
36
+ expect(template).not.toContain('capabilities: { logging: {} }');
37
+ });
25
38
  it('should include example resource', () => {
26
39
  const template = getServerTemplate(projectName);
27
40
  expect(template).toContain('greeting-resource');
@@ -29,20 +42,33 @@ describe('sdk/stateless templates', () => {
29
42
  });
30
43
  });
31
44
  describe('getIndexTemplate', () => {
32
- it('should use correct SDK import for transport', () => {
45
+ it('should use SDK v2 serving imports', () => {
46
+ const template = getIndexTemplate();
47
+ expect(template).toContain("import { createMcpHandler } from '@modelcontextprotocol/server'");
48
+ expect(template).toContain("import { createMcpExpressApp } from '@modelcontextprotocol/express'");
49
+ expect(template).toContain("import { toNodeHandler } from '@modelcontextprotocol/node'");
50
+ });
51
+ it('should not use v1 SDK import paths', () => {
33
52
  const template = getIndexTemplate();
34
- expect(template).toContain("from '@modelcontextprotocol/sdk/server/streamableHttp.js'");
53
+ expect(template).not.toContain('@modelcontextprotocol/sdk');
54
+ });
55
+ it('should build the handler from a per-request server factory', () => {
56
+ const template = getIndexTemplate();
57
+ expect(template).toContain('createMcpHandler(() => getServer())');
58
+ expect(template).toContain('toNodeHandler(handler)');
35
59
  });
36
60
  it('should use createMcpExpressApp', () => {
37
61
  const template = getIndexTemplate();
38
62
  expect(template).toContain('createMcpExpressApp');
39
63
  expect(template).toContain('const app = createMcpExpressApp({');
40
64
  });
41
- it('should configure /mcp endpoint', () => {
65
+ it('should mount the /mcp endpoint with app.all', () => {
66
+ const template = getIndexTemplate();
67
+ expect(template).toContain("app.all('/mcp'");
68
+ });
69
+ it('should include a health check endpoint', () => {
42
70
  const template = getIndexTemplate();
43
- expect(template).toContain("app.post('/mcp'");
44
- expect(template).toContain("app.get('/mcp'");
45
- expect(template).toContain("app.delete('/mcp'");
71
+ expect(template).toContain("app.get('/health'");
46
72
  });
47
73
  it('should use PORT from environment variable', () => {
48
74
  const template = getIndexTemplate();
@@ -53,14 +79,12 @@ describe('sdk/stateless templates', () => {
53
79
  expect(template).toContain('allowedHosts');
54
80
  expect(template).toContain("ALLOWED_HOSTS?.split(',')");
55
81
  });
56
- // Stateless-specific tests
57
- it('should use undefined sessionIdGenerator for stateless mode', () => {
82
+ it('should not carry over v1 session machinery', () => {
58
83
  const template = getIndexTemplate();
59
- expect(template).toContain('sessionIdGenerator: undefined');
60
- });
61
- it('should return 405 for GET requests', () => {
62
- const template = getIndexTemplate();
63
- expect(template).toContain('res.writeHead(405)');
84
+ expect(template).not.toContain('sessionIdGenerator');
85
+ expect(template).not.toContain('isInitializeRequest');
86
+ expect(template).not.toContain('randomUUID');
87
+ expect(template).not.toContain('mcp-session-id');
64
88
  });
65
89
  });
66
90
  describe('getReadmeTemplate', () => {
@@ -79,9 +103,14 @@ describe('sdk/stateless templates', () => {
79
103
  const template = getReadmeTemplate(projectName);
80
104
  expect(template).toContain('/mcp');
81
105
  });
82
- it('should describe stateless behavior', () => {
106
+ it('should describe stateless per-request behavior', () => {
83
107
  const template = getReadmeTemplate(projectName);
84
108
  expect(template).toContain('stateless');
109
+ expect(template).toContain('createMcpHandler');
110
+ });
111
+ it('should document the served protocol revision', () => {
112
+ const template = getReadmeTemplate(projectName);
113
+ expect(template).toContain('2026-07-28');
85
114
  });
86
115
  });
87
116
  describe('getReadmeTemplate with package manager', () => {
@@ -1,20 +1,13 @@
1
1
  // Options parameter kept for type consistency with other SDK templates
2
2
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3
3
  export function getIndexTemplate(_options) {
4
- return `import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ return `import { serveStdio } from '@modelcontextprotocol/server/stdio';
5
5
  import { getServer } from './server.js';
6
6
 
7
- async function main() {
8
- const server = getServer();
9
- const transport = new StdioServerTransport();
10
- await server.connect(transport);
11
- console.error("MCP Server running on stdio");
12
- }
7
+ // stdout is reserved for the MCP protocol - always log to stderr.
8
+ serveStdio(() => getServer());
13
9
 
14
- main().catch((error) => {
15
- console.error("Fatal error in main():", error);
16
- process.exit(1);
17
- });
10
+ console.error('MCP Server running on stdio');
18
11
  `;
19
12
  }
20
13
  export { getServerTemplate } from './server.js';
@@ -31,12 +31,16 @@ export function getReadmeTemplate(projectName, options) {
31
31
  }[packageManager];
32
32
  return `# ${projectName}
33
33
 
34
- A stdio MCP (Model Context Protocol) server using the official MCP SDK.
34
+ A stdio MCP (Model Context Protocol) server using the official MCP TypeScript SDK v2.
35
35
 
36
36
  ## About
37
37
 
38
38
  This project was created with [@agentailor/create-mcp-server](https://www.npmjs.com/package/@agentailor/create-mcp-server).
39
39
 
40
+ The server uses \`serveStdio\`, which pins one server instance per connection and negotiates the protocol era from the opening exchange. It serves MCP protocol revision **2026-07-28** and also accepts 2025-era clients.
41
+
42
+ Note: stdout is reserved for the MCP protocol, so all logging must go to stderr.
43
+
40
44
  ## Getting Started
41
45
 
42
46
  \`\`\`bash
@@ -70,10 +74,7 @@ You can also call tools directly:
70
74
 
71
75
  \`\`\`bash
72
76
  # Call a tool
73
- npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/call --tool-name start-notification-stream --tool-arg interval=100 --tool-arg count=5
74
-
75
- # Call a tool with JSON arguments
76
- npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/call --tool-name start-notification-stream --tool-arg 'options={"interval": 100, "count": 5}'
77
+ npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/call --tool-name greet --tool-arg name=World
77
78
  \`\`\`
78
79
 
79
80
  ## Included Examples
@@ -86,9 +87,8 @@ This server comes with example implementations to help you get started:
86
87
 
87
88
  ### Tools
88
89
 
89
- - **start-notification-stream** - Sends periodic notifications for testing. Parameters:
90
- - \`interval\`: Milliseconds between notifications (default: 100)
91
- - \`count\`: Number of notifications to send (default: 10, use 0 for unlimited)
90
+ - **greet** - Greets a user by name. Parameters:
91
+ - \`name\`: Name of the person to greet
92
92
 
93
93
  ### Resources
94
94
 
@@ -114,6 +114,6 @@ ${projectName}/
114
114
  ## Learn More
115
115
 
116
116
  - [Model Context Protocol](https://modelcontextprotocol.io/)
117
- - [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
117
+ - [MCP TypeScript SDK v2](https://ts.sdk.modelcontextprotocol.io/v2/)
118
118
  `;
119
119
  }
@@ -7,10 +7,10 @@ describe('sdk/stdio templates', () => {
7
7
  const template = getServerTemplate(projectName);
8
8
  expect(template).toContain(`name: '${projectName}'`);
9
9
  });
10
- it('should use correct SDK imports', () => {
10
+ it('should use SDK v2 imports', () => {
11
11
  const template = getServerTemplate(projectName);
12
- expect(template).toContain("from '@modelcontextprotocol/sdk/types.js'");
13
- expect(template).toContain("from '@modelcontextprotocol/sdk/server/mcp.js'");
12
+ expect(template).toContain("from '@modelcontextprotocol/server'");
13
+ expect(template).not.toContain('@modelcontextprotocol/sdk');
14
14
  });
15
15
  it('should include example prompt', () => {
16
16
  const template = getServerTemplate(projectName);
@@ -19,7 +19,7 @@ describe('sdk/stdio templates', () => {
19
19
  });
20
20
  it('should include example tool', () => {
21
21
  const template = getServerTemplate(projectName);
22
- expect(template).toContain('start-notification-stream');
22
+ expect(template).toContain('greet');
23
23
  expect(template).toContain('registerTool');
24
24
  });
25
25
  it('should include example resource', () => {
@@ -29,10 +29,16 @@ describe('sdk/stdio templates', () => {
29
29
  });
30
30
  });
31
31
  describe('getIndexTemplate', () => {
32
- it('should import StdioServerTransport', () => {
32
+ it('should serve via serveStdio from the SDK v2 stdio entry', () => {
33
33
  const template = getIndexTemplate();
34
- expect(template).toContain('StdioServerTransport');
35
- expect(template).toContain('@modelcontextprotocol/sdk/server/stdio.js');
34
+ expect(template).toContain("import { serveStdio } from '@modelcontextprotocol/server/stdio'");
35
+ expect(template).toContain('serveStdio(() => getServer())');
36
+ });
37
+ it('should not use v1 SDK import paths or transport wiring', () => {
38
+ const template = getIndexTemplate();
39
+ expect(template).not.toContain('@modelcontextprotocol/sdk');
40
+ expect(template).not.toContain('StdioServerTransport');
41
+ expect(template).not.toContain('server.connect(');
36
42
  });
37
43
  it('should NOT import express or createMcpExpressApp', () => {
38
44
  const template = getIndexTemplate();
@@ -44,20 +50,10 @@ describe('sdk/stdio templates', () => {
44
50
  expect(template).not.toContain('PORT');
45
51
  expect(template).not.toContain('process.env.PORT');
46
52
  });
47
- it('should connect server to StdioServerTransport', () => {
48
- const template = getIndexTemplate();
49
- expect(template).toContain('new StdioServerTransport()');
50
- expect(template).toContain('server.connect(transport)');
51
- });
52
53
  it('should log to stderr, not stdout', () => {
53
54
  const template = getIndexTemplate();
54
- expect(template).toContain('console.error("MCP Server running on stdio")');
55
- });
56
- it('should wrap startup in async main with error handling', () => {
57
- const template = getIndexTemplate();
58
- expect(template).toContain('async function main()');
59
- expect(template).toContain('main().catch');
60
- expect(template).toContain('process.exit(1)');
55
+ expect(template).toContain("console.error('MCP Server running on stdio')");
56
+ expect(template).not.toContain('console.log');
61
57
  });
62
58
  });
63
59
  describe('getReadmeTemplate', () => {