Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcp/server/mcpserver/utilities/func_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def _create_wrapped_model(func_name: str, annotation: Any) -> type[BaseModel]:
"""
model_name = f"{func_name}Output"

return create_model(model_name, result=annotation)
return create_model(model_name, result=(annotation, ...))


def _create_dict_model(func_name: str, dict_annotation: Any) -> type[BaseModel]:
Expand Down
24 changes: 24 additions & 0 deletions tests/server/mcpserver/test_func_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,30 @@ def func_optional() -> str | None: # pragma: no cover
}


def test_structured_output_pep604_union_of_container_and_primitives():
"""Test structured output with PEP 604 unions that combine containers and primitives."""

def func_container_union() -> dict | list | str: # pragma: no cover
return {"hello": "world"}

meta = func_metadata(func_container_union)
assert meta.output_schema == {
"type": "object",
"properties": {
"result": {
"title": "Result",
"anyOf": [
{"additionalProperties": True, "type": "object"},
{"items": {}, "type": "array"},
{"type": "string"},
],
}
},
"required": ["result"],
"title": "func_container_unionOutput",
}


def test_structured_output_dataclass():
"""Test structured output with dataclass return types"""

Expand Down
Loading