Commit fa89ea5
committed
fix(mcp): prevent stdout pollution in MCP stdio protocol
Root Cause:
Lines 1133-1135 (dual transport) and 1140-1142 (daemon mode) wrote
directly to stdout without checking if stdout is attached to a TTY.
This violated the MCP protocol specification which requires stdout
to contain ONLY JSON-RPC messages when in stdio mode.
Impact:
- MCP clients couldn't connect: "Failed to reconnect to codegraph"
- JSON-RPC parsing failed due to text preceding JSON messages
- Protocol violation prevented any MCP communication
Detection:
Dual transport: println!("✓ MCP server started with dual transport");
Daemon mode: println!("Running in daemon mode");
Fix:
Wrapped all println! calls in handle_start() with atty::is(Stream::Stdout)
checks, matching the pattern used elsewhere in the codebase (handle_stop,
etc.). Messages now only appear when stdout is a terminal, not when it's
being used for MCP JSON-RPC communication.
Verified:
- Build successful
- Follows existing pattern from lines 1154-1155 (handle_stop)
- Only affects dual transport and daemon mode startup messages
- Other println! calls are in CLI-only commands (status, config, index)1 parent ebd3e7a commit fa89ea5
1 file changed
+10
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1130 | 1130 | | |
1131 | 1131 | | |
1132 | 1132 | | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
1136 | 1138 | | |
1137 | 1139 | | |
1138 | 1140 | | |
1139 | 1141 | | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
1143 | 1147 | | |
1144 | 1148 | | |
1145 | 1149 | | |
| |||
0 commit comments