📦
Fastmcp Pydantic Future Issue Reproduction
No description available
0 installs
Trust: 30 — Low
Devtools
Ask AI about Fastmcp Pydantic Future Issue Reproduction
Powered by Claude · Grounded in docs
I know everything about Fastmcp Pydantic Future Issue Reproduction. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Loading tools...
Reviews
Documentation
FastMCP + Pydantic + Future Annotations Issue Reproduction
This is a minimal reproduction of a bug where FastMCP fails to properly resolve custom types when from __future__ import annotations is enabled.
Issue Description
When using from __future__ import annotations, FastMCP's TypeAdapter creation fails to resolve custom types because it uses FastMCP's module globals instead of the function's module globals for type evaluation.
Error
NameError: name 'CustomType' is not defined
Versions Tested
- FastMCP: 2.10.2
- Pydantic: 2.11.7
- Python: 3.11.10
Root Cause
from __future__ import annotationsconverts type annotations to strings- FastMCP calls
TypeAdapter(method)which triggers Pydantic's type evaluation - Pydantic calls
eval('CustomType', fastmcp_globals, localns) CustomTypeis not available in FastMCP's globals, only in the original module's globals- Results in
NameError
Files
broken_example.py- Demonstrates the issueworking_example.py- Shows workaroundstest_reproduction.py- Test to reproduce the issue
How to Run
pip install fastmcp==2.10.2
python test_reproduction.py
Workarounds
- Remove
from __future__ import annotations - Use built-in types like
dict[str, Any]instead of custom types - Remove return type annotations entirely for FastMCP methods
