Skip to content

Pydantic schema generation fails for non-standard output types in toolkit functions #1131

@coolbeevip

Description

@coolbeevip

Initial Checks

Description

Description:

When registering toolkit functions that return non-standard Python objects (i.e., types not natively supported by Pydantic), MCP/fastMCP fails with a PydanticSchemaGenerationError. This error occurs because Pydantic cannot generate a schema for such custom or third-party types by default. The problem arises whenever tool registration parses output annotations involving these unsupported types.

Reason:

MCP/fastMCP automatically wraps toolkit function outputs with Pydantic models. When the output type is a non-standard or third-party object, schema generation is not supported by default, resulting in runtime errors.

https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/fastmcp/utilities/func_metadata.py#L410

Example Code

Python & MCP Python SDK

1.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions