fix: resolve Docker stdio initialization timeout issue

- Add InitializeRequestSchema handler to MCP server
- Implement stdout flushing for Docker environments
- Create stdio-wrapper for clean JSON-RPC communication
- Update docker-entrypoint.sh to prevent stdout pollution
- Fix logger to check MCP_MODE before level check

These changes ensure the MCP server responds to initialization requests
within Claude Desktop's 60-second timeout when running in Docker.
This commit is contained in:
czlonkowski
2025-06-17 09:12:01 +02:00
parent 75952f94ca
commit a688ad3d14
7 changed files with 211 additions and 82 deletions

View File

@@ -35,12 +35,19 @@ fi
# Trap signals for graceful shutdown
# In stdio mode, don't output anything to stdout as it breaks JSON-RPC
if [ "$MCP_MODE" = "stdio" ]; then
trap 'kill -TERM $PID 2>/dev/null' TERM INT
# Silent trap - no output at all
trap 'kill -TERM $PID 2>/dev/null || true' TERM INT EXIT
else
trap 'echo "Shutting down..." >&2; kill -TERM $PID' TERM INT
# In HTTP mode, output to stderr
trap 'echo "Shutting down..." >&2; kill -TERM $PID 2>/dev/null' TERM INT EXIT
fi
# Execute the main command in background
"$@" &
# In stdio mode, use the wrapper for clean output
if [ "$MCP_MODE" = "stdio" ] && [ -f "/app/dist/mcp/stdio-wrapper.js" ]; then
node /app/dist/mcp/stdio-wrapper.js &
else
"$@" &
fi
PID=$!
wait $PID