Repository navigation
Conversation
… JSON member bound A version-pinned server (any decisioning serve() seller, or a handler with _adcp_version) advertised its release's bundled response schemas unpruned, ignoring schema_mode. A 3.2 sales seller listed ~106,000 JSON members in 2.5 MB: under the 4 MiB byte budget, over MAX_JSON_MEMBERS (100,000), so every call_tool from an SDK 10 client failed with ADCPResponseTooComplexError (the MCP client lists tools first). Under the default schema_mode="compact", the pinned path now prunes the bundled outputSchema the way Pydantic outputs are pruned: root fields kept, nested required and scalar fields kept, other nested properties re-admitted by name as `true`. Bundled schemas reference arbitrary JSON pointers, so reference targets are kept, `not`/`if`/`contains` and what they reference are copied verbatim, and a loosened `oneOf` is advertised as `anyOf`, keeping the result a relaxation (the MCP client validates structuredContent against it). Request schemas stay exact; "defs"/"inline" keep the exact response schema. The startup tools/list guard now also counts JSON members, warning past half the buyer bound and logging an error past it. Issue repro: 106,250 -> 37,631 members. Decisioning sales seller on 3.1/3.2: 108,030 -> 38,596; on the packaged 3.3.0-beta.1 pin: 122,643 -> 47,119. Fixes #1692 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean PR, no blocking or medium findings.
This change compacts a version-pinned seller's bundled response schemas under the default schema_mode="compact" so tools/list stays inside the SDK buyer's 100,000 JSON-member bound (#1692); request schemas and defs/inline modes stay exact. Reviewer verified _compact_wire_schema is a strict relaxation of the bundled schema (dropped nested optionals → true, loosened oneOf arms advertised as anyOf, not/if/contains + ref targets copied verbatim, dangling ref returns the original schema unchanged). Operational checks passed: memoization keyed by (version,tool), invalidated on loader-state identity, per-caller json.loads copies (no shared mutation); startup guard counts members comparably to the buyer's JsonBoundsScanner and errs high. Semver signal is correct — advertised outputSchema only loosens and actual response data is unchanged, so no buyer stops deserializing. Tests drive a real SDK buyer against a real decisioning seller end to end.
Decision table: no critical/high findings (row 1 n/a); gated_paths false (row 2 n/a); high_risk true but both reasons are (modified) with no medium finding, so rows 3/5 do not fire; no medium findings at all (rows 4/8 n/a); no prior decision (row 6 n/a); no no-auto-approve team match (row 7 n/a). Falls through to row 9 → approve.
Summary
On 10.0.0b1 a sales seller on SDK defaults publishes a
tools/listlarger than the SDK buyer's ownMAX_JSON_MEMBERS = 100_000bound. The MCP client lists tools before everycall_tool, so every call from an SDK 10 client fails withADCPResponseTooComplexError. This PR shrinks the listing and adds a startup guard for the member bound.Root cause
The version-pinned discovery path ignored
schema_mode. A pinned server advertises its release's bundled wire schemas throughget_mcp_schema. Pinned servers include every decisioningserve()seller (PlatformHandleralways has a pin) and any handler that sets_adcp_version. Those bundled response schemas carry every optional nested subtree. On 3.2,get_productsalone is 14,865 members,get_media_buys12,731 andcreate_media_buy12,075. Unpinned handlers already get compact Pydantic outputs, so this only hit pinned servers.What drives the size. The pin decides it, not
supported_versions. For the issue's plain handler (pinned to3.2) the listing is 106,250 members with or withoutsupported_versions. With no pin at all it drops to about 26.5k, which is the "~24,600" case in the issue. On the decisioning path,supported_versionsmatters only because it picks the pin: 3.2 for["3.1", "3.2"], otherwise the packaged 3.3.0-beta.1.I could not reproduce SDK-side growth between b0 and b1. The same configuration gives the same listing on both tags:
_json_bounds/_response_limitare also unchanged between the tags. So the b0 pass in the issue most likely came from a change on the seller or client side, not from the SDK listing.Fix
Compact the pinned
outputSchemaunder the defaultschema_mode="compact"._compact_wire_schemaapplies the same rule as the Pydantic compaction:oneOf/anyOf/allOfarms, are kept;true, so a closed object stays closed and the field inventory survives.Bundled schemas need extra care that Pydantic schemas don't:
#/oneOf/0/properties/fonts/definitions/font_roleand#/$defs/external:core~1format.json/$defs/baseGroupAsset. Any subtree on a path to a reference target is kept, and definitions are dropped only when nothing that survives reaches them. If a reference would still dangle, the schema falls back to the exact bundle (this never triggers on any shipped bundle; covered by a test that sweeps them all).structuredContentagainstoutputSchema, so the compact schema must accept everything the bundle accepts. Loosening insidenot/if/containswould tighten the schema, so those subtrees, and anything they reference, are copied verbatim. AoneOfwhose arms were loosened becomesanyOf, because loosened arms can overlap.Request schemas stay exact: they are the contract buyers build requests from.
schema_mode="defs"/"inline"still advertise the exact bundled response schema. Results are memoized per loader state.Startup guard for the member bound.
warn_if_discovery_payload_is_oversizednow counts JSON members as well as bytes. It uses the same rule as the client'sJsonBoundsScanner(a test pins that it never reads low). Past half of either bound it warns; past either bound it also logs an error that names the bound. It warns rather than refusing to start, like the existing byte check: a buyer without the member bound can still use the agent, and refusing would turn a buyer-specific failure into an outage.Before / after (JSON members of the full
tools/listresponse)supported_versions3.1/3.2)serve(),examples/hello_seller.pysales set, 3.1/3.2serve(), full sales set incl.sync_catalogs, 3.1/3.2serve(), same set, packaged 3.3.0-beta.1 pinAcross every tool, compacted response schemas shrink by 3x to 5x: 3.2 goes from 178,691 to 33,573 members, 3.3.0-beta.1 from 210,469 to 39,821.
Tradeoffs considered
tools/liston the client. Not done here. The member bound protects the buyer from a hostile agent: 4 MiB can hold about 2M members, and the MCP client also compiles everyoutputSchema. A carve-out needs its own safe limit and a security review of its own. One fact argues for doing it as a follow-up:main(9.x) has the same pinned path and an identical 3.2 bundle, so 9.x sellers list the same ~106k members. 9.x clients have no member bound, so 9.x to 9.x works. An SDK 10 buyer calling an unfixed 9.x (or other-SDK) pinned seller will hit this same error. That is a policy call I've left to the maintainers.Tests
tests/test_tools_list_member_bound.py:serve()path (withadcp.server.serve.servecaptured), with and withoutsupported_versions.ADCPClienton defaults callsget_productson a decisioning seller over in-process streamable HTTP, through the client's real response bounds. That coverstools/list,call_tool, and the MCP client'soutputSchemavalidation of the result. Without the fix this test fails withADCPResponseTooComplexError.not/ifstay verbatim,oneOfbecomesanyOf, reference targets are kept.tests/test_mcp_schema_materialization.py: the pinned digests captured from e9a1c8f are the exact definitions, so they are now checked withschema_mode="defs". Compact definitions get their own mutation-isolation check.Local runs:
outputSchema: pass.ruff check src/, black andmypy src/adcp/: clean.Side finding, not changed here: on
next,examples/hello_seller.pyfails boot-time capabilities validation (noaccount.supported_billing) unlessvalidate_at_init=False. No test boots it.Fixes #1692
🤖 Generated with Claude Code