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:
24
Dockerfile.test
Normal file
24
Dockerfile.test
Normal file
@@ -0,0 +1,24 @@
|
||||
# Quick test Dockerfile using pre-built files
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy only the essentials
|
||||
COPY package*.json ./
|
||||
COPY dist ./dist
|
||||
COPY data ./data
|
||||
COPY docker/docker-entrypoint.sh /usr/local/bin/
|
||||
COPY .env.example ./
|
||||
|
||||
# Install only runtime dependencies
|
||||
RUN npm install --production @modelcontextprotocol/sdk better-sqlite3 express dotenv
|
||||
|
||||
# Make entrypoint executable
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Set environment
|
||||
ENV IS_DOCKER=true
|
||||
ENV MCP_MODE=stdio
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
CMD ["node", "dist/mcp/index.js"]
|
||||
@@ -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
|
||||
2
n8n-docs
2
n8n-docs
Submodule n8n-docs updated: a616515bf2...fea7a3692c
@@ -5,26 +5,41 @@
|
||||
* Ensures clean JSON-RPC communication by suppressing all non-JSON output
|
||||
*/
|
||||
|
||||
// CRITICAL: Set environment BEFORE any imports to prevent any initialization logs
|
||||
process.env.MCP_MODE = 'stdio';
|
||||
process.env.DISABLE_CONSOLE_OUTPUT = 'true';
|
||||
process.env.LOG_LEVEL = 'error';
|
||||
|
||||
// Suppress all console output before anything else
|
||||
const originalConsoleLog = console.log;
|
||||
const originalConsoleError = console.error;
|
||||
const originalConsoleWarn = console.warn;
|
||||
const originalConsoleInfo = console.info;
|
||||
const originalConsoleDebug = console.debug;
|
||||
const originalConsoleTrace = console.trace;
|
||||
const originalConsoleDir = console.dir;
|
||||
const originalConsoleTime = console.time;
|
||||
const originalConsoleTimeEnd = console.timeEnd;
|
||||
|
||||
// Override all console methods
|
||||
// Override ALL console methods to prevent any output
|
||||
console.log = () => {};
|
||||
console.error = () => {};
|
||||
console.warn = () => {};
|
||||
console.info = () => {};
|
||||
console.debug = () => {};
|
||||
console.trace = () => {};
|
||||
console.dir = () => {};
|
||||
console.time = () => {};
|
||||
console.timeEnd = () => {};
|
||||
console.timeLog = () => {};
|
||||
console.group = () => {};
|
||||
console.groupEnd = () => {};
|
||||
console.table = () => {};
|
||||
console.clear = () => {};
|
||||
console.count = () => {};
|
||||
console.countReset = () => {};
|
||||
|
||||
// Set environment to ensure logger suppression
|
||||
process.env.MCP_MODE = 'stdio';
|
||||
process.env.DISABLE_CONSOLE_OUTPUT = 'true';
|
||||
process.env.LOG_LEVEL = 'error';
|
||||
|
||||
// Import and run the server
|
||||
// Import and run the server AFTER suppressing output
|
||||
import { N8NDocumentationMCPServer } from './server-update';
|
||||
|
||||
async function main() {
|
||||
|
||||
Reference in New Issue
Block a user