Repository navigation
fix(server): support scalar, enum, and Pydantic value return types in structured output - #3898
chengwudi1 wants to merge 1 commit into
Conversation
… structured output Fixes modelcontextprotocol#3886. When a tool returned standard library scalars (Enum, UUID, datetime, Decimal, Path, IP address) or Pydantic value types with custom core schemas (such as AnyUrl / AnyHttpUrl), _create_output_model either dropped structured output, raised InvalidSignature, or created an empty BaseModel with zero fields (silently discarding data). Wrap these types in {"result": ...} like other scalars, and ensure _create_model_from_class returns None when all annotations are private.
|
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 #3886. If a maintainer assigns you to #3886, 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 |
Summary
Fixes #3886.
When a tool function uses standard library scalar types (
Enum,UUID,datetime,date,time,timedelta,Decimal,Path,PurePath,ipaddressnetwork/address types) or Pydantic value types implementing__get_pydantic_core_schema__(such asAnyUrl/AnyHttpUrl),_create_output_modelexhibited unexpected behavior:AnyUrl/AnyHttpUrlhave non-emptyget_type_hints()consisting only of private annotations (_constraints), so_create_model_from_classproduced an emptyBaseModelwith zero fields. When called,convert_result()silently dropped the serialized URL and returnedstructured_content == {}.Enum,UUID, anddatetimehave emptyget_type_hints(), so_create_output_modelreturned(None, False). Structured output was dropped, orstructured_output=TrueraisedInvalidSignature.Solution
_create_output_modelto treat standard library scalar types,Enumsubclasses, and types with__get_pydantic_core_schema__/__get_pydantic_json_schema__as wrapped values ({"result": ...}), consistent with Give baredict,setandfrozensetreturn annotations structured output #3758._create_model_from_classto returnNonewhen a class has no public fields, preventing empty models.tests/server/mcpserver/test_func_metadata.pyverifying schema generation and result conversion for URLs, enums, UUIDs, datetimes, decimals, paths, IP addresses, and private-only classes.