Files
n8n-mcp/docker/docker-entrypoint.sh
czlonkowski 75952f94ca fix: Docker stdio communication for Claude Desktop compatibility
Fixed the initialization timeout issue with minimal changes:

1. Added stdout flush after server connection to combat Docker buffering
2. Fixed docker-entrypoint.sh to not output to stdout in stdio mode
3. Added process.stdin.resume() to keep server alive
4. Added IS_DOCKER environment variable for future use
5. Updated README to prioritize Docker with correct -i flag configuration

The core issue was Docker's block buffering preventing immediate JSON-RPC
responses. The -i flag maintains stdin connection, and explicit flushing
ensures responses reach Claude Desktop immediately.

Also fixed "Shutting down..." message that was breaking JSON-RPC protocol
by redirecting it to stderr in stdio mode.

Docker is now the recommended installation method as originally intended.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-17 00:30:54 +02:00

46 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
set -e
# Environment variable validation
if [ "$MCP_MODE" = "http" ] && [ -z "$AUTH_TOKEN" ]; then
echo "ERROR: AUTH_TOKEN is required for HTTP mode"
exit 1
fi
# Database initialization with file locking to prevent race conditions
if [ ! -f "/app/data/nodes.db" ]; then
echo "Database not found. Initializing..."
# Use a lock file to prevent multiple containers from initializing simultaneously
(
flock -x 200
# Double-check inside the lock
if [ ! -f "/app/data/nodes.db" ]; then
echo "Initializing database..."
cd /app && node dist/scripts/rebuild.js || {
echo "ERROR: Database initialization failed"
exit 1
}
fi
) 200>/app/data/.db.lock
fi
# Fix permissions if running as root (for development)
if [ "$(id -u)" = "0" ]; then
echo "Running as root, fixing permissions..."
chown -R nodejs:nodejs /app/data
# Switch to nodejs user (using Alpine's native su)
exec su nodejs -c "$*"
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
else
trap 'echo "Shutting down..." >&2; kill -TERM $PID' TERM INT
fi
# Execute the main command in background
"$@" &
PID=$!
wait $PID