Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/omniroute.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ 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 _stderrWrite = (msg) => process.stderr.write(msg + "\n");
console.log = (...a) => _stderrWrite(a.join(" "));
console.warn = (...a) => _stderrWrite(a.join(" "));
}
Comment on lines +34 to +39

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Overriding console.log and console.warn with a simple a.join(" ") breaks standard Node.js console formatting (such as formatting of objects, multiple arguments, and string formatting placeholders like %s or %j).

To preserve full formatting capabilities while redirecting output to stderr, you can use Node's built-in Console class from node:console.

if (process.argv.includes("--mcp")) {
  const { Console } = await import("node:console");
  const mcpConsole = new Console({ stdout: process.stderr, stderr: process.stderr });
  console.log = mcpConsole.log.bind(mcpConsole);
  console.warn = mcpConsole.warn.bind(mcpConsole);
}


function loadEnvFile() {
const envPaths = [];

Expand Down