Skip to content

Protocol types for 2026-07-28: superset monolith, committed per-version packages, and wire-method maps#2849

Open
maxisbey wants to merge 6 commits into
mainfrom
maxisbey/types-two-surface-packages
Open

Protocol types for 2026-07-28: superset monolith, committed per-version packages, and wire-method maps#2849
maxisbey wants to merge 6 commits into
mainfrom
maxisbey/types-two-surface-packages

Conversation

@maxisbey

@maxisbey maxisbey commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Overview

Three type sets:

  • mcp.types.v2025_11_25 — full generated types for the 2025-11-25 schema; serves every version through 2025-11-25
  • mcp.types.v2026_07_28 — full generated types for the 2026-07-28 (draft) schema
  • mcp.types (the monolith) — hand-maintained superset of both; this is the public API

The per-version packages validate inbound payloads and shape outbound ones; the monolith types are what user code constructs and receives. mcp.types.methods holds (method, version) → surface-type maps and the parse/validate/serialize functions.

Generation

scripts/gen_surface_types.py runs datamodel-codegen over vendored sha-pinned schema/*.json, with a few mappings overridden (format: byte/uri/uri-templatestr, since JSON-Schema format is annotation-only) and extra="ignore" everywhere except a per-version allow-list of spec-declared open types (_meta, Result, GetTaskPayloadResult, Tool input/output schemas, URLElicitationRequiredError.data). CI regenerates with --check and diffs.

Server-side wiring

ServerRunner consults the maps:

  • Inbound — spec methods are validated against the negotiated version's surface row; a spec method that doesn't exist at that version is METHOD_NOT_FOUND even if a handler is registered. Custom methods skip the gate and use their registered params_type as before.
  • Outbound — spec-method results are dumped from the monolith model, then re-serialized through the surface row. Fields not in that version's schema are dropped, so 2026-only keys (resultType, ttlMs, cacheScope) never reach a pre-2026 peer. A handler return that doesn't validate against the surface schema is logged and answered with INTERNAL_ERROR.

ttlMs/cacheScope default to None on the monolith; the SDK does not stamp a caching policy. At 2026 (when negotiable) handlers will need to set them explicitly. resultType defaults to "complete" on concrete results and is stripped at pre-2026 by the sieve.

SUPPORTED_PROTOCOL_VERSIONS is unchanged — 2026-07-28 is modeled, not yet negotiable. Client-side wiring is a follow-up.

Breaking changes

  • Server handlers must return spec-valid results; nonconforming output (e.g. Tool(inputSchema={}) — missing "type": "object") now raises and the client receives INTERNAL_ERROR. Documented in docs/migration.md.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@maxisbey maxisbey changed the title Two-surface protocol types: validated model packages (candidate 1/2) Protocol types for 2026-07-28: superset monolith, committed per-version packages, and wire-method maps Jun 12, 2026
@maxisbey maxisbey force-pushed the maxisbey/types-two-surface-packages branch 2 times, most recently from 9a38b0d to 655c393 Compare June 15, 2026 13:33
Comment thread docs/migration.md Outdated
Comment thread docs/migration.md Outdated
Comment thread src/mcp/shared/version.py Outdated
Comment thread src/mcp/types/v2025_11_25/__init__.py Outdated
Comment thread src/mcp/types/__init__.py Outdated
Comment thread tests/interaction/lowlevel/test_wire.py
Comment thread tests/interaction/_helpers.py
Comment thread tests/interaction/_requirements.py Outdated
Comment thread tests/interaction/README.md Outdated
Comment thread tests/types/test_public_surface.py Outdated
Comment thread src/mcp/shared/version.py Outdated
Comment thread src/mcp/types/jsonrpc.py Outdated
Comment thread src/mcp/types/methods.py
Comment thread tests/interaction/_requirements.py Outdated
@maxisbey maxisbey force-pushed the maxisbey/types-two-surface-packages branch 4 times, most recently from 4913884 to d52fbc6 Compare June 15, 2026 16:58
maxisbey added 2 commits June 15, 2026 17:07
…s, and wire-method maps

One public type set (mcp.types) covering every protocol revision through
2026-07-28; two per-version model packages that act as the schema-exact
validating layer; and plain (method, version) maps with two-step parse
functions. Version gating is data: key absence is the gate. Outbound
serialization is the model dump, with the new 2026-07-28 result fields
as ordinary serialized defaults.

Includes a surface-to-monolith field-parity test that asserts every wire
alias in either per-version package is carried by the monolith.
Vendor schema/2025-11-25.json and schema/2026-07-28.json (pinned to spec
SHA 6d441518), restore scripts/gen_surface_types.py to regenerate both
src/mcp/types/v* packages from them, and run --check in CI so the
committed files cannot drift from the schemas.
@maxisbey maxisbey force-pushed the maxisbey/types-two-surface-packages branch from d52fbc6 to 408c56e Compare June 15, 2026 17:07
maxisbey added 3 commits June 15, 2026 17:21
- Add validate_client_request/notification, validate_server_result to
  types.methods (surface-only siblings of the parse_* functions)
- ServerRunner validates inbound requests/notifications against the
  negotiated version's surface schema; custom methods fall through to
  the registered params_type as before
- Handler results are validated against the surface schema after dump;
  a spec-invalid result is logged and returns INTERNAL_ERROR to the client
- Map JSON-Schema format byte/uri/uri-template to plain str in codegen
  (Base64Str and AnyUrl over-assert on annotation-only formats);
  regenerate both surface packages
- Fix two test fixtures that built Tool(input_schema={}) without the
  spec-required type field
- Document handler-result validation in migration.md
@maxisbey maxisbey marked this pull request as ready for review June 15, 2026 20:53
Generated surface types switch to extra="ignore" (with a per-version
allow-list for spec-declared open types: Result, _meta, GetTaskPayloadResult,
Tool input/output schemas, URLElicitationRequiredError data). The runner now
serializes spec-method results by dumping the monolith model and re-dumping
through the negotiated version's surface row, so 2026-only fields (resultType,
ttlMs, cacheScope) never reach the wire on a pre-2026 session.

- Monolith ttl_ms/cache_scope default to None; the SDK does not stamp a
  caching policy. EmptyResult.result_type stays None (deployed peer servers
  strict-validate ping responses).
- Spec methods absent at the negotiated version reject with METHOD_NOT_FOUND
  even if a handler is registered; custom methods fall through unchanged.
- Version fallback for pre-handshake/stateless is the literal 2025-11-25,
  not LATEST_PROTOCOL_VERSION.
- Add serialize_server_result to types.methods; codegen drift-guard asserts
  the open-class substitution count.
- Docstrings now say method-gating per version, shape per schema era.
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