mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-09 23:03:12 +00:00
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:
52
src/mcp/stdio-wrapper.ts
Normal file
52
src/mcp/stdio-wrapper.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Stdio wrapper for MCP server
|
||||
* Ensures clean JSON-RPC communication by suppressing all non-JSON output
|
||||
*/
|
||||
|
||||
// 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;
|
||||
|
||||
// Override all console methods
|
||||
console.log = () => {};
|
||||
console.error = () => {};
|
||||
console.warn = () => {};
|
||||
console.info = () => {};
|
||||
console.debug = () => {};
|
||||
|
||||
// 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 { N8NDocumentationMCPServer } from './server-update';
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const server = new N8NDocumentationMCPServer();
|
||||
await server.run();
|
||||
} catch (error) {
|
||||
// In case of fatal error, output to stderr only
|
||||
originalConsoleError('Fatal error:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle uncaught errors silently
|
||||
process.on('uncaughtException', (error) => {
|
||||
originalConsoleError('Uncaught exception:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
originalConsoleError('Unhandled rejection:', reason);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user