fix(openapi): preserve anyOf/oneOf/allOf in projected MCP input schema (adopted from #308) - #337
Open
K4bain wants to merge 1 commit into
Open
fix(openapi): preserve anyOf/oneOf/allOf in projected MCP input schema (adopted from #308)#337K4bain wants to merge 1 commit into
K4bain wants to merge 1 commit into
Conversation
convert_openapi_to_mcp_tools() injected a sibling type whenever the resolved property lacked one — including properties using anyOf, oneOf or allOf. A sibling type over-constrains the schema (validators AND the constraints), so Optional[...] unions rejected null and other unions became unsatisfiable. Skip the type injection when a composition keyword is present. Adopted from tadata-org#308 (original patch by @AlexisMarasigan).
This was referenced Aug 27, 2026
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.
Adopted from #308 (original patch by @AlexisMarasigan) — rebased onto current main and verified. This is the same root cause as #316 but extends the guard to oneOf and allOf in addition to anyOf.
Why this is needed
When a resolved property has no top-level type, convert_openapi_to_mcp_tools() injects one from the raw param schema. For properties whose schema uses anyOf/oneOf/allOf (every Optional[...] under Pydantic/OpenAPI 3.1!), that injected sibling type over-constrains the schema — JSON Schema validators AND sibling keys, so the projection rejects null for Optionals and breaks unions outright (#246).
The fix: skip the type injection when any of the three composition keywords is present in the property schema. Composition schemas are already complete and self-describing.
Verification
Credit to @AlexisMarasigan for the original report and patch in #308. If this lands, #316 (same fix, anyOf-only) can be closed as superseded.