Repository navigation
fix(func_metadata): give bare dict/list/tuple returns a structured output model - #3731
CodeAlex52 wants to merge 1 commit into
Conversation
…tput model
A tool annotated with a bare `dict` (or `list` / `tuple`) produced no output
model: those classes have no type hints, so they reached the generic class
branch, `get_type_hints()` came back empty and the model stayed None. The tool
therefore advertised no outputSchema and returned no structuredContent, and
`structured_output=True` raised InvalidSignature claiming the return type was
not serializable for structured output.
Treat bare containers like their parameterised equivalents (wrapped in
{"result": ...}), which is what `dict[str, Any]` already did.
Fixes modelcontextprotocol#3725
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3725. If a maintainer assigns you to #3725, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Fixes #3725
Summary
A tool annotated with a bare
dict(orlist/tuple) produced no output model at all:outputSchemaon the tool,structuredContentin the result (only JSON text),structured_output=True,InvalidSignature: ... return type <class 'dict'> is not serializable for structured output.Root cause
In
_create_output_model, bare containers are plain classes with no annotations, so they fell into the "other class types" branch:dict[str, Any]never took that path (it is aGenericAlias), which is why only the bare form misbehaved.Change
Handle bare containers as their parameterised equivalents before the generic class branch:
That matches the behaviour the docs already promise for
dict[str, Any](a{"result": ...}wrapper), and keepsstr/int/... unchanged.Tests
Added to
tests/server/mcpserver/test_func_metadata.py:dict,list,tuple:func_metadata(func).output_model is not Noneandwrap_output is True(previouslyNone/False);func_metadata(func) -> dictwithstructured_output=Trueproduces a model that validates{"a": 1}into{"result": {"a": 1}}(previously raisedInvalidSignature).