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

View File

@@ -51,15 +51,19 @@ export class Logger {
}
private log(level: LogLevel, levelName: string, message: string, ...args: any[]): void {
// Check environment variables FIRST, before level check
// In stdio mode, suppress ALL console output to avoid corrupting JSON-RPC
const isStdio = process.env.MCP_MODE === 'stdio';
const isDisabled = process.env.DISABLE_CONSOLE_OUTPUT === 'true';
if (isStdio || isDisabled) {
// Silently drop all logs in stdio mode
return;
}
if (level <= this.config.level) {
const formattedMessage = this.formatMessage(levelName, message);
// In stdio mode, suppress ALL console output to avoid corrupting JSON-RPC
if (process.env.MCP_MODE === 'stdio' || process.env.DISABLE_CONSOLE_OUTPUT === 'true') {
// Silently drop all logs in stdio mode
return;
}
// In HTTP mode during request handling, suppress console output
// The ConsoleManager will handle this, but we add a safety check
if (process.env.MCP_MODE === 'http' && process.env.MCP_REQUEST_ACTIVE === 'true') {