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

52
src/mcp/stdio-wrapper.ts Normal file
View 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();