Commit 2396a34
fix: refactor SSE transport to use per-session SDK server instances
The SSE transport previously multiplexed all client connections through a
single SDK Server + custom transport, causing session collisions when
clients like n8n reconnect frequently. Responses were broadcast to ALL
connected clients instead of being routed to the correct session.
This refactor creates a separate SDK SSEServerTransport and SDK Server
instance per SSE connection, matching the SDK's intended usage pattern
(as shown in its own examples) and the HTTP stream transport's architecture.
Key changes:
- Each GET /sse creates a new SDK SSEServerTransport + SDK Server pair
- POST /messages routes to the correct per-session transport
- MCPServer provides a server factory via createSDKServerForSession()
- Session cleanup avoids circular close between server and transport
- Removed manual SSE stream management, keep-alive, and broadcast logic
Fixes #90
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent a385629 commit 2396a34
4 files changed
Lines changed: 320 additions & 265 deletions
File tree
- src
- core
- transports/sse
- tests
- e2e
- transports/sse
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
198 | 215 | | |
199 | 216 | | |
200 | 217 | | |
| |||
977 | 994 | | |
978 | 995 | | |
979 | 996 | | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
980 | 1009 | | |
981 | 1010 | | |
982 | 1011 | | |
| |||
0 commit comments