Skip to content

Commit 7e2d9df

Browse files
committed
Allow arbitrary types in model creation by updating config in create_model
1 parent d28a1a6 commit 7e2d9df

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
@@ -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,7 +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(model_name, result=(annotation, field_info), __base__=BaseModel)
418+
return create_model(model_name, result=(annotation, field_info), __base__=OutputModelBase)
411419

412420

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

0 commit comments

Comments
 (0)