@agentailor/create-mcp-server 0.6.2 → 0.7.1

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,227 +1,6 @@
1
- export function getIndexTemplate(options) {
2
- const withOAuth = options?.withOAuth ?? false;
3
- const imports = withOAuth
4
- ? `import 'dotenv/config';
5
- import { type Request, type Response } from 'express';
6
- import { randomUUID } from 'node:crypto';
7
- import { createMcpExpressApp } from '@modelcontextprotocol/sdk/server/express.js';
8
- import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
9
- import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
10
- import { getServer } from './server.js';
11
- import {
12
- setupAuthMetadataRouter,
13
- authMiddleware,
14
- getOAuthMetadataUrl,
15
- validateOAuthConfig,
16
- } from './auth.js';`
17
- : `import 'dotenv/config';
18
- import { type Request, type Response } from 'express';
19
- import { randomUUID } from 'node:crypto';
20
- import { createMcpExpressApp } from '@modelcontextprotocol/sdk/server/express.js';
21
- import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
22
- import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js';
23
- import { getServer } from './server.js';`;
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
- });
29
-
30
- // Health check endpoint for container orchestration
31
- app.get('/health', (_, res) => res.sendStatus(200));`;
32
- const postRoute = withOAuth
33
- ? `app.post('/mcp', authMiddleware, async (req: Request, res: Response) => {`
34
- : `app.post('/mcp', async (req: Request, res: Response) => {`;
35
- const getRoute = withOAuth
36
- ? `app.get('/mcp', authMiddleware, async (req: Request, res: Response) => {`
37
- : `app.get('/mcp', async (req: Request, res: Response) => {`;
38
- const deleteRoute = withOAuth
39
- ? `app.delete('/mcp', authMiddleware, async (req: Request, res: Response) => {`
40
- : `app.delete('/mcp', async (req: Request, res: Response) => {`;
41
- return `${imports}
42
-
43
- ${appSetup}
44
-
45
- // Map to store transports by session ID
46
- const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};
47
-
48
- ${postRoute}
49
- const sessionId = req.headers['mcp-session-id'] as string | undefined;
50
- if (sessionId) {
51
- console.log(\`Received MCP request for session: \${sessionId}\`);
52
- }
53
-
54
- try {
55
- let transport: StreamableHTTPServerTransport;
56
-
57
- if (sessionId && transports[sessionId]) {
58
- // Reuse existing transport
59
- transport = transports[sessionId];
60
- } else if (!sessionId && isInitializeRequest(req.body)) {
61
- // New initialization request
62
- transport = new StreamableHTTPServerTransport({
63
- sessionIdGenerator: () => randomUUID(),
64
- onsessioninitialized: (sessionId: string) => {
65
- // Store the transport by session ID when session is initialized
66
- console.log(\`Session initialized with ID: \${sessionId}\`);
67
- transports[sessionId] = transport;
68
- },
69
- });
70
-
71
- // Set up onclose handler to clean up transport when closed
72
- transport.onclose = () => {
73
- const sid = transport.sessionId;
74
- if (sid && transports[sid]) {
75
- console.log(\`Transport closed for session \${sid}, removing from transports map\`);
76
- delete transports[sid];
77
- }
78
- };
79
-
80
- // Connect the transport to the MCP server BEFORE handling the request
81
- const server = getServer();
82
- await server.connect(transport);
83
-
84
- await transport.handleRequest(req, res, req.body);
85
- return;
86
- } else {
87
- // Invalid request - no session ID or not initialization request
88
- res.status(400).json({
89
- jsonrpc: '2.0',
90
- error: {
91
- code: -32000,
92
- message: 'Bad Request: No valid session ID provided',
93
- },
94
- id: null,
95
- });
96
- return;
97
- }
98
-
99
- // Handle the request with existing transport
100
- await transport.handleRequest(req, res, req.body);
101
- } catch (error) {
102
- console.error('Error handling MCP request:', error);
103
- if (!res.headersSent) {
104
- res.status(500).json({
105
- jsonrpc: '2.0',
106
- error: {
107
- code: -32603,
108
- message: 'Internal server error',
109
- },
110
- id: null,
111
- });
112
- }
113
- }
114
- });
115
-
116
- ${getRoute}
117
- const sessionId = req.headers['mcp-session-id'] as string | undefined;
118
- if (!sessionId || !transports[sessionId]) {
119
- res.status(400).send('Invalid or missing session ID');
120
- return;
121
- }
122
-
123
- console.log(\`Establishing SSE stream for session \${sessionId}\`);
124
- const transport = transports[sessionId];
125
- await transport.handleRequest(req, res);
126
- });
127
-
128
- ${deleteRoute}
129
- const sessionId = req.headers['mcp-session-id'] as string | undefined;
130
- if (!sessionId || !transports[sessionId]) {
131
- res.status(400).send('Invalid or missing session ID');
132
- return;
133
- }
134
-
135
- console.log(\`Received session termination request for session \${sessionId}\`);
136
-
137
- try {
138
- const transport = transports[sessionId];
139
- await transport.handleRequest(req, res);
140
- } catch (error) {
141
- console.error('Error handling session termination:', error);
142
- if (!res.headersSent) {
143
- res.status(500).send('Error processing session termination');
144
- }
145
- }
146
- });
147
-
148
- ${withOAuth
149
- ? `// Start the server
150
- const PORT = process.env.PORT || 3000;
151
-
152
- function startServer(port: number | string): void {
153
- const server = app.listen(port, () => {
154
- console.log(\`MCP Stateful HTTP Server listening on port \${port}\`);
155
- console.log(\`OAuth metadata available at \${getOAuthMetadataUrl()}\`);
156
- });
157
-
158
- server.on('error', (error: NodeJS.ErrnoException) => {
159
- if (error.code === 'EADDRINUSE') {
160
- const randomPort = Math.floor(Math.random() * (65535 - 49152) + 49152);
161
- console.log(\`Port \${port} is in use, trying port \${randomPort}...\`);
162
- startServer(randomPort);
163
- } else {
164
- console.error('Failed to start server:', error);
165
- process.exit(1);
166
- }
167
- });
168
- }
169
-
170
- async function main() {
171
- // Validate OAuth configuration and fetch OIDC discovery document
172
- await validateOAuthConfig();
173
-
174
- // Setup OAuth metadata routes (must be after validateOAuthConfig)
175
- setupAuthMetadataRouter(app);
176
-
177
- startServer(PORT);
178
- }
179
-
180
- main().catch((error) => {
181
- console.error('Failed to start server:', error.message);
182
- process.exit(1);
183
- });`
184
- : `// Start the server
185
- const PORT = process.env.PORT || 3000;
186
-
187
- function startServer(port: number | string): void {
188
- const server = app.listen(port, () => {
189
- console.log(\`MCP Stateful HTTP Server listening on port \${port}\`);
190
- });
191
-
192
- server.on('error', (error: NodeJS.ErrnoException) => {
193
- if (error.code === 'EADDRINUSE') {
194
- const randomPort = Math.floor(Math.random() * (65535 - 49152) + 49152);
195
- console.log(\`Port \${port} is in use, trying port \${randomPort}...\`);
196
- startServer(randomPort);
197
- } else {
198
- console.error('Failed to start server:', error);
199
- process.exit(1);
200
- }
201
- });
202
- }
203
-
204
- startServer(PORT);`}
205
-
206
- // Handle server shutdown
207
- process.on('SIGINT', async () => {
208
- console.log('Shutting down server...');
209
-
210
- // Close all active transports to properly clean up resources
211
- for (const sessionId in transports) {
212
- try {
213
- console.log(\`Closing transport for session \${sessionId}\`);
214
- await transports[sessionId].close();
215
- delete transports[sessionId];
216
- } catch (error) {
217
- console.error(\`Error closing transport for session \${sessionId}:\`, error);
218
- }
219
- }
220
- console.log('Server shutdown complete');
221
- process.exit(0);
222
- });
223
- `;
224
- }
1
+ // Intentionally identical to the stateless template - see "Why stateless and
2
+ // stateful are identical" in CLAUDE.md. Edit behaviour in stateless/, not here.
3
+ export { getIndexTemplate } from '../stateless/index.js';
225
4
  export { getServerTemplate } from './server.js';
226
5
  export { getReadmeTemplate } from './readme.js';
227
6
  export { getAuthTemplate } from './auth.js';
@@ -1,2 +1 @@
1
- import type { TemplateOptions } from './index.js';
2
- export declare function getReadmeTemplate(projectName: string, options?: TemplateOptions): string;
1
+ export { getReadmeTemplate } from '../stateless/readme.js';
@@ -1,208 +1,3 @@
1
- export function getReadmeTemplate(projectName, options) {
2
- const withOAuth = options?.withOAuth ?? false;
3
- const packageManager = options?.packageManager ?? 'npm';
4
- const commands = {
5
- npm: {
6
- install: 'npm install',
7
- dev: 'npm run dev',
8
- build: 'npm run build',
9
- start: 'npm start',
10
- inspect: 'npm run inspect',
11
- },
12
- pnpm: {
13
- install: 'pnpm install',
14
- dev: 'pnpm dev',
15
- build: 'pnpm build',
16
- start: 'pnpm start',
17
- inspect: 'pnpm inspect',
18
- },
19
- yarn: {
20
- install: 'yarn',
21
- dev: 'yarn dev',
22
- build: 'yarn build',
23
- start: 'yarn start',
24
- inspect: 'yarn inspect',
25
- },
26
- }[packageManager];
27
- const description = withOAuth
28
- ? 'A stateful streamable HTTP MCP (Model Context Protocol) server with session management and OAuth authentication.'
29
- : 'A stateful streamable HTTP MCP (Model Context Protocol) server with session management.';
30
- const oauthSection = withOAuth
31
- ? `
32
- ## OAuth Authentication
33
-
34
- This server uses OAuth 2.0 with JWT tokens for authentication. It works with any OIDC-compliant provider including:
35
- - Auth0
36
- - Keycloak
37
- - Azure AD / Entra ID
38
- - Okta
39
- - And more...
40
-
41
- ### Environment Variables
42
-
43
- | Variable | Description | Example |
44
- |----------|-------------|---------|
45
- | \`OAUTH_ISSUER_URL\` | Base URL of your OAuth provider | \`https://your-tenant.auth0.com\` |
46
- | \`OAUTH_AUDIENCE\` | API identifier / audience claim (optional) | \`https://your-api.com\` |
47
-
48
- ### Provider-Specific Issuer URLs
49
-
50
- | Provider | Issuer URL Format |
51
- |----------|-------------------|
52
- | Auth0 | \`https://{tenant}.auth0.com\` |
53
- | Keycloak | \`http://{host}:{port}/realms/{realm}\` |
54
- | Azure AD | \`https://login.microsoftonline.com/{tenant}/v2.0\` |
55
- | Okta | \`https://{domain}.okta.com/oauth2/default\` |
56
-
57
- ### How It Works
58
-
59
- 1. The server fetches public keys from \`{OAUTH_ISSUER_URL}/.well-known/jwks.json\`
60
- 2. Incoming JWT tokens are verified locally using these keys
61
- 3. The token's \`iss\` (issuer) and optionally \`aud\` (audience) claims are validated
62
-
63
- ### Protected Resource Metadata
64
-
65
- - **GET /.well-known/oauth-protected-resource** - OAuth protected resource metadata
66
-
67
- ### Token Requirements
68
-
69
- - All MCP endpoints require a valid JWT Bearer token in the \`Authorization\` header
70
- - Tokens must be signed by the configured OAuth provider
71
- - If \`OAUTH_AUDIENCE\` is set, the token's \`aud\` claim must match
72
- `
73
- : '';
74
- const apiEndpointsOAuthNote = withOAuth
75
- ? '\n - Requires valid Bearer token in Authorization header'
76
- : '';
77
- const projectStructure = withOAuth
78
- ? `\`\`\`
79
- ${projectName}/
80
- ├── src/
81
- │ ├── server.ts # MCP server definition (tools, prompts, resources)
82
- │ ├── index.ts # Express app and stateful HTTP transport setup
83
- │ └── auth.ts # OAuth configuration and middleware
84
- ├── Dockerfile # Multi-stage Docker build
85
- ├── package.json
86
- ├── tsconfig.json
87
- └── README.md
88
- \`\`\``
89
- : `\`\`\`
90
- ${projectName}/
91
- ├── src/
92
- │ ├── server.ts # MCP server definition (tools, prompts, resources)
93
- │ └── index.ts # Express app and stateful HTTP transport setup
94
- ├── Dockerfile # Multi-stage Docker build
95
- ├── package.json
96
- ├── tsconfig.json
97
- └── README.md
98
- \`\`\``;
99
- const deploymentSection = `
100
- ## Deployment
101
-
102
- ### Docker
103
-
104
- Build and run the Docker container:
105
-
106
- \`\`\`bash
107
- docker build -t ${projectName} .
108
- docker run -p 3000:3000 ${projectName}
109
- \`\`\`
110
- `;
111
- const customizationOAuthNote = withOAuth
112
- ? '\n- Configure OAuth scopes and token verification in `src/auth.ts`'
113
- : '';
114
- return `# ${projectName}
115
-
116
- ${description}
117
-
118
- ## About
119
-
120
- This project was created with [@agentailor/create-mcp-server](https://www.npmjs.com/package/@agentailor/create-mcp-server).
121
-
122
- ## Getting Started
123
-
124
- \`\`\`bash
125
- # Install dependencies
126
- ${commands.install}
127
-
128
- # Build and run in development
129
- ${commands.dev}
130
-
131
- # Or build and start separately
132
- ${commands.build}
133
- ${commands.start}
134
- \`\`\`
135
-
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
-
138
- ## Testing with MCP Inspector
139
-
140
- This project includes [MCP Inspector](https://github.com/modelcontextprotocol/inspector) as a dev dependency for testing and debugging.
141
-
142
- First, start the server in one terminal:
143
-
144
- \`\`\`bash
145
- ${commands.dev}
146
- \`\`\`
147
-
148
- Then, in another terminal, launch the inspector:
149
-
150
- \`\`\`bash
151
- ${commands.inspect}
152
- \`\`\`
153
- ${oauthSection}
154
- ## API Endpoints
155
-
156
- - **POST /mcp** - Main MCP endpoint for JSON-RPC messages
157
- - First request must be an initialization request (no session ID required)
158
- - Subsequent requests must include \`mcp-session-id\` header${apiEndpointsOAuthNote}
159
- - **GET /mcp** - Server-Sent Events (SSE) stream for server-initiated messages
160
- - Requires \`mcp-session-id\` header${apiEndpointsOAuthNote}
161
- - **DELETE /mcp** - Terminate a session
162
- - Requires \`mcp-session-id\` header${apiEndpointsOAuthNote}
163
- - **GET /health** - Health check endpoint (returns 200 OK)
164
-
165
- ## Session Management
166
-
167
- This server maintains stateful sessions:
168
-
169
- 1. **Initialize**: Send a POST request without a session ID to start a new session
170
- 2. **Session ID**: The server returns an \`mcp-session-id\` header in the response
171
- 3. **Subsequent requests**: Include the session ID in the \`mcp-session-id\` header
172
- 4. **SSE Stream**: Use GET /mcp with your session ID to receive server-initiated messages
173
- 5. **Terminate**: Send DELETE /mcp with your session ID to end the session
174
-
175
- ## Included Examples
176
-
177
- This server comes with example implementations to help you get started:
178
-
179
- ### Prompts
180
-
181
- - **greeting-template** - A simple greeting prompt that takes a name parameter
182
-
183
- ### Tools
184
-
185
- - **start-notification-stream** - Sends periodic notifications for testing. Parameters:
186
- - \`interval\`: Milliseconds between notifications (default: 100)
187
- - \`count\`: Number of notifications to send (default: 10, use 0 for unlimited)
188
-
189
- ### Resources
190
-
191
- - **greeting-resource** - A simple text resource at \`https://example.com/greetings/default\`
192
-
193
- ## Project Structure
194
-
195
- ${projectStructure}
196
- ${deploymentSection}
197
-
198
- ## Customization
199
-
200
- - Add new tools, prompts, and resources in \`src/server.ts\`
201
- - Modify the HTTP transport configuration in \`src/index.ts\`${customizationOAuthNote}
202
-
203
- ## Learn More
204
-
205
- - [Model Context Protocol](https://modelcontextprotocol.io/)
206
- - [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
207
- `;
208
- }
1
+ // Intentionally identical to the stateless template - see "Why stateless and
2
+ // stateful are identical" in CLAUDE.md. Edit behaviour in stateless/, not here.
3
+ export { getReadmeTemplate } from '../stateless/readme.js';
@@ -1,86 +1,62 @@
1
1
  import { describe, it, expect } from 'vitest';
2
2
  import { getServerTemplate, getIndexTemplate, getReadmeTemplate } from './index.js';
3
+ import { getIndexTemplate as getStatelessIndexTemplate, getReadmeTemplate as getStatelessReadmeTemplate, } from '../stateless/index.js';
3
4
  describe('sdk/stateful templates', () => {
4
5
  const projectName = 'test-project';
6
+ // Pins the re-export: shared behaviour is covered by the stateless suite.
7
+ describe('convergence with the stateless template', () => {
8
+ it('should produce the same index template as stateless', () => {
9
+ expect(getIndexTemplate()).toBe(getStatelessIndexTemplate());
10
+ });
11
+ it('should produce the same index template as stateless with OAuth', () => {
12
+ expect(getIndexTemplate({ withOAuth: true })).toBe(getStatelessIndexTemplate({ withOAuth: true }));
13
+ });
14
+ it('should produce the same readme as stateless', () => {
15
+ expect(getReadmeTemplate(projectName)).toBe(getStatelessReadmeTemplate(projectName));
16
+ });
17
+ });
5
18
  describe('getServerTemplate', () => {
6
19
  it('should include project name in server config', () => {
7
20
  const template = getServerTemplate(projectName);
8
21
  expect(template).toContain(`name: '${projectName}'`);
9
22
  });
10
- it('should use correct SDK imports', () => {
23
+ it('should use SDK v2 imports', () => {
11
24
  const template = getServerTemplate(projectName);
12
- expect(template).toContain("from '@modelcontextprotocol/sdk/types.js'");
13
- expect(template).toContain("from '@modelcontextprotocol/sdk/server/mcp.js'");
25
+ expect(template).toContain("from '@modelcontextprotocol/server'");
26
+ expect(template).not.toContain('@modelcontextprotocol/sdk');
14
27
  });
15
- it('should include example prompt', () => {
28
+ it('should include example prompt, tool and resource', () => {
16
29
  const template = getServerTemplate(projectName);
17
30
  expect(template).toContain('greeting-template');
18
31
  expect(template).toContain('registerPrompt');
19
- });
20
- it('should include example tool', () => {
21
- const template = getServerTemplate(projectName);
22
- expect(template).toContain('start-notification-stream');
32
+ expect(template).toContain('greet');
23
33
  expect(template).toContain('registerTool');
24
- });
25
- it('should include example resource', () => {
26
- const template = getServerTemplate(projectName);
27
34
  expect(template).toContain('greeting-resource');
28
35
  expect(template).toContain('registerResource');
29
36
  });
30
37
  });
31
38
  describe('getIndexTemplate', () => {
32
- it('should use correct SDK import for transport', () => {
33
- const template = getIndexTemplate();
34
- expect(template).toContain("from '@modelcontextprotocol/sdk/server/streamableHttp.js'");
35
- });
36
- it('should use createMcpExpressApp', () => {
39
+ it('should use SDK v2 serving imports', () => {
37
40
  const template = getIndexTemplate();
38
- expect(template).toContain('createMcpExpressApp');
39
- expect(template).toContain('const app = createMcpExpressApp({');
41
+ expect(template).toContain("import { createMcpHandler } from '@modelcontextprotocol/server'");
42
+ expect(template).toContain("import { createMcpExpressApp } from '@modelcontextprotocol/express'");
43
+ expect(template).toContain("import { toNodeHandler } from '@modelcontextprotocol/node'");
40
44
  });
41
- it('should configure /mcp endpoint', () => {
45
+ it('should mount the /mcp endpoint with app.all', () => {
42
46
  const template = getIndexTemplate();
43
- expect(template).toContain("app.post('/mcp'");
44
- expect(template).toContain("app.get('/mcp'");
45
- expect(template).toContain("app.delete('/mcp'");
47
+ expect(template).toContain("app.all('/mcp'");
46
48
  });
47
49
  it('should use PORT from environment variable', () => {
48
50
  const template = getIndexTemplate();
49
51
  expect(template).toContain('process.env.PORT');
50
52
  });
51
- it('should pass allowedHosts to createMcpExpressApp', () => {
52
- const template = getIndexTemplate();
53
- expect(template).toContain('allowedHosts');
54
- expect(template).toContain("ALLOWED_HOSTS?.split(',')");
55
- });
56
- // Stateful-specific tests
57
- it('should use session ID header', () => {
58
- const template = getIndexTemplate();
59
- expect(template).toContain('mcp-session-id');
60
- });
61
- it('should store transports by session ID', () => {
53
+ it('should not carry over v1 session machinery', () => {
62
54
  const template = getIndexTemplate();
63
- expect(template).toContain('const transports');
64
- expect(template).toContain('transports[sessionId]');
65
- });
66
- it('should use isInitializeRequest for new sessions', () => {
67
- const template = getIndexTemplate();
68
- expect(template).toContain('isInitializeRequest');
69
- });
70
- it('should generate session IDs with randomUUID', () => {
71
- const template = getIndexTemplate();
72
- expect(template).toContain('randomUUID');
73
- expect(template).toContain('sessionIdGenerator');
74
- });
75
- it('should handle session cleanup on close', () => {
76
- const template = getIndexTemplate();
77
- expect(template).toContain('transport.onclose');
78
- expect(template).toContain('delete transports[sid]');
79
- });
80
- it('should close all transports on SIGINT', () => {
81
- const template = getIndexTemplate();
82
- expect(template).toContain("process.on('SIGINT'");
83
- expect(template).toContain('transports[sessionId].close()');
55
+ expect(template).not.toContain('sessionIdGenerator');
56
+ expect(template).not.toContain('isInitializeRequest');
57
+ expect(template).not.toContain('randomUUID');
58
+ expect(template).not.toContain('mcp-session-id');
59
+ expect(template).not.toContain('const transports');
84
60
  });
85
61
  });
86
62
  describe('getReadmeTemplate', () => {
@@ -99,20 +75,11 @@ describe('sdk/stateful templates', () => {
99
75
  const template = getReadmeTemplate(projectName);
100
76
  expect(template).toContain('/mcp');
101
77
  });
102
- // Stateful-specific documentation tests
103
- it('should document session management', () => {
104
- const template = getReadmeTemplate(projectName);
105
- expect(template).toContain('mcp-session-id');
106
- expect(template).toContain('Session');
107
- });
108
- it('should document SSE stream support', () => {
78
+ it('should not document removed session management', () => {
109
79
  const template = getReadmeTemplate(projectName);
110
- expect(template).toContain('GET /mcp');
111
- expect(template).toContain('SSE');
112
- });
113
- it('should document session termination', () => {
114
- const template = getReadmeTemplate(projectName);
115
- expect(template).toContain('DELETE /mcp');
80
+ expect(template).not.toContain('mcp-session-id');
81
+ expect(template).not.toContain('DELETE /mcp');
82
+ expect(template).not.toContain('SSE');
116
83
  });
117
84
  });
118
85
  describe('getReadmeTemplate with package manager', () => {
@@ -156,11 +123,9 @@ describe('sdk/stateful templates', () => {
156
123
  const template = getIndexTemplate({ withOAuth: true });
157
124
  expect(template).toContain('setupAuthMetadataRouter(app)');
158
125
  });
159
- it('should apply auth middleware to routes when OAuth enabled', () => {
126
+ it('should apply auth middleware to the /mcp route when OAuth enabled', () => {
160
127
  const template = getIndexTemplate({ withOAuth: true });
161
- expect(template).toContain("app.post('/mcp', authMiddleware,");
162
- expect(template).toContain("app.get('/mcp', authMiddleware,");
163
- expect(template).toContain("app.delete('/mcp', authMiddleware,");
128
+ expect(template).toContain("app.all('/mcp', authMiddleware,");
164
129
  });
165
130
  it('should log OAuth metadata URL on startup when OAuth enabled', () => {
166
131
  const template = getIndexTemplate({ withOAuth: true });
@@ -214,6 +179,10 @@ describe('sdk/stateful templates', () => {
214
179
  expect(template).toContain('JWT');
215
180
  expect(template).toContain('.well-known/jwks.json');
216
181
  });
182
+ it('should document where auth info surfaces to handlers', () => {
183
+ const template = getReadmeTemplate(projectName, { withOAuth: true });
184
+ expect(template).toContain('ctx.http.authInfo');
185
+ });
217
186
  it('should include auth.ts in project structure when OAuth enabled', () => {
218
187
  const template = getReadmeTemplate(projectName, { withOAuth: true });
219
188
  expect(template).toContain('auth.ts');
@@ -1,5 +1,9 @@
1
1
  export type { SdkTemplateOptions as TemplateOptions } from '../../common/types.js';
2
2
  import type { SdkTemplateOptions } from '../../common/types.js';
3
+ /**
4
+ * Shared HTTP entrypoint template, used by both SDK HTTP template types.
5
+ * Varies only by `options.withOAuth`.
6
+ */
3
7
  export declare function getIndexTemplate(options?: SdkTemplateOptions): string;
4
8
  export { getServerTemplate } from './server.js';
5
9
  export { getReadmeTemplate } from './readme.js';