Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(openapi): preserve anyOf/oneOf/allOf in projected MCP input schema (adopted from #308) - #337

Open
K4bain wants to merge 1 commit into
tadata-org:mainfrom
K4bain:fix/preserve-composition-schemas
Open

fix(openapi): preserve anyOf/oneOf/allOf in projected MCP input schema (adopted from #308)#337
K4bain wants to merge 1 commit into
tadata-org:mainfrom
K4bain:fix/preserve-composition-schemas

Conversation

@K4bain

@K4bain K4bain commented Aug 27, 2026

Copy link
Copy Markdown

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

  • New tests: an end-to-end FastAPI union body field keeps anyOf with no sibling type; hand-built oneOf and allOf schemas survive conversion unchanged. Both fail on main, pass with the fix.
  • Existing test_parameter_handling expectations updated to assert the now-preserved anyOf shapes (they previously asserted the buggy injected types).
  • Full unit suite: 71 passed.

Credit to @AlexisMarasigan for the original report and patch in #308. If this lands, #316 (same fix, anyOf-only) can be closed as superseded.

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).
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