| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…protocol#2591) Closes modelcontextprotocol#2591. A tool whose return type uses a multi-member Python 3.10+ union mixing container and scalar types (dict | list | str) previously crashed at registration with PydanticUserError, because the bare types.UnionType was passed to create_model() as a field value. This is already fixed on main: such a union is neither a types.GenericAlias nor a type, so _try_create_model_and_schema falls through to the catch-all branch and wraps the result under {"result": ...}; modelcontextprotocol#2434 additionally guards the schema-generation path. But there was no regression test for the exact reported signature -- the existing func_union test only covers a 2-member all-scalar union (str | int), not a container+scalar mix with bare generics. Adds test_structured_output_pep604_union_return asserting the wrapped anyOf output_schema for the issue's exact signature, so the fix can't silently regress. Verification: uv run pytest tests/server/mcpserver/test_func_metadata.py -q -> 34 passed; ruff check/format clean; pyright 0 errors.
|
Thanks for the PR. The behaviour here has since landed on main by another route. Closing as part of a general backlog cleanup following the v2 release. If this is still relevant against v2, feel free to reopen. |
Sorry, something went wrong.
|
Thanks @maxisbey — understood. Appreciate the cleanup note; happy to leave this closed. If a v2-targeted regression coverage gap remains later, I can open a fresh PR against current main. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Motivation
Closes #2591.
FastMCP/MCPServer used to crash at registration with PydanticUserError when a tool's return type was a bare PEP 604 union like dict | list | str, because the types.UnionType was passed to create_model() as a field value.
This already works on current main (734746a): such a union is neither a types.GenericAlias nor a type, so _try_create_model_and_schema (func_metadata.py) falls through to the catch-all branch that calls _create_wrapped_model(...) with wrap_output=True; #2434 (5cbd259) additionally guards the schema-generation path. But there is no test covering the reported signature — the existing test_structured_output_generic_types only exercises a 2-member, all-scalar union (func_union() -> str | int), not a container+scalar mix with bare (unparametrized) generics, which is a different branch interaction (the dict member touches the RootModel dict special-casing before the union wraps).
The three prior fix attempts (#2592, #2599, #2669) were all closed during backlog cleanup rather than for an approach problem, and one of them switched the repro to typed generics to satisfy pyright — which masked the exact reported case. This PR keeps the bare-generic signature (with scoped # type: ignore) so the test reproduces the issue faithfully.
Verification
Real behavior proof
{ "properties": { "result": { "anyOf": [ {"additionalProperties": true, "type": "object"}, {"items": {}, "type": "array"}, {"type": "string"} ], "title": "Result" } }, "required": ["result"], "title": "func_pep604_unionOutput", "type": "object" }