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
Open
Protocol types for 2026-07-28: superset monolith, committed per-version packages, and wire-method maps#2849maxisbey wants to merge 6 commits into
maxisbey wants to merge 6 commits into
Conversation
9 tasks
9a38b0d to
655c393
Compare
maxisbey
commented
Jun 15, 2026
maxisbey
commented
Jun 15, 2026
4913884 to
d52fbc6
Compare
…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.
d52fbc6 to
408c56e
Compare
… generated-file pyright suppression
- 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
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.
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.
Overview
Three type sets:
mcp.types.v2025_11_25— full generated types for the 2025-11-25 schema; serves every version through 2025-11-25mcp.types.v2026_07_28— full generated types for the 2026-07-28 (draft) schemamcp.types(the monolith) — hand-maintained superset of both; this is the public APIThe per-version packages validate inbound payloads and shape outbound ones; the monolith types are what user code constructs and receives.
mcp.types.methodsholds(method, version)→ surface-type maps and the parse/validate/serialize functions.Generation
scripts/gen_surface_types.pyrunsdatamodel-codegenover vendored sha-pinnedschema/*.json, with a few mappings overridden (format: byte/uri/uri-template→str, since JSON-Schemaformatis annotation-only) andextra="ignore"everywhere except a per-version allow-list of spec-declared open types (_meta,Result,GetTaskPayloadResult,Toolinput/output schemas,URLElicitationRequiredError.data). CI regenerates with--checkand diffs.Server-side wiring
ServerRunnerconsults the maps:METHOD_NOT_FOUNDeven if a handler is registered. Custom methods skip the gate and use their registeredparams_typeas before.resultType,ttlMs,cacheScope) never reach a pre-2026 peer. A handler return that doesn't validate against the surface schema is logged and answered withINTERNAL_ERROR.ttlMs/cacheScopedefault toNoneon the monolith; the SDK does not stamp a caching policy. At 2026 (when negotiable) handlers will need to set them explicitly.resultTypedefaults to"complete"on concrete results and is stripped at pre-2026 by the sieve.SUPPORTED_PROTOCOL_VERSIONSis unchanged — 2026-07-28 is modeled, not yet negotiable. Client-side wiring is a follow-up.Breaking changes
Tool(inputSchema={})— missing"type": "object") now raises and the client receivesINTERNAL_ERROR. Documented indocs/migration.md.Types of changes
Checklist