Skip to content

Commit 9dfb1cb

Browse files
authored
refactor!: switch to stateless HTTP transport (#304)
* refactor!: switch HTTP transport to stateless mode Each request creates its own McpServer and transport with sessionIdGenerator: undefined. Removes the session registry, SSE transport, /messages endpoint, and progress notification interval. StreamableHTTP is served at both /mcp and /sse for backward compatibility. GET and DELETE return 405. * docs: update transport references after stateless HTTP refactor * fix: catch async errors in Express 4 route handler Express 4 does not catch rejected promises from async handlers. Without a try/catch, a failure in connect() or handleRequest() causes an unhandled rejection that crashes the process. * chore: upgrade Express to v5 Aligns with the MCP SDK which already depends on Express 5. Express 5 natively catches async route handler rejections, so the manual try/catch added in the previous commit is no longer needed. * fix: add per-request cleanup and JSON-RPC error middleware Close transport and McpServer when the response ends, matching the SDK's recommended pattern for stateless servers. Add Express error-handling middleware that returns a JSON-RPC error response instead of Express's default HTML 500. * fix: use SDK's createMcpExpressApp for DNS rebinding protection Replace raw express() with the SDK's createMcpExpressApp(), which applies localhost DNS rebinding protection middleware automatically. This also handles express.json() globally, removing the need for per-route body parsing.
1 parent e5ea5d6 commit 9dfb1cb

6 files changed

Lines changed: 113 additions & 627 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ Configuration:
5656
- FIGMA_API_KEY: ****8pXg (source: cli)
5757
- PORT: 3333 (source: default)
5858
59-
Initializing Figma MCP Server in HTTP mode on port 3333...
59+
Initializing Figma MCP Server in HTTP mode on 127.0.0.1:3333...
6060
HTTP server listening on port 3333
61-
SSE endpoint available at http://localhost:3333/sse
62-
Message endpoint available at http://localhost:3333/messages
63-
New SSE connection established
61+
StreamableHTTP endpoint available at http://127.0.0.1:3333/mcp
62+
StreamableHTTP endpoint available at http://127.0.0.1:3333/sse (backward compat)
6463
```
6564

6665
**MCP Logs**

CLAUDE.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ PRs are squash-merged, so the PR title becomes the commit message that release-p
4949

5050
### Transport Modes
5151

52-
The server supports three transports (all configured in `src/server.ts`):
52+
The server supports two transports (configured in `src/server.ts`):
5353

5454
- **stdio** — For direct MCP client integration (activated with `--stdio` flag or `NODE_ENV=cli`)
55-
- **StreamableHTTP** — Modern HTTP transport at `/mcp`
56-
- **SSE** — Legacy HTTP transport at `/sse` + `/messages`
55+
- **StreamableHTTP** — Stateless HTTP transport at `/mcp` (also served at `/sse` for backward compatibility with existing client configs)
5756

5857
### Core Data Flow
5958

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
"cleye": "^2.2.1",
5555
"cross-env": "^7.0.3",
5656
"dotenv": "^16.4.7",
57-
"express": "^4.21.2",
57+
"express": "^5.2.1",
58+
"jimp": "^1.6.0",
5859
"js-yaml": "^4.1.1",
5960
"remeda": "^2.20.1",
60-
"jimp": "^1.6.0",
6161
"zod": "^3.25.76"
6262
},
6363
"devDependencies": {

0 commit comments

Comments
 (0)