Skip to content

fix(mcp): cap HTTP/SSE response bodies before SDK parse - #123194

Merged
obviyus merged 3 commits into
openclaw:mainfrom
SebTardif:fix/101554-mcp-tools-list-preparse-limit
Aug 30, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
SebTardif:fix/101554-mcp-tools-list-preparse-limit

Conversation

@SebTardif

@SebTardif SebTardif commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Each finite HTTP response has a 10 MiB limit.
  • Each Server-Sent Events (SSE) event has a 10 MiB limit.
  • Long-lived SSE connections have no cumulative byte limit. Completed keepalive comments and completed events reset their accounting.

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/list responses.

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:

  • Current main accepted a 10,486,784-byte JSON catalog and the same streamed catalog.
  • This head rejected the JSON catalog before SDK parsing with MCP HTTP response exceeds 10485760 bytes.
  • This head rejected the streamed catalog event and closed the affected stream.
  • JSON and SSE catalogs below 10 MiB passed.
  • A legacy SSE connection accepted 10,519,491 cumulative keepalive bytes, then delivered a tool catalog on the same connection.
  • A legacy SSE connection closed after one oversized event and made no reconnect request.
  • The two oversized-message regression tests fail on current main and pass on this head.
  • The legacy SSE closure regression fails on the prior head and passes on this head.

Focused checks:

node scripts/run-vitest.mjs src/agents/mcp-http-transport.test.ts
node scripts/run-vitest.mjs src/agents/mcp-transport.test.ts
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/mcp-http-transport.ts src/agents/mcp-http-transport.test.ts
git diff --check

Closes #101554

@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Aug 13, 2026
@SebTardif

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

CI is green on tip 85b5a605b77 (knip unused-export fix: size-limit helpers unexported; tests assert error.code locally).

Proof body has live loopback evidence for pre-parse HTTP/SSE body caps before SDK parse.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@SebTardif
SebTardif force-pushed the fix/101554-mcp-tools-list-preparse-limit branch 2 times, most recently from 654f921 to ee9b902 Compare August 14, 2026 01:14
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 30, 2026, 12:47 PM ET / 16:47 UTC.

ClawSweeper review

What this changes

This 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 provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Needs maintainer review before merge - 5 items remain

Keep 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
Reviewed head: 9b13912dc094ed06bf797709faac4a451f3300e3

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has strong reported loopback proof for the intended cap, but a P1 Streamable reconnect defect remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body describes after-fix real loopback MCP runs through the HTTP and legacy-SSE adapters, observing pre-parse rejection, under-limit success, and legacy no-reconnect behavior; that evidence is sufficient for the cap itself, but does not exercise the missing Streamable HTTP no-reconnect scenario.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body describes after-fix real loopback MCP runs through the HTTP and legacy-SSE adapters, observing pre-parse rejection, under-limit success, and legacy no-reconnect behavior; that evidence is sufficient for the cap itself, but does not exercise the missing Streamable HTTP no-reconnect scenario.
Evidence reviewed 7 items Introduced reconnect gap: The new oversized-SSE condition calls close immediately, but omits the next-turn SDK close used to cancel a reconnect timer armed after the error callback returns.
Established lifecycle invariant: The adjacent closed-state error path explicitly documents that an SDK reconnect callback can arm a timer after close clears the old one, and schedules a deferred second close to handle it.
Legacy sibling handles this case: The legacy SSE adapter’s new oversized-event branch performs the immediate close and a next-turn underlying transport close; the Streamable HTTP branch should preserve the same no-reconnect invariant.
Findings 1 actionable finding [P1] Cancel Streamable HTTP's deferred reconnect after overflow
Security None None.

How this fits together

OpenClaw’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]
Loading

Before merge

  • Cancel Streamable HTTP's deferred reconnect after overflow (P1) - The new overflow branch closes immediately, but the adjacent closed-state path documents that the SDK can arm its reconnect timer only after this callback returns. Unlike the legacy adapter, this branch never closes again on the next turn, so an oversized SSE event can still issue a follow-up GET. Reuse that terminal-close sequence and cover it with a one-request assertion.
  • Resolve merge risk (P1) - An oversized Streamable HTTP SSE response can trigger a reconnect after the wrapper closes, contrary to the intended terminal handling of unsafe stream state.
  • Resolve merge risk (P1) - The global 10 MiB ceiling intentionally makes previously accepted larger MCP replies fail; the PR body records maintainer approval, but this remains an upgrade compatibility change.
  • Resolve merge risk (P1) - Production changes are +184/-4 lines versus tests +225/-0; the necessary byte-boundary logic should avoid diverging reconnect handling between the two transport adapters.
  • Resolve merge risk (P1) - MCP SDK 1.30.0 source was unavailable in this checkout and remote retrieval failed due DNS, so the final repair should re-check its reconnect callback contract against the installed dependency.

Findings

  • [P1] Cancel Streamable HTTP's deferred reconnect after overflow — src/agents/mcp-http-transport.ts:335-339
Agent review details

Security

None.

PR surface

Source +184, Tests +225. Total +409 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 188 4 +184
Tests 1 225 0 +225
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 413 4 +409

Review metrics

Metric Value Why it matters
Production versus tests production +184/-4; tests +225/-0 The substantial new transport framing logic needs the missing Streamable no-reconnect boundary test before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #101554
Summary: This PR explicitly proposes the implementation for the open oversized-MCP-response issue, but the remaining reconnect defect means it is not yet a complete candidate fix.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Cancel Streamable reconnect after overflow (recommended)
    Add the same next-turn underlying-close behavior to the Streamable HTTP oversized-SSE path and prove it makes no follow-up GET request.
  2. Pause the response-cap change
    Pause this branch if the SDK reconnect lifecycle cannot be verified against version 1.30.0 before landing.

Technical review

Best 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:

  • [P1] Cancel Streamable HTTP's deferred reconnect after overflow — src/agents/mcp-http-transport.ts:335-339
    The new overflow branch closes immediately, but the adjacent closed-state path documents that the SDK can arm its reconnect timer only after this callback returns. Unlike the legacy adapter, this branch never closes again on the next turn, so an oversized SSE event can still issue a follow-up GET. Reuse that terminal-close sequence and cover it with a one-request assertion.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ef5e85385236.

Labels

Label justifications:

  • P1: The introduced closure gap can make a hostile oversized Streamable SSE response reconnect against an active MCP server.
  • merge-risk: 🚨 compatibility: The approved global response ceiling changes runtime behavior for existing MCP servers that return a single reply over 10 MiB.
  • merge-risk: 🚨 availability: The Streamable HTTP error path can reconnect after an oversized SSE event instead of remaining terminal.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body describes after-fix real loopback MCP runs through the HTTP and legacy-SSE adapters, observing pre-parse rejection, under-limit success, and legacy no-reconnect behavior; that evidence is sufficient for the cap itself, but does not exercise the missing Streamable HTTP no-reconnect scenario.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body describes after-fix real loopback MCP runs through the HTTP and legacy-SSE adapters, observing pre-parse rejection, under-limit success, and legacy no-reconnect behavior; that evidence is sufficient for the cap itself, but does not exercise the missing Streamable HTTP no-reconnect scenario.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/agents/mcp-http-transport.test.ts.
  • [P1] node scripts/run-vitest.mjs src/agents/mcp-transport.test.ts.
  • [P1] node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/agents/mcp-http-transport.ts src/agents/mcp-http-transport.test.ts.
  • [P1] git diff --check.

What I checked:

  • Introduced reconnect gap: The new oversized-SSE condition calls close immediately, but omits the next-turn SDK close used to cancel a reconnect timer armed after the error callback returns. (src/agents/mcp-http-transport.ts:335, 9b13912dc094)
  • Established lifecycle invariant: The adjacent closed-state error path explicitly documents that an SDK reconnect callback can arm a timer after close clears the old one, and schedules a deferred second close to handle it. (src/agents/mcp-http-transport.ts:320, 9b13912dc094)
  • Legacy sibling handles this case: The legacy SSE adapter’s new oversized-event branch performs the immediate close and a next-turn underlying transport close; the Streamable HTTP branch should preserve the same no-reconnect invariant. (src/agents/mcp-http-transport.ts:233, 9b13912dc094)
  • Missing Streamable regression coverage: The added no-reconnect test covers legacy SSE only; no equivalent Streamable HTTP SSE response proves the new branch cancels a deferred reconnect. (src/agents/mcp-http-transport.test.ts:240, 9b13912dc094)
  • Caller and boundary: The MCP transport factory instantiates these adapters for configured streamable-HTTP and legacy SSE servers, so a reconnect reaches the configured server boundary. (src/agents/mcp-transport.ts:206, 9b13912dc094)
  • Real behavior evidence: The PR body records exact-head loopback results for over-limit and under-limit HTTP/SSE responses, including legacy SSE closure and no reconnect; it does not cover the Streamable HTTP reconnect case identified here. (src/agents/mcp-http-transport.test.ts:115, 9b13912dc094)

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add the deferred second close to the Streamable HTTP oversized-SSE path and prove a malicious event produces no follow-up GET request.
  • Recheck the final implementation against the installed MCP SDK 1.30.0 reconnect source or types before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (16 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-15T23:33:51.810Z sha 6d9e333ed32708dfdce00a9f267a2fd304aa90f1 :: needs real behavior proof before merge. :: [P1] Scope the cap to outgoing tools/list requests | [P1] Bound streamed tools/list results without ending SSE connections
  • reviewed 2026-08-19T13:16:02.612Z sha 6d9e333ed32708dfdce00a9f267a2fd304aa90f1 :: needs real behavior proof before merge. :: [P1] Scope the cap to outgoing tools/list requests | [P1] Cap streamed tools/list responses too
  • reviewed 2026-08-25T13:25:02.821Z sha 6d9e333ed32708dfdce00a9f267a2fd304aa90f1 :: needs real behavior proof before merge. :: [P1] Scope the cap to tools/list requests | [P1] Bound streamed tools/list messages
  • reviewed 2026-08-25T13:50:18.970Z sha 6d9e333ed32708dfdce00a9f267a2fd304aa90f1 :: needs real behavior proof before merge. :: [P1] Scope the cap to outgoing tools/list requests | [P1] Cap streamed tools/list responses too
  • reviewed 2026-08-30T15:13:10.166Z sha c7eaabcb03af7076656eda10039afaf4fc5fbd2f :: needs real behavior proof before merge. :: [P1] Preserve large non-catalog streamed results
  • reviewed 2026-08-30T15:26:51.939Z sha 31b71327a14eefea2873493a878450b7d24132ca :: needs real behavior proof before merge. :: [P1] Preserve unrelated SSE replies while a catalog request is pending
  • reviewed 2026-08-30T15:45:11.893Z sha 3a48f87e9698c0ddbfafe1a5874d38331f6cb7dd :: found issues before merge. :: [P1] Preserve late-ID non-catalog SSE replies
  • reviewed 2026-08-30T16:09:51.225Z sha 5f0a531bca037ac252d82e81e32a698029560fef :: found issues before merge. :: [P1] Preserve late-ID non-catalog SSE replies

@SebTardif
SebTardif force-pushed the fix/101554-mcp-tools-list-preparse-limit branch from ee9b902 to 153cab0 Compare August 14, 2026 18:37
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes size: L and removed size: M labels Aug 14, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@SebTardif
SebTardif force-pushed the fix/101554-mcp-tools-list-preparse-limit branch from 74976cd to 6bb9757 Compare August 14, 2026 19:40
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed gateway Gateway runtime cli CLI command changes size: L labels Aug 14, 2026
@obviyus
obviyus force-pushed the fix/101554-mcp-tools-list-preparse-limit branch 3 times, most recently from 31b7132 to 3a48f87 Compare August 30, 2026 15:30
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 30, 2026
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]>
@obviyus
obviyus force-pushed the fix/101554-mcp-tools-list-preparse-limit branch from 5f0a531 to d46ae38 Compare August 30, 2026 16:14
@obviyus
obviyus force-pushed the fix/101554-mcp-tools-list-preparse-limit branch 2 times, most recently from c079f1b to 444d9d4 Compare August 30, 2026 16:26
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]>
@obviyus
obviyus force-pushed the fix/101554-mcp-tools-list-preparse-limit branch from a34a429 to 9b13912 Compare August 30, 2026 16:37
@obviyus

obviyus commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Bug: A hostile MCP server could make OpenClaw buffer and parse an unbounded HTTP catalog response.
  • Fix: The transport now caps each finite HTTP response and each SSE event at 10 MiB, matching the SDK stdio message limit.

Example

Before After
A 10.49 MiB catalog reached the SDK parser. The response stops at 10 MiB with a clear size error.
Long-lived streams had no safe per-event boundary. Small events and keepalives can run indefinitely; one oversized event closes without reconnecting.

ClawSweeper move: No deferred second close was added to Streamable HTTP. SDK 1.30 calls onerror, then checks its abort signal before scheduling reconnect. OpenClaw's immediate close aborts that signal synchronously. The loopback proof observed streamGetCount=1 after an oversized session GET. The installed SDK 1.30 source and types were rechecked before landing.

@obviyus
obviyus merged commit 86b6ec0 into openclaw:main Aug 30, 2026
266 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
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]>
teknium1 added a commit to NousResearch/hermes-agent that referenced this pull request Sep 14, 2026
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.
teknium1 added a commit to NousResearch/hermes-agent that referenced this pull request Sep 14, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Oversized HTTP/SSE MCP tool-list responses can block the Gateway before catalog limits apply

2 participants