fix: enhance stdio wrapper for Docker clean JSON-RPC output

- Set environment variables BEFORE imports in stdio-wrapper
- Override ALL console methods to prevent any output
- Update docker-entrypoint.sh to use exec for proper signal handling
- Add fallback if stdio-wrapper.js is missing
- Remove background process handling in stdio mode

This ensures absolutely no log output corrupts the JSON-RPC stream
This commit is contained in:
czlonkowski
2025-06-17 09:55:14 +02:00
parent a688ad3d14
commit b31ad630b8
4 changed files with 64 additions and 14 deletions

View File

@@ -44,10 +44,21 @@ 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 &
if [ "$MCP_MODE" = "stdio" ]; then
# Debug: Log to stderr to check if wrapper exists
if [ "$DEBUG_DOCKER" = "true" ]; then
echo "MCP_MODE is stdio, checking for wrapper..." >&2
ls -la /app/dist/mcp/stdio-wrapper.js >&2 || echo "Wrapper not found!" >&2
fi
if [ -f "/app/dist/mcp/stdio-wrapper.js" ]; then
# Use the stdio wrapper for clean JSON-RPC output
exec node /app/dist/mcp/stdio-wrapper.js
else
# Fallback: run with explicit environment
exec env MCP_MODE=stdio DISABLE_CONSOLE_OUTPUT=true LOG_LEVEL=error node /app/dist/mcp/index.js
fi
else
"$@" &
fi
PID=$!
wait $PID
# HTTP mode or other
exec "$@"
fi