fix(openapi): preserve anyOf/oneOf/allOf in projected MCP input schema#308
Open
AlexisMarasigan wants to merge 1 commit into
Open
fix(openapi): preserve anyOf/oneOf/allOf in projected MCP input schema#308AlexisMarasigan wants to merge 1 commit into
AlexisMarasigan wants to merge 1 commit into
Conversation
`convert_openapi_to_mcp_tools` was injecting a single `"type"` field on every property without one — including properties whose schema used a JSON Schema composition keyword (`anyOf`, `oneOf`, `allOf`). The downstream jsonschema validator then AND'd the injected `type` with the existing composition, silently rejecting valid inputs at the MCP layer with `Input validation error: <payload> is not of type '<picked>'`. For `T | None` the bug surfaced as rejected null values (issue tadata-org#246). For `T | U` with both real types (e.g. `dict[str, list[str]] | list[str]`) the bug rejects whichever side lost the non-deterministic `next(iter(set))` pick in `get_single_param_type_from_schema` (issue tadata-org#307). Skip the "type" injection when any of the composition keywords is already present. Updates two existing tests that asserted the buggy behavior on `Optional[ProductCategory]` / `Optional[float]` / `Optional[List[str]]` / `Optional[str]` params, and adds two regression tests covering `T | U` and `oneOf`/`allOf`. Closes tadata-org#307. Likely also closes tadata-org#246. May help tadata-org#165.
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.
Summary
convert_openapi_to_mcp_toolswas injecting a top-level"type"field on every property without one — including properties whose schema used a JSON Schema composition keyword (anyOf,oneOf,allOf). The downstream jsonschema validator then AND'd the injected type with the existing composition, silently rejecting valid inputs at the MCP layer withInput validation error: <payload> is not of type '<picked>'.For
T | None, the bug surfaced as the nullable-rejection in #246. ForT | Uwith both real types (e.g.dict[str, list[str]] | list[str]), the bug rejects whichever side lost the non-deterministicnext(iter(set))pick inget_single_param_type_from_schema— #307.Fix
Skip the
"type"injection when any composition keyword is already present:Tests
Optional[ProductCategory]/Optional[float]/Optional[List[str]]/Optional[str]params (they expected the spurious"type"injection). Updated to assert the correct post-fix shape (anyOfpreserved, no sibling"type").test_anyof_union_preserved_in_input_schema— pins the [BUG] Union types of two real types (non-null) rejected at MCP-server jsonschema validator with misleading "is not of type 'X'" #307 case (T | U, both real types).test_oneof_and_allof_preserved_in_input_schema— pins the same behavior foroneOfandallOf.(The 14 errors in
test_http_real_transport.pyare pre-existing onmain—RuntimeError: Event loop is closedon Python 3.13. Unrelated to this fix.)Closes / refs
convert.py"type"-injection bug; the existing buggy tests for it are updated here)itemsmissing — same area, different symptom)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need. Autofix is disabled.