You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Migrated to flat ESLint config with strict type-only imports enforcement
- Added comprehensive async safety rules and type checking
- Configured minimal Prettier with high-signal settings only
- Setup pre-commit hooks with husky and lint-staged
- Added GitHub Actions CI workflow for automated validation
- Pinned Node types explicitly and updated tsconfig for NodeNext modules
- Fixed all ESLint warnings and type safety issues
- Cleaned up unused config files and dependencies
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CLAUDE.md
+34-12Lines changed: 34 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,9 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
7
7
This is an **Educational Reference Implementation** of a Stateless HTTP Streamable MCP Server. This is NOT just a simple example - it's a comprehensive teaching resource designed to demonstrate production-ready patterns, security best practices, and modern deployment strategies for Model Context Protocol servers.
8
8
9
9
### Educational Mission
10
+
10
11
This repository serves as a **masterclass** in building stateless MCP servers, covering:
thrownewMcpError(ErrorCode.InvalidParams, 'Division by zero is not allowed.');
182
198
183
199
// Global error handler catches unexpected errors
184
200
requestLogger.error('Unhandled error in MCP request handler', { error });
185
201
res.status(500).json({
186
202
jsonrpc: '2.0',
187
203
error: {
188
204
code: ErrorCode.InternalError,
189
-
message: 'An internal server error occurred.'
205
+
message: 'An internal server error occurred.',
190
206
},
191
-
id: req.body?.id||null
207
+
id: req.body?.id||null,
192
208
});
193
209
```
194
210
195
211
### Request Lifecycle Pattern
212
+
196
213
1. Generate unique `requestId` for correlation
197
214
2. Create contextual logger with `requestId`
198
215
3. Create fresh MCP server and transport instances
@@ -203,13 +220,15 @@ res.status(500).json({
203
220
## Testing Stateless Behavior
204
221
205
222
### Verification Points
223
+
206
224
- Each request creates new server instance
207
225
- No shared state between concurrent requests
208
226
- Request correlation works via `requestId`
209
227
- Cleanup happens properly on connection close
210
228
- Metrics collection doesn't leak memory
211
229
212
230
### Common Issues to Watch
231
+
213
232
- Forgetting to set `sessionIdGenerator: undefined`
214
233
- Missing cleanup in `res.on('close')` listener
215
234
- Sharing state accidentally via closures
@@ -218,19 +237,22 @@ res.status(500).json({
218
237
## Production Deployment
219
238
220
239
### Containerization
240
+
221
241
- Multi-stage Dockerfile (builder + production stages)
222
242
- Docker Compose with health checks
223
243
- Minimal production image (no dev dependencies)
224
244
225
245
### Serverless Ready
246
+
226
247
-`handleMCPRequest` function can be exported as serverless handler
227
248
- No persistent state to manage
228
249
- Scales infinitely without coordination
229
250
230
251
### Monitoring
252
+
231
253
- Structured JSON logging with correlation
232
254
- Prometheus-style metrics endpoint
233
255
- Health checks for load balancers
234
256
- Request duration and tool execution histograms
235
257
236
-
This server demonstrates that stateless architecture enables simpler, more secure, and infinitely scalable MCP implementations. The educational approach teaches both what to build and what NOT to build, making it an invaluable learning resource.
258
+
This server demonstrates that stateless architecture enables simpler, more secure, and infinitely scalable MCP implementations. The educational approach teaches both what to build and what NOT to build, making it an invaluable learning resource.
0 commit comments