Hmbown/CodeWhale · error · std::io::Error

MCP stdio line exceeded {max} bytes without a newline

Error message

MCP stdio line exceeded {max} bytes without a newline

What it means

Capacity guard in read_line_capped: the accumulated buffered line for an MCP stdio message exceeded the configured maximum byte cap before any newline was seen, so the read is aborted to prevent unbounded memory growth from a hostile or broken peer.

Source

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

        let (chunk, consumed, done) = {
            let available = reader.fill_buf().await?;
            if available.is_empty() {
                (Vec::new(), 0usize, true)
            } else if let Some(pos) = available.iter().position(|&b| b == b'\n') {
                (available[..=pos].to_vec(), pos + 1, true)
            } else {
                (available.to_vec(), available.len(), false)
            }
        };
        if consumed > 0 {
            reader.consume(consumed);
        }
        out.extend_from_slice(&chunk);
        if done {
            break;
        }
        if out.len() > max {
            return Err(std::io::Error::new(
                std::io::ErrorKind::InvalidData,
                format!("MCP stdio line exceeded {max} bytes without a newline"),
            ));
        }
    }
    Ok(out.len())
}

#[cfg(test)]
mod read_cap_tests {
    use super::read_line_capped;

    #[tokio::test]
    async fn reads_a_line_and_reports_eof() {
        let data = b"hello\nworld\n".to_vec();
        let mut reader = tokio::io::BufReader::new(std::io::Cursor::new(data));
        let mut out = Vec::new();
        assert_eq!(

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Fix or restart the MCP server so it emits newline-delimited lines within the size cap.
  2. Check the cap configuration if legitimately large messages are expected.
  3. Inspect the stream for protocol desync or corruption upstream.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/tui/src/mcp/stdio.rs:398 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/9bd1f34aafb55ca8. Report an issue: GitHub.