Skip to content

fix(mcp-servers): stop debug console.log from polluting the stdio JSON-RPC channel - #2051

Open
leom1919 wants to merge 1 commit into
bytedance:mainfrom
leom1919:fix-mcp-servers-stdout-log-pollution
Open

leom1919 wants to merge 1 commit into
bytedance:mainfrom
leom1919:fix-mcp-servers-stdout-log-pollution

Conversation

@leom1919

Copy link
Copy Markdown

Summary

@agent-infra/mcp-server-filesystem and @agent-infra/mcp-server-commands are published as standalone npm packages and default to the stdio transport (the READMEs instruct running them via npx in VS Code / Cursor / Claude Desktop MCP configs). For stdio servers, process.stdout is the JSON-RPC protocol channel: the SDK's StdioServerTransport writes every protocol message there and does not intercept console output, so any stray console.log injects non-JSON lines into the stream that clients try to parse as JSON-RPC.

Both servers currently ship leftover debug logging on that channel:

  • mcp-server-filesystem: validatePath() logs requestedPath and allowedDirectories on every tool call (and parentDir on the new-file fallback branch).
  • mcp-server-commands: runCommand() logs the full exec result (including command output) on every successful run_command.

Changes:

  • Removed the three console.log calls in packages/agent-infra/mcp-servers/filesystem/src/server.ts (validatePath).
  • Removed the console.log('execute command result', result) call in packages/agent-infra/mcp-servers/commands/src/server.ts (runCommand).
  • Existing console.error (stderr) logging is untouched, so error-path diagnostics keep working.

No existing issue covers this; found while auditing the MCP server packages for stdio safety.

Verification: added a regression test per package that spies on console.log and fails if any call fires while tools are invoked over an in-memory client/server pair:

  • filesystem: covers both validatePath branches (existing file via read_file, new file via write_file) — fails on main, passes with this patch.
  • commands: covers run_command end to end — fails on main, passes with this patch.

Full package test suites pass after the change (the only remaining failures on a Windows dev machine are pre-existing bash/ls-dependent tests that require a Unix shell; they are unrelated to this change and pass on Linux CI).

Checklist

  • Added or updated necessary tests (Optional).
  • Updated documentation to align with changes (Optional).
  • Verified no breaking changes, or prepared solutions for any occurring breaking changes (Optional).
  • My change does not involve the above items.

…N-RPC channel

Both @agent-infra/mcp-server-filesystem and @agent-infra/mcp-server-commands
default to the stdio transport, where process.stdout is the JSON-RPC
protocol channel (the SDK StdioServerTransport does not intercept console
output). Leftover debug logging therefore injects non-JSON lines into the
stream that clients parse as JSON-RPC:

- mcp-server-filesystem: validatePath logged requestedPath and
  allowedDirectories on every tool call (and parentDir on the new-file
  fallback branch).
- mcp-server-commands: runCommand logged the full exec result (including
  command output) on every successful run_command.

Remove the console.log calls and add a regression test per package that
fails if any console.log fires while tools are invoked. Existing
console.error (stderr) logging is untouched.
@netlify

netlify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for agent-tars-docs canceled.

Name Link
🔨 Latest commit 32f4b39
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/6ad85efb36071584d9d60aad

@netlify

netlify Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tarko canceled.

Name Link
🔨 Latest commit 32f4b39
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/6ad85efb94e24c2e067b7a18

@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants