Initial Checks
Description
FastMCP crashes on startup when a tool function's return type annotation uses Python 3.10+ union syntax (A | B | C, i.e. types.UnionType). The error originates from _create_wrapped_model in func_metadata.py, which passes the union annotation directly to Pydantic's create_model() as a bare keyword value, causing PydanticUserError.
Example Code
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("test")
@mcp.tool()
async def my_tool(flag: bool) -> dict | list | str: # <-- triggers the bug
if flag:
return {"key": "value"}
return ["item"]
Python & MCP Python SDK
- mcp (Python): latest (>=1.0.0,<2.0.0)
- pydantic: >=2.10 (observed on 2.10.x)
- Python: >=3.10
Initial Checks
Description
FastMCPcrashes on startup when a tool function's return type annotation uses Python 3.10+ union syntax (A | B | C, i.e.types.UnionType). The error originates from_create_wrapped_modelinfunc_metadata.py, which passes the union annotation directly to Pydantic'screate_model()as a bare keyword value, causingPydanticUserError.Example Code
Python & MCP Python SDK