Skip to content

fix: preserve anyOf nullable schemas without injecting type field#264

Open
Br1an67 wants to merge 1 commit intotadata-org:mainfrom
Br1an67:fix/nullable-anyof-schema-conversion
Open

fix: preserve anyOf nullable schemas without injecting type field#264
Br1an67 wants to merge 1 commit intotadata-org:mainfrom
Br1an67:fix/nullable-anyof-schema-conversion

Conversation

@Br1an67
Copy link
Copy Markdown

@Br1an67 Br1an67 commented Mar 1, 2026

Summary

convert_openapi_to_mcp_tools added a top-level type field to parameter schemas that already had anyOf with a null variant (e.g. Optional[str]anyOf: [{type: string}, {type: null}]). This broke nullable validation because JSON Schema treats type and anyOf as independent constraints — adding type: string alongside anyOf meant null values were rejected.

Changes

Skip the type injection when anyOf is already present in the property schema, for path, query, and body parameters.

Files changed:

  • fastapi_mcp/openapi/convert.py — guard type injection with and "anyOf" not in properties[param_name]
  • tests/test_openapi_conversion.py — added test_nullable_anyof_schema_preserved and updated existing assertions

Closes #246

convert_openapi_to_mcp_tools added a top-level 'type' field to
parameter schemas that already had 'anyOf' with a null variant.
This broke nullable validation because JSON Schema treats 'type'
and 'anyOf' as independent constraints that must all be satisfied.

Skip the type injection when 'anyOf' is already present in the
property schema, for path, query, and body parameters.

Closes tadata-org#246
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.

convert_openapi_to_mcp_tools adds "type" field, breaking nullable schemas

1 participant