fix: implement Single-Session architecture to resolve MCP stream errors
- Add ConsoleManager to prevent console output interference with StreamableHTTPServerTransport - Implement SingleSessionHTTPServer with persistent session reuse - Create N8NMCPEngine for clean service integration - Add automatic session expiry after 30 minutes of inactivity - Update logger to be HTTP-aware during active requests - Maintain backward compatibility with existing deployments This fixes the "stream is not readable" error by implementing the Hybrid Single-Session architecture as documented in MCP_ERROR_FIX_PLAN.md 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
65
scripts/test-single-session.sh
Executable file
65
scripts/test-single-session.sh
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
# Test script for single-session HTTP server
|
||||
|
||||
set -e
|
||||
|
||||
echo "🧪 Testing Single-Session HTTP Server..."
|
||||
echo
|
||||
|
||||
# Generate test auth token if not set
|
||||
if [ -z "$AUTH_TOKEN" ]; then
|
||||
export AUTH_TOKEN="test-token-$(date +%s)"
|
||||
echo "Generated test AUTH_TOKEN: $AUTH_TOKEN"
|
||||
fi
|
||||
|
||||
# Start server in background
|
||||
echo "Starting server..."
|
||||
MCP_MODE=http npm start > server.log 2>&1 &
|
||||
SERVER_PID=$!
|
||||
|
||||
# Wait for server to start
|
||||
echo "Waiting for server to start..."
|
||||
sleep 3
|
||||
|
||||
# Check health endpoint
|
||||
echo
|
||||
echo "Testing health endpoint..."
|
||||
curl -s http://localhost:3000/health | jq .
|
||||
|
||||
# Test authentication failure
|
||||
echo
|
||||
echo "Testing authentication failure..."
|
||||
curl -s -X POST http://localhost:3000/mcp \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer wrong-token" \
|
||||
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}' | jq .
|
||||
|
||||
# Test successful request
|
||||
echo
|
||||
echo "Testing successful request..."
|
||||
curl -s -X POST http://localhost:3000/mcp \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AUTH_TOKEN" \
|
||||
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}' | jq .
|
||||
|
||||
# Test session reuse
|
||||
echo
|
||||
echo "Testing session reuse (second request)..."
|
||||
curl -s -X POST http://localhost:3000/mcp \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer $AUTH_TOKEN" \
|
||||
-d '{"jsonrpc":"2.0","method":"get_database_statistics","id":2}' | jq .
|
||||
|
||||
# Check health again to see session info
|
||||
echo
|
||||
echo "Checking health to see session info..."
|
||||
curl -s http://localhost:3000/health | jq .
|
||||
|
||||
# Clean up
|
||||
echo
|
||||
echo "Stopping server..."
|
||||
kill $SERVER_PID 2>/dev/null || true
|
||||
wait $SERVER_PID 2>/dev/null || true
|
||||
|
||||
echo
|
||||
echo "✅ Test complete! Check server.log for details."
|
||||
Reference in New Issue
Block a user