Skip to content

fix(openapi): preserve array items for Optional[List] MCP tool params (adopted from #314) - #336

Closed
K4bain wants to merge 1 commit into
tadata-org:mainfrom
K4bain:fix/optional-list-items
Closed

K4bain wants to merge 1 commit into
tadata-org:mainfrom
K4bain:fix/optional-list-items

Conversation

@K4bain

@K4bain K4bain commented Aug 27, 2026

Copy link
Copy Markdown

Adopted from #314 (original patch by @syf2211) — rebased onto current main and verified.

Why this is needed

A request body field like tags: Optional[List[str]] resolves (after expansion + anyOf cleanup) to a property that carries only anyOf variants and no top-level items — so MCP clients/LLMs see an array param with no item schema and cannot construct valid input.

This PR:

  1. Adds _hoist_array_fields_from_composition(): before clean_schema_for_display() strips anyOf/oneOf, it copies items (and type=array) from the first array variant up to the top level.
  2. Runs converted properties through clean_schema_for_display() so the cleaned shape is what clients actually receive.

Result: Optional[List[str]] becomes a plain {type: array, items: {type: string}} tool param.

Verification

  • New tests: unit test for the hoisting on a hand-built anyOf schema, plus an end-to-end FastAPI app test asserting tags resolves to type array + items string with no anyOf left. Both fail on main, pass with the fix.
  • Full unit suite: 71 passed (69 existing + 2 new).

Credit to @syf2211 for the original report and patch in #314.

Optional[List[T]] body fields resolved to a schema with only anyOf
variants and no top-level items, so LLM clients saw an unusable param.
clean_schema_for_display() now hoists items/type from the first array
variant of anyOf/oneOf before stripping composition keys, and converted
properties are passed through the cleaner.

Adopted from tadata-org#314 (original patch by @syf2211).
@K4bain

K4bain commented Sep 14, 2026

Copy link
Copy Markdown
Author

Closing for housekeeping - the repo had no reviewer engagement and we are re-approaching these areas through a narrower pipeline. Happy to reopen on request.

@K4bain K4bain closed this Sep 14, 2026
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