Skip to content

Incorrect typing hint for FastMCP.call_tool #1251

@de-code

Description

@de-code

Initial Checks

Description

The signature for FastMCP.call_tool:

    async def call_tool(self, name: str, arguments: dict[str, Any]) -> Sequence[ContentBlock] | dict[str, Any]:

i.e. it says the return type is either a sequence of ContentBlock or a dict.

However, it seems to be more like either just a sequence of ContentBlock or a tuple of: sequence of ContentBlock and a dict:

Sequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]]

That is because it always passes convert_result=True to self._tool_manager.call_tool (it would be nice if that was exposed as a parameter). And the convert_result result function (in mcp.server.fastmcp.utilities.func_metadata) is implemented like that but doesn't have any useful type hints.

This has changed after version 1.9.4 (i.e. in 1.9.4 it was still just a sequence of ContentBlock).

Example Code

from mcp.server.fastmcp import FastMCP


mcp = FastMCP(name='Example MCP Server')


@mcp.tool()
async def add_numbers(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

...

# Within an async context call:

result = await mcp.call_tool(
    "add_numbers",
    arguments={"a": 1, "b": 2}
)
print('result:', result)

# Output:
result: ([TextContent(type='text', text='3', annotations=None, meta=None)], {'result': 3})

Python & MCP Python SDK

1.12.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Nice to haves, rare edge casesbugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions