Repository navigation
fix(mcp): cap HTTP/SSE response bodies before SDK parse - #123194
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review CI is green on tip Proof body has live loopback evidence for pre-parse HTTP/SSE body caps before SDK parse. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
654f921 to
ee9b902
Compare
|
Codex review: needs changes before merge. Reviewed August 30, 2026, 12:47 PM ET / 16:47 UTC. ClawSweeper reviewWhat this changesThis PR caps each MCP HTTP response and SSE event at 10 MiB before MCP SDK parsing, while retaining unlimited cumulative bytes across completed SSE events. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open: the new oversized-SSE branch closes the Streamable HTTP transport before the SDK finishes scheduling its reconnect, so it can still make one reconnect request after an oversized event. The existing closed-state handler documents this timing race; the legacy adapter already uses the required next-turn close. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw’s MCP transport adapters obtain server catalogs and tool replies over HTTP or SSE, then pass JSON-RPC messages to the MCP SDK for agent use. This change sits at that network-to-SDK boundary and decides whether an oversized response is rejected before parsing. flowchart LR
Server[MCP server] --> Transport[OpenClaw MCP transport]
Transport --> Kind{HTTP or SSE response}
Kind --> Limit[Per-message byte limit]
Limit --> SDK[MCP SDK parsing]
SDK --> Agent[Agent tool client]
Limit --> Close[Size error and transport closure]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +184, Tests +225. Total +409 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve the approved global 10 MiB boundary, but make both HTTP transport adapters use one terminal oversized-SSE closure sequence that also cancels a reconnect timer armed after the SDK error callback, with a Streamable HTTP regression case. Do we have a high-confidence way to reproduce the issue? Yes. The submitted loopback setup provides a high-confidence transport-level reproduction for oversized HTTP and SSE messages; extend its no-reconnect assertion to Streamable HTTP SSE to reproduce the remaining defect. Is this the best way to solve the issue? No. The pre-parse cap is the right owner boundary, but its Streamable SSE closure must also cancel the SDK timer that can be armed after the error callback returns. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ef5e85385236. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (16 earlier review cycles; latest 8 shown)
|
ee9b902 to
153cab0
Compare
74976cd to
6bb9757
Compare
31b7132 to
3a48f87
Compare
Cap finite tools/list responses and request-correlated catalog SSE events before SDK parsing while preserving long-lived streams and large non-catalog responses. Signed-off-by: Sebastien Tardif <[email protected]>
Narrow JSON-RPC ids before Set.delete, convert EventSource fetch results to web Response, and read unknown callTool content without assertions so check-prod-types, check-test-types, and the SAFETY ratchet pass. Signed-off-by: Sebastien Tardif <[email protected]>
5f0a531 to
d46ae38
Compare
c079f1b to
444d9d4
Compare
Apply the SDK stdio 10 MiB cap to each finite HTTP response and each SSE event while preserving long-lived streams. Signed-off-by: Sebastien Tardif <[email protected]>
a34a429 to
9b13912
Compare
|
Thanks @SebTardif! Proof: A real local MCP server sent 10,486,784-byte JSON and SSE catalogs. This head rejected both before SDK parsing, kept smaller messages working, kept a long-lived SSE stream healthy beyond 10 MiB total, and closed oversized legacy and Streamable HTTP streams without reconnecting.
Example
ClawSweeper move: No deferred second close was added to Streamable HTTP. SDK 1.30 calls |
Cap each finite MCP HTTP response and each SSE event at 10 MiB before SDK parsing, matching the SDK stdio message limit. Keep long-lived SSE streams healthy across bounded events and keepalive comments. Close oversized legacy and Streamable HTTP streams without reconnecting. Co-authored-by: Ayaan Zaidi <[email protected]>
Port from openclaw/openclaw#123194: a hostile or misbehaving remote MCP server could stream an unbounded HTTP catalog/tool-result body that the MCP SDK buffers and JSON-parses before any of Hermes' post-parse limits (resource cap, tool-result truncation) run. New _make_mcp_body_cap_transport wraps the owned httpx AsyncClient's transport on the Streamable HTTP (mcp >= 1.24) and SSE paths: - finite HTTP bodies capped at 10 MiB (Content-Length rejected up front, streamed bodies capped chunk-by-chunk); - each SSE event capped at 10 MiB, with accounting reset at completed event boundaries so long-lived streams/keepalives are unlimited; - violations raise httpx.ReadError naming the byte cap, handled by the existing transport teardown/reconnect path (#66092). verify/cert now live on the inner AsyncHTTPTransport (client-level TLS kwargs are inert once a custom transport is passed); the SSE httpx_client_factory is always injected so the cap applies with default TLS too. Legacy mcp < 1.24 path (SDK-internal client, no hook) stays uncapped — same degradation as strict_redirect_headers.
Port from openclaw/openclaw#123194: a hostile or misbehaving remote MCP server could stream an unbounded HTTP catalog/tool-result body that the MCP SDK buffers and JSON-parses before any of Hermes' post-parse limits (resource cap, tool-result truncation) run. New _make_mcp_body_cap_transport wraps the owned httpx AsyncClient's transport on the Streamable HTTP (mcp >= 1.24) and SSE paths: - finite HTTP bodies capped at 10 MiB (Content-Length rejected up front, streamed bodies capped chunk-by-chunk); - each SSE event capped at 10 MiB, with accounting reset at completed event boundaries so long-lived streams/keepalives are unlimited; - violations raise httpx.ReadError naming the byte cap, handled by the existing transport teardown/reconnect path (#66092). verify/cert now live on the inner AsyncHTTPTransport (client-level TLS kwargs are inert once a custom transport is passed); the SSE httpx_client_factory is always injected so the cap applies with default TLS too. Legacy mcp < 1.24 path (SDK-internal client, no hook) stays uncapped — same degradation as strict_redirect_headers.
What Problem This Solves
An MCP server could send an unbounded HTTP catalog body. OpenClaw passed the full body to the MCP SDK before its existing catalog limits ran, so a hostile server could force excessive memory use during parsing.
Why This Change Was Made
The HTTP transport now applies the MCP SDK's 10 MiB stdio message limit before parsing:
This method-neutral boundary avoids request-ID tracking and JSON scanning. It also means any HTTP or SSE MCP message above 10 MiB now fails, not only
tools/listresponses.Maintainer Decision
Maintainer @obviyus approved the global 10 MiB per-message ceiling for this PR. This intentionally replaces support for HTTP and SSE tool, prompt, or resource replies above 10 MiB with a clear size failure. An oversized SSE event closes its shared transport because continuing after a rejected event would leave the stream state unsafe.
User Impact
Normal MCP catalogs and tool replies continue to work. A server that sends one HTTP response or SSE event above 10 MiB gets a clear size error. An oversized SSE event closes its affected transport and cancels reconnect instead of continuing from a truncated or hostile stream.
Evidence
A real loopback MCP server exercised Streamable HTTP and legacy SSE against exact revisions:
mainaccepted a 10,486,784-byte JSON catalog and the same streamed catalog.MCP HTTP response exceeds 10485760 bytes.mainand pass on this head.Focused checks:
Closes #101554