Skip to content

Allow arbitrary types in model creation by updating config in create_model #1132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/mcp/server/fastmcp/utilities/func_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def model_dump_one_level(self) -> dict[str, Any]:
)


class OutputModelBase(BaseModel):
"""A model representing the output of a function."""

model_config = ConfigDict(
arbitrary_types_allowed=True,
)


class FuncMetadata(BaseModel):
arg_model: Annotated[type[ArgModelBase], WithJsonSchema(None)]
output_schema: dict[str, Any] | None = None
Expand Down Expand Up @@ -407,7 +415,7 @@ def _create_wrapped_model(func_name: str, annotation: Any, field_info: FieldInfo
if annotation is None:
annotation = type(None)

return create_model(model_name, result=(annotation, field_info), __base__=BaseModel)
return create_model(model_name, result=(annotation, field_info), __base__=OutputModelBase)


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