From cccc53cade41f6614119ce42b2d32c14cf3f74a5 Mon Sep 17 00:00:00 2001 From: Container <78986709+disonjer@users.noreply.github.com> Date: Fri, 29 May 2026 10:28:38 +0200 Subject: [PATCH] fix(mcp): redirect console.log/warn to stderr in --mcp stdio mode (#2840) Integrated into release/v3.8.6 --- bin/omniroute.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/omniroute.mjs b/bin/omniroute.mjs index e536ac30e0..b03bb3626c 100755 --- a/bin/omniroute.mjs +++ b/bin/omniroute.mjs @@ -28,6 +28,16 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const ROOT = join(__dirname, ".."); +// MCP stdio transport uses stdout exclusively for JSON-RPC messages. +// Redirect console.log/warn to stderr early (before loadEnvFile and DB init) +// so no startup output corrupts the protocol. +if (process.argv.includes("--mcp")) { + const { Console } = await import("node:console"); + const stderrConsole = new Console({ stdout: process.stderr, stderr: process.stderr }); + console.log = stderrConsole.log.bind(stderrConsole); + console.warn = stderrConsole.warn.bind(stderrConsole); +} + function loadEnvFile() { const envPaths = [];