Skip to main content

Module merge

Module merge 

Source
Expand description

Core schema-merging logic - a faithful Rust port of the definitions- combining half of the former schema/build_combined_schema.py (see git history for the original). Reused by both regen (the real merge) and bisect (building opaqued-out candidate schemas from the same merge).

Structs§

MethodsManifest
NotificationEntry
One server_notifications/client_notifications manifest entry - no response_type field at all (not even null), matching the Python original’s dict literal for notifications.
ParamsType
The resolved params type for one method’s oneOf branch: the referenced type name (if any) and whether the params were nullable (2-way anyOf).
RequestEntry
One client_requests/server_requests manifest entry (includes a resolved response type). Field order is JSON serialization order - must stay method, variant_name, fn_name, params_type, params_optional, response_type to byte-match the Python original’s output.

Constants§

EXPECTED_DIVERGENT_COLLISIONS 🔒
Definition names known to legitimately differ between the master and v2 bundles - v2’s copy is the deliberately-pruned/authoritative one and is expected to differ from master’s (ref-rewritten) copy. Any other name-collision with differing content is treated as a hard failure (see check_collision_compatibility) rather than silently letting v2 shadow a master definition that might carry different meaning.

Functions§

build_combined
Merges the master bundle’s flat top-level definitions (ref-rewritten) with the v2 bundle’s definitions (v2 wins name collisions), applies the McpServerElicitationRequestParams flatten workaround, and wraps the result in the same schema envelope build_combined_schema.py produced.
build_methods_manifest
Builds the full methods.json manifest from a merged, flat definitions map (as produced by build_combined).
check_collision_compatibility 🔒
For every definition name present in both master_flat_rewritten and v2_defs, verifies they’re either identical or on the explicit known-divergent allowlist. build_combined always prefers v2’s copy on a collision; this only exists to catch collisions where that’s not safe - a future codex schema change that makes some other same-named type genuinely diverge between the two bundles would otherwise have v2 silently substitute the wrong shape into a master-derived envelope type (several of which transitively $ref into collision names like AbsolutePathBuf and RequestId), with no build failure and no warning.
flatten_base_plus_oneof
The McpServerElicitationRequestParams typify-0.7.0 workaround: merges a schema’s top-level object properties/required into each sibling oneOf branch, producing a pure oneOf-of-self-contained-objects. Returns the schema unchanged unless it actually has this exact shape (top-level oneOf and properties both present).
get_def 🔒
methods_of
Extracts the method string of every oneOf branch of a discriminated union definition (e.g. ClientRequest), in schema order.
params_type_for
STRICT: only a plain $ref, a 2-way nullable-ref anyOf, an explicit {"type": "null"}, or a missing "params" key are recognized. Any other shape is a hard failure, matching the Python original’s params_type_for docstring: raising here (rather than silently falling back to “no params”) is load-bearing - the wrapper codegen in build.rs would otherwise silently emit params: () for a method that actually requires typed params.
ref_name 🔒
rewrite_v2_refs
Recursively rewrites "$ref": "#/definitions/v2/X" to "#/definitions/X" so refs resolve against a single flat definitions namespace.
wrap_definitions
Wraps a flat definitions map in the schema envelope the crate’s build.rs expects ($schema/title/description/type/definitions, in that field order).