Hmbown/CodeWhale · error

MCP server ' ': process closed stdout before answering

Error message

MCP server '{server}': process closed stdout before answering {method}{}

What it means

When the reader thread sees EOF on the child's stdout, it drops the response channel; request() then receives RecvTimeoutError::Disconnected and bails with this message plus the child's exit status (exit_note). It reports that the MCP server process terminated before delivering an answer.

Solutions

  1. Read the appended exit_note (exit code/signal) and the child's stderr to identify the cause of death.
  2. Run the server command manually and invoke the same method to reproduce the crash.
  3. Check for OOM kills or external signals (dmesg, journalctl).
  4. Update or pin the server version if a known crash regression.
Defensive patterns

Strategy: try-catch

Validate before calling

// detect a dead child before issuing a request
fn is_usable(client: &ChildProcessMcpClient) -> bool {
    !client.has_exited()
}

Try / catch

match client.request(method, params, timeout) {
    Ok(v) => v,
    Err(e) if e.to_string().contains("closed stdout") => {
        // exit_note in the message carries status; restart the server and retry once
        eprintln!("MCP server exited: {e}");
        respawn_and_retry(method, params)?
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: The child process exits or closes its stdout while request() is awaiting a response — crash, clean exit, or killed process — before the timeout expires.

Common situations: Server crashed handling the request; process killed by OOM/signal; npx/uvx wrapper exiting due to fetch failure; server exiting after an internal error.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/8fa53522f91b130b. Report an issue: GitHub.

Appendix: source

Thrown at crates/mcp/src/stdio_client.rs:901

        let deadline = Instant::now() + timeout;
        loop {
            let remaining = deadline.saturating_duration_since(Instant::now());
            if remaining.is_zero() {
                bail!("MCP server '{server}': {method} timed out after {timeout:?}");
            }
            let line = match self.responses.recv_timeout(remaining) {
                Ok(ChildStdoutMessage::Line(line)) => line,
                Ok(ChildStdoutMessage::Invalid(error)) => {
                    bail!(
                        "MCP server '{server}': invalid child stdout while awaiting {method}: {error}"
                    );
                }
                Err(RecvTimeoutError::Timeout) => {
                    bail!("MCP server '{server}': {method} timed out after {timeout:?}");
                }
                Err(RecvTimeoutError::Disconnected) => {
                    bail!(
                        "MCP server '{server}': process closed stdout before answering {method}{}",
                        self.exit_note()
                    );
                }
            };

            // Servers occasionally emit banners or log lines on stdout. They
            // are skipped; only the matching response ends the wait. Valid
            // requests and notifications are handled by the reader before
            // they reach this rendezvous.
            let Ok(message) = serde_json::from_str::<Value>(&line) else {
                continue;
            };
            if message.get("jsonrpc").and_then(Value::as_str) != Some("2.0") {
                bail!(
                    "MCP server '{server}': {method} received a child message without jsonrpc \"2.0\""
                );
            }

View on GitHub (pinned to 73e0f67d83)