Skip to content

MCP stdio corruption: AutoCommit logs to stdout break JSON-RPC on PREVC phase completion (v1.1.1) #89

Closed

Description

@edapinheiro

Summary

When running as the MCP stdio server (npx @dotcontext/mcp@latest), completing a PREVC phase corrupts the JSON-RPC stream and drops the connection. The MCP client fails with:

Client error: Unexpected token 'A', "[AutoCommit"... is not valid JSON
[V2 FSM] connection:transport_error: conn=connected,auth=valid -> conn=failed,auth=valid

This is the same class of bug as #74 (invalid JSON emitted on stdout). Likely relevant to the #73 / 1.1.2 release.

Root cause

MCP stdio uses stdout exclusively for JSON-RPC framing. In Node, console.info/console.log write to stdout; console.warn/console.error write to stderr.

dist/harness/domain/workflow/plans/planUpdateOrchestrator.js (method autoCommitPhase) logs two auto-commit messages via console.info, which land on stdout and corrupt the protocol:

  • console.info('[AutoCommit] No files to commit - skipping');
  • console.info(`[AutoCommit] Created commit ${commitResult.shortHash} for phase ${phaseId}`);

autoCommitOnPhaseComplete defaults to true and there is no env toggle, so this fires on every phase completion that stages .context/**. The console.warn/console.error calls in the same method are fine (stderr).

Reproduction

  1. Configure the MCP server: npx -y @dotcontext/mcp@latest (stdio) in an MCP host (Cursor).
  2. Init/link a PREVC plan in a git repo.
  3. Advance/complete a phase so autoCommitPhase runs with staged .context/**.
  4. Observe the client transport fail with Unexpected token 'A', "[AutoCommit"....

Timestamps of the failures line up exactly with the chore(plan): complete ... auto-commits.

Fix

Route these logs to stderr (they are diagnostics, not protocol data):

-                    console.info('[AutoCommit] No files to commit - skipping');
+                    console.error('[AutoCommit] No files to commit - skipping');
@@
-                console.info(`[AutoCommit] Created commit ${commitResult.shortHash} for phase ${phaseId}`);
+                console.error(`[AutoCommit] Created commit ${commitResult.shortHash} for phase ${phaseId}`);

Broader hardening suggestion

grep -rn "console\.(info|log)" dist shows ~231 occurrences. Most are CLI-only (safe), but any reachable from the MCP server request path is a latent stdout-corruption bug (e.g. sync/import/reverseSync services). Consider a lint rule banning console.log/console.info in server-reachable modules, or a logger that always targets stderr when running under the MCP transport.

Environment

  • @dotcontext/mcp 1.1.1 (latest)
  • Node.js v24.14.0
  • Host: Cursor (MCP stdio)
  • OS: macOS

Activity

  1. vinilana commented on Nov 22, 2026

    @vinilana
    Owner

    Thanks for the thorough report — your diagnosis is right. MCP stdio reserves stdout for JSON-RPC, but autoCommitPhase in planUpdateOrchestrator.ts logged with console.info, which Node writes to stdout, so the client died with Unexpected token 'A', "[AutoCommit"... on PREVC phase completion. Same class of issue as #74.

    Fix is up in #95: AutoCommit diagnostics now go to stderr, and the MCP stdio server installs a guard that redirects console.log/info/debug to stderr for the whole transport, with regression tests. It'll ship in the next release.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions