Skip to content

Commit 0697d90

Browse files
committed
Allow arbitrary types in model creation by updating config in create_model
1 parent e975d05 commit 0697d90

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/mcp/server/fastmcp/utilities/func_metadata.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ def model_dump_one_level(self) -> dict[str, Any]:
5959
)
6060

6161

62+
class OutputModelBase(BaseModel):
63+
"""A model representing the output of a function."""
64+
65+
model_config = ConfigDict(
66+
arbitrary_types_allowed=True,
67+
)
68+
69+
6270
class FuncMetadata(BaseModel):
6371
arg_model: Annotated[type[ArgModelBase], WithJsonSchema(None)]
6472
output_schema: dict[str, Any] | None = None
@@ -433,7 +441,7 @@ def _create_wrapped_model(func_name: str, annotation: Any, field_info: FieldInfo
433441
if annotation is None:
434442
annotation = type(None)
435443

436-
return create_model(model_name, result=(annotation, field_info), __base__=BaseModel)
444+
return create_model(model_name, result=(annotation, field_info), __base__=OutputModelBase)
437445

438446

439447
def _create_dict_model(func_name: str, dict_annotation: Any) -> type[BaseModel]:

0 commit comments

Comments
 (0)