Skip to content

Commit 75d9420

Browse files
committed
Allow arbitrary types in model creation by updating config in create_model
1 parent 2d5d9de commit 75d9420

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def model_dump_one_level(self) -> dict[str, Any]:
5656
)
5757

5858

59+
class OutputModelBase(BaseModel):
60+
"""A model representing the output of a function."""
61+
62+
model_config = ConfigDict(
63+
arbitrary_types_allowed=True,
64+
)
65+
66+
5967
class FuncMetadata(BaseModel):
6068
arg_model: Annotated[type[ArgModelBase], WithJsonSchema(None)]
6169
output_schema: dict[str, Any] | None = None
@@ -407,9 +415,7 @@ def _create_wrapped_model(func_name: str, annotation: Any, field_info: FieldInfo
407415
if annotation is None:
408416
annotation = type(None)
409417

410-
return create_model(
411-
model_name, result=(annotation, field_info), __base__=BaseModel, __config__={"arbitrary_types_allowed": True}
412-
)
418+
return create_model(model_name, result=(annotation, field_info), __base__= OutputModelBase)
413419

414420

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

0 commit comments

Comments
 (0)