Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(mcp): redirect console.log/warn to stderr in --mcp stdio mode (#2840)

Containercccc53cade41
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 = [];