Repository navigation
docs(security): default agent response cap to 4 MiB and keep discovery responses small - #8200
Merged
Merged
Conversation
…y responses small The Go, TypeScript, Python and Java SDKs and the hosted grader all ship a 4 MiB default, so raise the MCP and A2A whole-call defaults from 1 MiB to match. 4 MiB stays the ceiling on what any default may be, and a tighter default stays conformant. This loosens a limit: a client still enforcing 1 MiB rejects a response a 3.3 client accepts. Aligning the defaults raises no path-specific cap. The precedence list now also names the attestation resolution fetch cap, the max_embedded_credential_bytes ceiling, the format_schema and adagents.json publisher-origin cap, and the A2A auth-challenge cap. Correct two sub-default figures that would otherwise have become the real cap: - A2A's per-DataPart bound was 1 MiB. The single-artifact invariant makes the authoritative DataPart the whole response, so a tighter per-part number silently became the effective A2A cap and rejected over A2A what the byte-identical MCP call accepts. It is now the call limit, with the reasoning stated so it is not "fixed" back. - The MCP extraction algorithm hard-coded a 1 MB content[].text check. For a server that returns only content[].text, that item is the entire response. It is now the configured limit. Two bounds gain the detail the 4x raise makes load-bearing: an aggregate budget covers nodes as well as bytes and is not the per-call default multiplied by concurrency, and depth and node bounds do not limit the length of a single scalar, so per-field length limits are what keep a 4 MiB string out of a log or a model context. Add the seller-side counterpart. Agents SHOULD keep tools/list, get_adcp_capabilities and the agent card well under the default client cap and paginate large catalogs. Discovery is where oversize makes an agent unreachable rather than slow, and the recourse differs per surface: the agent card has no narrowing lever, tools/list page size is the server's choice, and get_adcp_capabilities narrows with protocols[] but the signing-key discovery path does not — so a capabilities document over MAX_CAPABILITIES_BYTES fails request_signature_capabilities_unreachable and makes signing keys unresolvable. The agent-card target is marked editorial rather than a cap a client may enforce, and the capabilities target is scoped to agents that sign. Flags two tensions found in review: #8197 (a third party can inflate publisher_domains past the capabilities budget and break key discovery) and #8198 (supported_formats pushes creative agents past the same budget). Refs: #8190 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — docs/spec-only PR raising the client response-size default from 1 MiB to 4 MiB across the MCP and A2A transport profiles, with migration/whats-new updates, seller-side discovery guidance, and matching tests.
What I checked:
- No
static/schemas/source/**touched, so no schema↔docs drift, oneOf discriminator, or dist-immutability concern applies. - The
minorchangeset is present and correctly scoped — loosening a client-enforced default to codify SDK behavior is non-breaking (existing tighter clients stay conformant), so this is not a Breaking-class change and the hard gate does not fire. - Reviewer spot-checked every newly-cited cap (256 KB auth-challenge, 1 MiB format_schema/adagents, 1 MiB attestation resolution, 64 KiB MAX_CAPABILITIES_BYTES) and the
request_signature_capabilities_unreachableerror code against base — all accurate; new heading anchors resolve. - No blocking or medium findings.
high_risk is true only because two docs/reference/** files were (modified); with no medium-or-higher findings on those files, the modification is presumed safe (no deletions). gated_paths is false, and no no-auto-approve team match. None of decision rows 1–8 fire, so the outcome falls through to row 9: approve.
bokelley
added a commit
to adcontextprotocol/adcp-client-python
that referenced
this pull request
Oct 15, 2026
adcp#8200 aligned the spec and removed the hard-coded 1 MB `content[].text` check from the MCP extraction algorithm. The reason is specific: for a server that answers with `content[].text` and no `structuredContent`, that one item *is* the whole response, so a per-text limit tighter than the call limit silently becomes the effective call cap. This SDK shipped exactly that — `_MAX_TEXT_SIZE_BYTES = 1_048_576` — so a text-fallback server was bounded at 1 MiB no matter what `max_response_bytes` said, and a 2 MiB response failed under a 4 MiB default. The bound is now the configured per-call budget, resolved through `resolve_max_response_bytes` so a `TaskOptions` override reaches the post-parse check too, and `None` disables it exactly as it does on the transport. It raises rather than skipping. A skipped item left extraction reporting "no structured data found", which a caller cannot tell from a server that genuinely sent none — worse, when a later item parsed, the oversized one vanished entirely and the call succeeded on whatever followed it. Spec §Response Size Bounds (7) requires the distinct error instead. Bytes, not characters: the budget is a wire figure, so the check measures UTF-8 length, skipping the encode for any string short enough that it cannot matter. The error path shares the budget for the same reason — `isError: true` plus a giant payload is the same allocation primitive, and the 4 KiB `adcp_error` cap only applies after `json.loads` has already run. A2A has no equivalent per-part figure; nothing to change there. Refs #1503, adcontextprotocol/adcp#8200 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
bokelley
added a commit
to adcontextprotocol/adcp-client-python
that referenced
this pull request
Oct 15, 2026
… live path
Both review passes landed on the same two things.
The guard allocated what it was defending against. Past the `limit // 4`
short-circuit it encoded unconditionally, so a 64 MiB text item under a
4 MiB budget peaked at 64 MiB of transient `bytes` to conclude 4 MiB was
exceeded — 16x the budget, and the one place in this PR that broke the
discipline `_response_limit.py` states for itself. UTF-8 is at least one
byte per character, so `len(text) > limit` already proves the overrun; the
encode is now the last resort, reached only for a string already known to be
within a factor of four, and `received` reads as the lower bound the message
already called it.
`from_mcp_client()` was documented as uncapped while the new bound applied to
it — and applied to only one of its two extraction paths, decided by whether
the in-process server happened to emit `structuredContent` or text. The
contradiction resolves toward keeping the bound, because that session is
exactly where it is load-bearing: this SDK does not own that transport, so
nothing counted those bytes on the way in. `from_mcp_client()` now takes
`max_response_bytes`, and the docstring and README say which half of the
budget applies. The asymmetry with `structuredContent` stays and is now
explained: it arrives already parsed by the MCP SDK, so its allocation has
happened before any SDK code runs.
Both reviews also noted the end-to-end tests passed without reaching the
code they test — the transport pre-rejects on the declared Content-Length,
and `caught.value.limit` cannot tell the layers apart. They now assert
`declared`, and an injected-session test covers the raise on the only path
that can reach it. Deleting the bound fails 8 tests; it failed none of the
end-to-end ones before.
Smaller, from the same reviews:
- `max_response_bytes=None` removed the last backstop silently. Spec
§Response Size Bounds (8) asks that calls made without a bound be logged;
it now says so once per agent.
- `f"Got content: {result.content}"` put up to a whole budget of unhygienated
server text into `TaskResult.error`, which in an agentic buyer goes
straight into a model context — the leak class point 7 forbids, one branch
from where this PR gets it right. Bounded to 512 characters.
- `ADCPResponseTooLargeError`'s docstring promised the body was never
buffered, which stopped being true of every path.
- Tests for the astral-plane case that makes `limit // 4` exactly tight, a
lone surrogate (which would crash the guard without `surrogatepass`), the
equality boundary, and `structuredContent` winning over an over-budget
text item.
- The CHANGELOG now states that two public functions raise where they used
to return `None`.
Refs #1503, adcontextprotocol/adcp#8200
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
bokelley
added a commit
to adcontextprotocol/adcp-client-python
that referenced
this pull request
Oct 15, 2026
* feat(client): cap agent response size by default Agent responses are untrusted input. A seller answering one tool call with tens of megabytes could exhaust a buyer's memory long before any parser ran: nothing on the MCP or A2A call path bounded a response body, and the existing 1 MiB `_MAX_TEXT_SIZE_BYTES` check only skipped oversized `content[].text` after the whole result was already in memory. Add `AgentConfig.max_response_bytes`, defaulting to 4 MiB, and enforce it in a size-limiting httpx transport installed under every client the adapters build — MCP streamable HTTP, MCP SSE, the MCP session-close DELETE, and A2A (JSON-RPC, streamed events, and the agent card). The budget is enforced while the body is read: an over-cap `Content-Length` is refused before the first body byte, and decoded bytes are counted as they arrive so a compression bomb trips on the chunk that expands past the cap. SSE is measured per event as well as cumulatively per call, so a peer cannot slip a large payload past the budget by replying with `Content-Type: text/event-stream`. Only `gzip`/`deflate` are requested, and a response in another coding is refused rather than expanded unmeasured. An oversized response raises the new `ADCPResponseTooLargeError` and is never truncated. Both adapters recover the typed error from the transport failures that bury it — MCP's anyio writer task reports a `CancelledError`, and `a2a-sdk` rewraps as its own error type. Override per agent with `AgentConfig.max_response_bytes`, per call with `TaskOptions(max_response_bytes=...)`, or opt out with `AgentConfig.max_response_bytes=None`. Closes #1503 Refs adcontextprotocol/adcp#8190 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(client): close the response-cap gaps found in review Expert code review and security review of the previous commit each found ways the budget could be evaded, mis-scoped, or lost. Surfacing. An oversized *handshake* escaped as a bare `asyncio.CancelledError` — the cancellation branch in `_get_session` ran before the budget check, and a limiter abort inside MCP's writer task arrives precisely as a cancellation. `tools/list` and `get_agent_info` had no conversion at all, so an oversized tool listing killed them the same way. Both now run through one helper that also balances the swallowed cancellation with `Task.uncancel()`, and the unsupported-coding rejection is typed (`ADCPResponseEncodingError`) so it travels the same path. Scope. The cumulative cap was per HTTP response, but MCP's legacy SSE transport and its standalone notification stream carry a whole session on one `GET` body — so a healthy long session would eventually fail. A session- lifetime `GET` event-stream is now capped per event only; a per-call body (including the event-stream answer to a streamable-HTTP POST) keeps both caps. A per-call `TaskOptions` override no longer reaches that background stream, where MCP's context snapshot would have let it outlive its call and rebind the budget for the rest of the session. Containment. `ADCPMultiAgentClient` fanned out with bare `asyncio.gather`, so one hostile seller padding a reply discarded every honest seller's results. A budget rejection now becomes that agent's failed `TaskResult`; every other exception keeps abort-on-first-exception. The limiter itself. It asked zlib for the whole remaining budget in one call and copied the result, allocating 2x the budget to measure a bomb — it now decodes in 64 KiB slices and keeps decoded bytes only when SSE needs them. Concatenated gzip/deflate members are counted whole instead of stopping at the first. Compressed bodies get a wire ceiling, so a stream padded with empty deflate blocks cannot run forever under a decoded-bytes budget. `identity` is no longer read as an extra coding, and the URL in the error message is stripped of userinfo, query and fragment. Installation fails closed on the SDK's own clients and warns on an adopter's: a custom `httpx_client_factory` may return a duck-typed client this SDK cannot reach into, which stays supported but is no longer silently uncapped. Refs #1503, adcontextprotocol/adcp#8190 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(client): propagate the encoding rejection typed on every path Review found the MCP tool-call path listing only `ADCPResponseTooLargeError` in its re-raise tuple, so an unmeasurable-coding rejection fell through to `TaskResult(FAILED)` there while A2A and MCP's own session paths raised it. The body was still refused either way — only the typed surface diverged by protocol. Both now share `_BUDGET_ERRORS`, with a test on the tool-call path. Also narrow the two `except BaseException` handlers to `(Exception, asyncio.CancelledError)`: the cancellation is the one base exception that has to be caught, because that is how a limiter abort inside MCP's writer task reaches the awaiting call. `GeneratorExit`, `KeyboardInterrupt` and `SystemExit` now propagate as they should. Drop a redundant local `import asyncio` in the new fan-out helper. Refs #1503 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(client): bound content[].text by the call budget, not a fixed 1 MiB adcp#8200 aligned the spec and removed the hard-coded 1 MB `content[].text` check from the MCP extraction algorithm. The reason is specific: for a server that answers with `content[].text` and no `structuredContent`, that one item *is* the whole response, so a per-text limit tighter than the call limit silently becomes the effective call cap. This SDK shipped exactly that — `_MAX_TEXT_SIZE_BYTES = 1_048_576` — so a text-fallback server was bounded at 1 MiB no matter what `max_response_bytes` said, and a 2 MiB response failed under a 4 MiB default. The bound is now the configured per-call budget, resolved through `resolve_max_response_bytes` so a `TaskOptions` override reaches the post-parse check too, and `None` disables it exactly as it does on the transport. It raises rather than skipping. A skipped item left extraction reporting "no structured data found", which a caller cannot tell from a server that genuinely sent none — worse, when a later item parsed, the oversized one vanished entirely and the call succeeded on whatever followed it. Spec §Response Size Bounds (7) requires the distinct error instead. Bytes, not characters: the budget is a wire figure, so the check measures UTF-8 length, skipping the encode for any string short enough that it cannot matter. The error path shares the budget for the same reason — `isError: true` plus a giant payload is the same allocation primitive, and the 4 KiB `adcp_error` cap only applies after `json.loads` has already run. A2A has no equivalent per-part figure; nothing to change there. Refs #1503, adcontextprotocol/adcp#8200 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(client): bound the extraction guard's own allocation and name its live path Both review passes landed on the same two things. The guard allocated what it was defending against. Past the `limit // 4` short-circuit it encoded unconditionally, so a 64 MiB text item under a 4 MiB budget peaked at 64 MiB of transient `bytes` to conclude 4 MiB was exceeded — 16x the budget, and the one place in this PR that broke the discipline `_response_limit.py` states for itself. UTF-8 is at least one byte per character, so `len(text) > limit` already proves the overrun; the encode is now the last resort, reached only for a string already known to be within a factor of four, and `received` reads as the lower bound the message already called it. `from_mcp_client()` was documented as uncapped while the new bound applied to it — and applied to only one of its two extraction paths, decided by whether the in-process server happened to emit `structuredContent` or text. The contradiction resolves toward keeping the bound, because that session is exactly where it is load-bearing: this SDK does not own that transport, so nothing counted those bytes on the way in. `from_mcp_client()` now takes `max_response_bytes`, and the docstring and README say which half of the budget applies. The asymmetry with `structuredContent` stays and is now explained: it arrives already parsed by the MCP SDK, so its allocation has happened before any SDK code runs. Both reviews also noted the end-to-end tests passed without reaching the code they test — the transport pre-rejects on the declared Content-Length, and `caught.value.limit` cannot tell the layers apart. They now assert `declared`, and an injected-session test covers the raise on the only path that can reach it. Deleting the bound fails 8 tests; it failed none of the end-to-end ones before. Smaller, from the same reviews: - `max_response_bytes=None` removed the last backstop silently. Spec §Response Size Bounds (8) asks that calls made without a bound be logged; it now says so once per agent. - `f"Got content: {result.content}"` put up to a whole budget of unhygienated server text into `TaskResult.error`, which in an agentic buyer goes straight into a model context — the leak class point 7 forbids, one branch from where this PR gets it right. Bounded to 512 characters. - `ADCPResponseTooLargeError`'s docstring promised the body was never buffered, which stopped being true of every path. - Tests for the astral-plane case that makes `limit // 4` exactly tight, a lone surrogate (which would crash the guard without `surrogatepass`), the equality boundary, and `structuredContent` winning over an over-budget text item. - The CHANGELOG now states that two public functions raise where they used to return `None`. Refs #1503, adcontextprotocol/adcp#8200 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #8192 (
d1fa747d9), implementing three maintainer decisions. Tracking issue: #8190.Decisions implemented
tools/list,get_adcp_capabilitiesand the A2A agent card well under the default client cap, and paginate large catalogs.Two sub-default figures that would have made the raise cosmetic
Review caught these, and they are the substantive part of the PR.
A2A's per-DataPart 1 MiB had to move. The instruction was to leave it alone unless it contradicts the whole-call text — it does.
a2a-response-extraction.mdxstates the single-artifact invariant: an AdCP task produces one artifact, and the last DataPart in it is the authoritative response. So the authoritative part is the whole payload; the bounds do not compose. A 1 MiB per-part figure would have silently become the effective A2A cap and rejected over A2A exactly what the byte-identical MCP call accepts — the transport divergence this bound exists to prevent, relocated rather than removed. It is now the call limit, with the reasoning written into the page so it is not "corrected" back. Earlier DataParts are superseded progress snapshots and a client MAY bound those more tightly.MCP had the same bug, untouched by the original PR. The normative extraction algorithm hard-codes a 1 MB check on
content[].text. For a server that returns onlycontent[].text, that item is the entire response, so raising the streamed cap to 4 MiB would have changed nothing for those servers. Now the configured limit, with the reference implementation intests/mcp-response-extraction.test.cjskept in sync.Two bounds the 4x raise makes load-bearing
Corrections to claims in the first draft of this PR
security.mdxplaces the agent card under the general bound — which this PR just set to 4 MiB. A client implementer could have read the table as a reject threshold and become non-interoperable with conformant agents. It is now explicitly an editorial target, by analogy withMAX_JWKS_BYTES/MAX_CAPABILITIES_BYTES, with "a client MUST NOT reject an agent card at 64 KiB" stated outright. The migration-guide sentence is split so the normative 64 KiB is not conflated with the advisory one.get_adcp_capabilities.protocols[]narrows it. The text now distinguishes per-surface recourse: the agent card has no narrowing lever (and the authenticated extended card is larger),tools/listpage size is the server's choice since MCP'scursorhas no page-size parameter, and capabilities can be narrowed — but the signing-key discovery path does not narrow, which is the case that matters.#agent-key-publication, which never mentionsMAX_CAPABILITIES_BYTES. Retargeted, andrequest_signature_capabilities_unreachableis now named so a reader can verify the chain.Loosening documented on the brand.json precedent
This loosens a limit, which the migration guide previously said only brand.json did. Added
### Client response-size default rises to 4 MiBmodeled on#brand-json-size-cap-rises-to-2-mib, including the transition-window rule that has no analogue otherwise: a seller spending the new headroom still breaks against every 3.2-era 1 MiB client, with no protocol error it can see. Also added the 3.3 feature-narrative entry that #8192 never wrote, which3-2-to-3-3.mdxalready pointed readers to.The precedence list now also names the attestation resolution fetch cap, the
max_embedded_credential_bytesceiling, theformat_schema/adagents.jsonpublisher-origin cap, and the A2A auth-challenge cap, since that paragraph is the sole assertion that 4 MiB did not move them.Follow-ups filed
get_adcp_capabilitiespastMAX_CAPABILITIES_BYTESand break its signing-key discovery.publisher_domainshas nomaxItemsand is populated from publishers' ownadagents.json, which any domain owner writes unilaterally. ~1,600–2,600 domains clears 64 KiB. Availability and authentication failure caused by a party with no relationship to the victim.supported_formatsreplaced the pageablelist_creative_formats, so the spec pushes creative agents toward a capabilities document larger than the 64 KiB that gates key discovery.Both are referenced from the new docs section as known tensions.
Tests
tests/response-size-bounds.test.cjsis at 42 assertions, all mutation-checked. New guard: no L0 transport profile may state a byte figure below the whole-call default without a justification clause — the invariant both transports had broken.Local:
test:contracts,test:docs-nav,test:doc-compliance-drift,test:compliance-snippets,lint:schema-links,test:json-schema, test-coverage registration, and the full pre-commit hook all pass.test:snippetshas 12 pre-existing failures inget_products.mdx,sync_creatives.mdxandtestable-examples-demo.md— files not touched here, which execute against a hosted test agent.Reviewed before opening by an ad-tech-protocol-expert and a security-reviewer agent; every finding is implemented or answered above.
🤖 Generated with Claude Code
Open workspace in Conductor