fix: Reconnect transport layer during session restoration (v2.19.3) (#317)

Fixes critical bug where session restoration successfully restored InstanceContext
but failed to reconnect the transport layer, causing all requests on restored
sessions to hang indefinitely.

Root Cause:
The handleRequest() method's session restoration flow (lines 1119-1197) called
createSession() which creates a NEW transport separate from the current HTTP request.
This separate transport is not linked to the current req/res pair, so responses
cannot be sent back through the active HTTP connection.

Fix Applied:
Replace createSession() call with inline transport creation that mirrors the
initialize flow. Create StreamableHTTPServerTransport directly for the current
HTTP req/res context and ensure transport is connected to server BEFORE handling
request. This makes restored sessions work identically to fresh sessions.

Impact:
- Zero-downtime deployments now work correctly
- Users can continue work after container restart without restarting MCP client
- Session persistence is now fully functional for production use

Technical Details:
The StreamableHTTPServerTransport class from MCP SDK links a specific HTTP
req/res pair to the MCP server. Creating transport in createSession() binds
it to the wrong req/res (or no req/res at all). The initialize flow got this
right, but restoration flow did not.

Files Changed:
- src/http-server-single-session.ts: Fixed session restoration (lines 1163-1244)
- package.json, package.runtime.json, src/mcp-engine.ts: Version bump to 2.19.3
- CHANGELOG.md: Documented fix with technical details

Testing:
All 13 session persistence integration tests pass, verifying restoration works
correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Romuald Członkowski
2025-10-13 13:11:35 +02:00
committed by GitHub
parent 318986f546
commit 112b40119c
6 changed files with 147 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "n8n-mcp-runtime",
"version": "2.19.2",
"version": "2.19.3",
"description": "n8n MCP Server Runtime Dependencies Only",
"private": true,
"main": "dist/index.js",