Hmbown/CodeWhale · error

Stdio transport read error

Error message

Stdio transport read error: {err}
{stderr}

What it means

Thrown by the stdio MCP transport's `recv` when reading a JSON-RPC message line from the child process's stdout fails. The error wraps the underlying I/O error and appends a tail of the child's captured stderr, since stderr is usually the only place the child explains why it stopped producing output.

Solutions

  1. Inspect the stderr excerpt in the message to find the child's actual failure (panic, missing module, bad flag).
  2. Fix the MCP server command/config so the child starts and stays healthy (correct binary path, args, env).
  3. Restart the MCP server process / reopen the transport and retry.
  4. Check for resource issues (OOM, disk, permissions) that killed the child.

Example fix

// before: broken command kills child mid-session
"command": "npx", "args": ["-y", "@acme/server@0.1.0"]
// after: stderr excerpt showed 'Cannot find module'; pin a working version
"command": "npx", "args": ["-y", "@acme/server@0.3.2"]
Defensive patterns

Strategy: try-catch

Validate before calling

// Smoke-test the child command before wiring it into the transport
let out = std::process::Command::new("npx").args(["-y", "@acme/server", "--help"]).output()?;
if !out.status.success() { bail!("MCP server command fails: {}", String::from_utf8_lossy(&out.stderr)); }

Try / catch

// Surface the stderr excerpt verbatim to the operator, then restart the transport
match transport.recv().await {
    Err(e) if e.to_string().starts_with("Stdio transport read error") => {
        log::error!("{e}");
        transport = spawn_stdio_transport(config)?;
    }
    other => other,
}

Prevention

When it happens

Trigger: The child MCP server process read on stdout returns an Err from `read` (e.g. child died mid-line, pipe broken, OS-level I/O error), and `format_stderr_context` finds non-empty stderr output to attach.

Common situations: The MCP server binary crashes while handling a request; the child writes a panic to stderr and exits; the command is killed by OOM or a signal mid-communication; a broken pipe after the child terminates unexpectedly.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/ae81b9813dccdc98. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/mcp/stdio.rs:329

        self.stdin.flush().await?;
        Ok(())
    }

    async fn recv(&mut self) -> Result<Vec<u8>> {
        loop {
            // Bounded read: a server emitting a newline-free multi-GB "line"
            // must not OOM us (read_line is unbounded).
            let bytes = match read_line_capped(
                &mut self.reader,
                &mut self.pending_line,
                MAX_MCP_RESPONSE_BYTES,
            )
            .await
            {
                Ok(b) => b,
                Err(err) => {
                    if let Some(stderr) = format_stderr_context(&self.stderr_tail).await {
                        anyhow::bail!("Stdio transport read error: {err}\n{stderr}");
                    }
                    return Err(err.into());
                }
            };
            if bytes == 0 {
                // Let the stderr drain task catch up before snapshotting, and
                // name the exit status: a reviewed plugin's stderr is never
                // retained, so the status is the only reason the operator
                // gets when the child dies before the handshake (#5916).
                tokio::task::yield_now().await;
                let exit = self.child.lock().await.try_wait().ok().flatten();
                let exit = exit.map_or_else(String::new, |status| format!(" ({status})"));
                if let Some(stderr) = format_stderr_context(&self.stderr_tail).await {
                    anyhow::bail!("Stdio transport closed{exit}\n{stderr}");
                }
                anyhow::bail!("Stdio transport closed{exit}");
            }

View on GitHub (pinned to 433685b202)