Skip to content

stdio transport: a request over the maximum line length gets no answer #1395

Open

Description

@jordiboehme

Since #1049 (rmcp 3.6.0) AsyncRwTransport drops a line that is longer than the maximum line length (16 MiB by default). It only writes a log entry. When that line is a request, the peer never gets an answer and waits until its own timeout. From the client side this looks like a server that hangs.

I found this while writing an MCP server that takes large inline files. A tools/call with a large base64 file in the arguments is enough.

To reproduce:

  1. Start any stdio server built on rmcp 3.7.0.
  2. Send initialize and notifications/initialized.
  3. Send one tools/call request whose line is larger than 16 MiB, for example with a 17 MiB string in arguments.
  4. The server logs "Incoming message exceeded the maximum line length, discarding it". The client gets nothing for this id.

Expected: an error answer for the request id, like the -32600 Invalid Request answer rmcp already sends for valid JSON with the wrong shape.

Lines without an id, responses and input that is not JSON should stay unanswered, so this does not bring back the error storm from #938.

I have a fix ready that builds on #1370. I can open it after that PR is merged.

Activity

  1. added
    bugSomething is not working
    P1High: significant functionality gap or spec violation
    T-transportTransport layer changes
    ready for workIssue is well-defined and ready to be picked up
    on Oct 26, 2026
  2. github-actions commented on Oct 26, 2026

    @github-actions
    Contributor

    @gocamille is on triage rotation this week and is the reviewer for this one.

    Codex labeled this bug / P1 (T-transport). Please confirm or correct those labels.

    Automated triage. Labels are a first pass and the assigned maintainer has the final say.

  3. sai-softwareforest commented on Nov 12, 2026

    @sai-softwareforest

    @jordiboehme I looked at this after #1370 merged (28 Oct) and didn't find a follow-up PR. If you still have the patch, I'd rather review it and help with tests than open a competing one.

    I didn't run a 17 MiB stdio session, but the current code matches the report. In AsyncRwTransport::receive (crates/rmcp/src/transport/async_rw.rs:283-289), LineRead::Oversized only logs Incoming message exceeded the maximum line length, discarding it and continues. The line is never parsed, so nothing is queued on pending_error_response and the peer gets no reply for that id. Transport::receive has no error channel, so the service loop never sees the dropped request either.

    crates/rmcp/tests/test_async_rw_max_line_length.rs already covers drop, recovery, and the default 16 MiB bound, but the test helper builds the transport with tokio::io::sink(), so those tests don't assert what the client would read.

    Repro is the one in the issue: start a stdio server on current main, send initialize and notifications/initialized, then one single-line tools/call whose frame is just over 16 MiB (for example a ~17 MiB string in arguments). The server logs the discard line; nothing comes back for that request id.

    If we can recover the id from a prefix of the discarded line, the reply I'd expect is the same -32600 the wrong-shape path already sends, but with that id:

    {"jsonrpc":"2.0","id":,"error":{"code":-32600,"message":"Invalid request"}}

    If the id isn't in the prefix — or the line is a response, a notification, or not JSON — stay silent, same as #938. One open question: when a request-shaped line is oversized but the id can't be recovered, do you want that same id-less -32600 the current protocol-error path already writes ({"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request"}}, id omitted), or silence?

    Happy to help add tests that actually read the write side (id present, id after a large field, stay-silent cases) against whichever patch lands.

  4. jokemanfire commented on Nov 17, 2026

    @jokemanfire
    Member

    I checked this against current main (9b3ec05); the code matches the report, and there is one detail that constrains any fix: the id is gone before receive sees the oversized line.

    Where it breaks

    • AsyncRwTransport::read_line (crates/rmcp/src/transport/async_rw.rs:157-167) hits the limit, calls self.line_buf.clear(), and does not append the chunk that tripped it. So the bytes before the limit point — which is where a normal request carries "id" — are discarded inside read_line.
    • receive then only sees LineRead::Oversized and logs + continues (async_rw.rs:283-289). PendingErrorResponse is Queue | Flush (async_rw.rs:73-76) and the queued error is built with id: None, so there is no way to answer a specific request today even if the id were known.

    So "recover the id from a prefix" requires a change in read_line, not just in the error path.

    Sketch that fits the existing structure

    1. Keep a bounded prefix while discarding: cap at something like 8 KiB (min(max_line_length, 8 * 1024)). It has to live on the struct next to discarding (async_rw.rs:64-67) rather than in read_line, because receive is polled inside a select! and the read can be cancelled mid-line; a local buffer would lose the prefix on cancellation.
    2. When the terminating newline finally arrives (i.e. after the EndDiscard step), inspect the prefix: it is request-shaped only if it has a top-level "method" and neither "result" nor "error". Notifications and responses therefore stay silent, same as rmcp shouldn't respond to unparseable messages #938. This also means the reply is delayed until the whole oversized line has been drained — which is the right trade-off, you don't want to emit anything before you know what the line was.
    3. Extract the id from the prefix. The prefix is truncated JSON, so serde_json::from_slice::<RxJsonRpcMessage<_>> can't work, but a streaming parse of just the id value does: locate the "id" key, then serde_json::Deserializer::from_slice(&prefix[after_colon..]).into_iter::<RequestId>() and take the first complete value. Number and short-string ids parse without needing the rest of the document.
    4. Carry it on the pending state: PendingErrorResponse::Queue(Option<RequestId>), and pass that id to TxJsonRpcMessage::error(...) instead of None.

    On your open question — if the line is request-shaped but the id is not in the bounded prefix, I'd stay silent rather than send the id-less -32600. An id-less error cannot be correlated by the client (it still times out), and it reopens the #938 error-storm surface for no benefit. If the id is in the prefix, answer -32600 with that id; everything else stays unanswered.

    Tests
    The existing helper in crates/rmcp/tests/test_async_rw_max_line_length.rs:34-37 builds the transport with tokio::io::sink() as the writer, so none of those tests can observe a reply. A fix needs a duplex write half (or a shared buffer) and four cases: id early in the line, id only after a large field (expect silence), notification (silent), response (silent). The padded_request helper already puts the id near the front, so the first case is cheap.

    Unknowns — I have not validated step 3 against ids containing escapes (a "id" string with \"), and I don't know whether the maintainers prefer tying prefix retention to max_line_length or a fixed cap. Both are worth settling before the patch lands.

  5. sai-softwareforest commented on Nov 19, 2026

    @sai-softwareforest

    Thanks @jokemanfire, that's a much clearer picture. I missed that read_line clears the buffer before receive sees anything, so yes, the prefix has to be kept in read_line and live on the struct.

    Agree on silence when the id isn't in the prefix. An id-less -32600 doesn't help the client and just reopens #938.

    One thing on step 3: a plain search for "id" in the prefix could match a nested key inside params, or the text "id" inside a string value. I think it needs a small top-level scan that tracks depth and string state, and only takes id/method/result/error keys at depth 1. Escaped ids themselves should be fine since serde's streaming deserializer handles the escapes once you're at the right offset.

    A fixed cap (8 KiB) seems simpler to reason about than tying it to max_line_length, but happy either way.

    @jordiboehme if you're still on this I'm glad to review. If not, I can put up the four tests with a duplex writer (id early, id after a big field, notification, response) so whichever patch lands has something real to run against.

  6. jordiboehme commented on Nov 19, 2026

    @jordiboehme
    Author

    Thanks @sai-softwareforest and @jokemanfire for the analysis. Sorry, I did not get to open my PR after #1370 was merged. #1471 now does the same as my patch did, and it follows the design from this thread: a bounded prefix, a top-level scan for id and method, and silence when the id is not in the prefix. So I will not open a second PR. I will review #1471 instead.

  7. jordiboehme commented on Nov 19, 2026

    @jordiboehme
    Author

    @sai-softwareforest thanks for the offer. #1471 already has the four cases with a duplex writer: id early (oversized_request_with_early_numeric_id_gets_invalid_request), id after the retained prefix (oversized_request_with_id_after_retained_prefix_stays_silent), and notification and response (oversized_notification_and_response_stay_silent).

    I added two commits on top of #1471, in the branch https://github.com/jordiboehme/rust-sdk/commits/test/oversized-id-after-params

    1. jordiboehme@5267a9d fixes a flaky test. oversized_line_is_logged_once_when_peer_closes failed in about one run of four on macOS, also on the head of fix(transport): reply to oversized stdio requests #1471 (ab9e1d5). Each test set its own subscriber with set_default, and a test on another thread could cache the log call site as never wanted. One global subscriber now counts the events of the thread that asked for them. 40 runs in a row passed.
    2. jordiboehme@ff439c0 covers the TypeScript key order from my review on fix(transport): reply to oversized stdio requests #1471 ({"method":...,"params":...,"jsonrpc":"2.0","id":5}). It keeps a short tail (128 bytes) of the oversized line. When the prefix shows a top-level method but no id, it reads the id from the member right before the final }. Only integers and strings without escapes are read. Tests: id last as a number and as a string, the same read in 7 byte chunks, and silence for an id inside params, an id-like text in a string, a response, no method, an escaped id and a fraction.

    @jonxsong feel free to cherry-pick both into #1471, or tell me if you want them as a separate PR after #1471 is merged.

  8. jonxsong commented on Nov 19, 2026

    @jonxsong

    Thanks for tracking down the tracing race and putting both commits together, @jordiboehme. I reproduced the unterminated-close assertion failure on Windows at ab9e1d5 in 1 of 40 runs of the all-features line-length suite. One subscriber with per-thread counts makes sense here, and I'd keep 5267a9d as a test-only fix so it can land independently of late-ID recovery. Your test report and patches

    The TypeScript-order tests are worth carrying forward. Before using the ID from the tail, I'd want to verify the top-level JSON context across the discarded bytes. PR discussion

  9. jonxsong commented on Nov 19, 2026

    @jonxsong

    @jordiboehme. Let’s handle this in one follow-up PR after #1471 merges. That follow-up can cover the flaky logging test, late IDs in TypeScript requests, and a clearer error message that includes the configured line limit. Your proposed commits

  10. jordiboehme commented on Nov 19, 2026

    @jordiboehme
    Author

    Thanks @jonxsong, agreed. I will open one follow-up PR after #1471 is merged. Instead of the tail, the reader will follow the JSON structure through the discarded bytes with a small fixed state (depth, string and escape state, the current top-level key and at most 128 bytes of a top-level id). A second top-level id, or a top-level result or error, keeps the line unanswered. It will also carry the flaky test fix, the TypeScript order tests and an error message that names the line limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High: significant functionality gap or spec violationT-transportTransport layer changesbugSomething is not workingready for workIssue is well-defined and ready to be picked up

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions