-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Open
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingready for workEnough information for someone to start working onEnough information for someone to start working on
Description
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
If you try to use a tool a which is wrapped and uses from __future__ import annotations
setup fails with and InvalidSignature
exception e.g.
mcp.server.fastmcp.exceptions.InvalidSignature: Unable to evaluate type annotation ForwardRef("Literal['literal'] | None")
The cause of this is that the global name space used for the lookup is the wrapper namespace and not the original function namespace.
Example Code
from __future__ import annotations
import logfire
from mcp.server.fastmcp import FastMCP
@logfire.instrument
def test_tool(location_type: Literal["literal"] | None = None) -> str:
"""Test tool."""
return f"a is {location_type}"
mcp = FastMCP(
"Wrap test",
tools=[
Tool.from_function(test_tool),
],
)
Python & MCP Python SDK
SDL: 1.14.1
Python: 3.13.7
Metadata
Metadata
Assignees
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featurebugSomething isn't workingSomething isn't workingready for workEnough information for someone to start working onEnough information for someone to start working on