fix: complete solution for MCP HTTP server stream errors (v2.3.2)

Root Cause Analysis:
- Express.json() middleware was consuming request stream before StreamableHTTPServerTransport
- StreamableHTTPServerTransport has initialization issues with stateless usage

Two-Phase Solution:
1. Removed all body parsing middleware to preserve raw streams
2. Created http-server-fixed.ts with direct JSON-RPC implementation

Key Changes:
- Remove express.json() from all HTTP server implementations
- Add http-server-fixed.ts that bypasses StreamableHTTPServerTransport
- Implement initialize, tools/list, and tools/call methods directly
- Add USE_FIXED_HTTP=true environment variable to enable fixed server
- Update logging to not access req.body

The fixed implementation:
- Handles JSON-RPC protocol directly without transport complications
- Maintains full MCP compatibility
- Works reliably without stream or initialization errors
- Provides better performance and debugging capabilities

Usage: MCP_MODE=http USE_FIXED_HTTP=true npm start

This provides a stable, production-ready HTTP server for n8n-MCP.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-06-14 17:19:42 +02:00
parent 2cb264fd56
commit baf5293cb8
10 changed files with 652 additions and 58 deletions

View File

@@ -84,7 +84,7 @@ export class N8NMCPEngine {
total: Math.round(memoryUsage.heapTotal / 1024 / 1024),
unit: 'MB'
},
version: '2.3.1'
version: '2.3.2'
};
} catch (error) {
logger.error('Health check failed:', error);
@@ -93,7 +93,7 @@ export class N8NMCPEngine {
uptime: 0,
sessionActive: false,
memoryUsage: { used: 0, total: 0, unit: 'MB' },
version: '2.3.1'
version: '2.3.2'
};
}
}