Skip to content

fix(server): keep a pinned seller's tools/list inside the SDK buyer's JSON member bound - #1700

Closed
bokelley wants to merge 1 commit into
nextfrom
bokelley/fix-1692-tools-list-bound
Closed

bokelley wants to merge 1 commit into
nextfrom
bokelley/fix-1692-tools-list-bound

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

On 10.0.0b1 a sales seller on SDK defaults publishes a tools/list larger than the SDK buyer's own MAX_JSON_MEMBERS = 100_000 bound. The MCP client lists tools before every call_tool, so every call from an SDK 10 client fails with ADCPResponseTooComplexError. 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 through get_mcp_schema. Pinned servers include every decisioning serve() seller (PlatformHandler always has a pin) and any handler that sets _adcp_version. Those bundled response schemas carry every optional nested subtree. On 3.2, get_products alone is 14,865 members, get_media_buys 12,731 and create_media_buy 12,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 to 3.2) the listing is 106,250 members with or without supported_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_versions matters 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:

Configuration v10.0.0-beta.0 v10.0.0-beta.1
Issue repro, pinned to 3.2 106,250 106,250
Decisioning seller, 3.1/3.2 108,030 108,030

_json_bounds / _response_limit are 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

  1. Compact the pinned outputSchema under the default schema_mode="compact". _compact_wire_schema applies the same rule as the Pydantic compaction:

    • fields at the root, and in the root's oneOf/anyOf/allOf arms, are kept;
    • nested required and scalar fields are kept;
    • every other nested property is re-admitted by name as true, so a closed object stays closed and the field inventory survives.

    Bundled schemas need extra care that Pydantic schemas don't:

    • Arbitrary pointers. They reference pointers like #/oneOf/0/properties/fonts/definitions/font_role and #/$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).
    • Staying a relaxation. The MCP client validates structuredContent against outputSchema, so the compact schema must accept everything the bundle accepts. Loosening inside not/if/contains would tighten the schema, so those subtrees, and anything they reference, are copied verbatim. A oneOf whose arms were loosened becomes anyOf, 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.

  2. Startup guard for the member bound. warn_if_discovery_payload_is_oversized now counts JSON members as well as bytes. It uses the same rule as the client's JsonBoundsScanner (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/list response)

Seller Before After
Issue repro (11 tools, pinned to 3.2, supported_versions 3.1/3.2) 106,250 (2.52 MB) 37,631 (0.96 MB)
Decisioning serve(), examples/hello_seller.py sales set, 3.1/3.2 108,030 37,111
Decisioning serve(), full sales set incl. sync_catalogs, 3.1/3.2 — 38,596
Decisioning serve(), same set, packaged 3.3.0-beta.1 pin 122,643 (hello_seller set) 47,119
Plain sales handler (12 tools): pinned 3.1 / 3.2 / 3.3.0-beta.1 / unpinned — 22,918 / 39,152 / 47,895 / 28,151

Across 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

  • Exempting or separately bounding tools/list on 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 every outputSchema. 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.
  • Compacting pinned request schemas as well. That would roughly halve the listing again (3.2 sales inputs go from about 29k to 6k members). But it drops nested optional request fields that buyer agents use to build requests. Inputs are now the dominant cost, so this is the next lever if headroom shrinks.
  • Headroom. The new invariant test keeps a default sales seller under half the bound, the same threshold the server warns at. 3.2 sits at about 39k, but the packaged 3.3.0-beta.1 pin sits at about 47.9k, close to the 50k ceiling. If a later 3.3 bundle grows request schemas, that test fails first and forces the decision above.

Tests

tests/test_tools_list_member_bound.py:

  • Invariant: a full sales set stays under half the bound for pins 3.1, 3.2, the packaged pin and unpinned.
  • The issue's repro.
  • The decisioning serve() path (with adcp.server.serve.serve captured), with and without supported_versions.
  • End to end: a real ADCPClient on defaults calls get_products on a decisioning seller over in-process streamable HTTP, through the client's real response bounds. That covers tools/list, call_tool, and the MCP client's outputSchema validation of the result. Without the fix this test fails with ADCPResponseTooComplexError.
  • Compaction sweep: every compacted bundled response schema for 3.1/3.2/3.3.0-beta.1 is metaschema-valid, has no dangling references, and is no larger than the bundle.
  • Compaction unit tests: relaxation with closed objects, not/if stay verbatim, oneOf becomes anyOf, reference targets are kept.
  • Guard tests: warning thresholds and member-count accuracy.

tests/test_mcp_schema_materialization.py: the pinned digests captured from e9a1c8f are the exact definitions, so they are now checked with schema_mode="defs". Compact definitions get their own mutation-isolation check.

Local runs:

  • Unit phase: 14,529 passed.
  • The reporting conformance files that read outputSchema: pass.
  • ruff check src/, black and mypy src/adcp/: clean.

Side finding, not changed here: on next, examples/hello_seller.py fails boot-time capabilities validation (no account.supported_billing) unless validate_at_init=False. No test boots it.

Fixes #1692

🤖 Generated with Claude Code

… 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>

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Closing in favour of #1701 (Brian's call). #1701 does the same compaction of a pinned seller's listing and also raises the client's member bound, sized to the byte budget, as requested. The startup member-count warning here is a good idea; it can follow as a separate PR on top of #1701 if wanted.

@bokelley bokelley closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant