openai/codex · error · io::Error

MCP stdin closed

Error message

MCP stdin closed

What it means

The local stdio MCP transport failed while sending a JSON-RPC frame because the child process's stdin stream has been closed. It fires in Transport::send when writing the serialized frame to the locked stdin pipe fails, typically because the MCP server process exited or the pipe was broken.

Solutions

  1. Check whether the MCP server process crashed or exited and restart it
  2. Inspect the server's stderr logs for a startup failure
  3. Verify the command configured for the stdio MCP server exists and runs
  4. Treat the transport as terminated and reconnect the MCP client
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/rmcp-client/src/local_stdio_transport.rs:150 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/1d7ac4e1020ee7db. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/rmcp-client/src/local_stdio_transport.rs:150

impl Transport<RoleClient> for LocalStdioTransport {
    type Error = io::Error;

    #[expect(
        clippy::await_holding_invalid_type,
        reason = "complete JSON-RPC frames must hold the stdin lock across writes"
    )]
    fn send(
        &mut self,
        item: TxJsonRpcMessage<RoleClient>,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + 'static {
        let stdin = Arc::clone(&self.stdin);
        async move {
            let mut message = serde_json::to_vec(&item).map_err(io::Error::other)?;
            message.push(b'\n');
            let mut guard = stdin.lock().await;
            let stdin = guard
                .as_mut()
                .ok_or_else(|| io::Error::new(io::ErrorKind::BrokenPipe, "MCP stdin closed"))?;
            stdin.write_all(&message).await?;
            stdin.flush().await
        }
    }

    fn receive(&mut self) -> impl Future<Output = Option<RxJsonRpcMessage<RoleClient>>> + Send {
        self.receive_message()
    }

    async fn close(&mut self) -> Result<(), Self::Error> {
        self.stdin.lock().await.take();
        match tokio::time::timeout(Duration::from_secs(3), self.child.wait()).await {
            Ok(status) => {
                status?;
                Ok(())
            }
            Err(_) => self.child.kill().await,
        }

View on GitHub (pinned to 339751715c)