Skip to content

fix(types): correct FastMCP.call_tool and convert_result return types (#1251)#2521

Open
SAY-5 wants to merge 3 commits intomodelcontextprotocol:mainfrom
SAY-5:fix/issue-1251-fastmcp-call-tool-return-type
Open

fix(types): correct FastMCP.call_tool and convert_result return types (#1251)#2521
SAY-5 wants to merge 3 commits intomodelcontextprotocol:mainfrom
SAY-5:fix/issue-1251-fastmcp-call-tool-return-type

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 30, 2026

Summary

Fixes #1251 (labelled ready for work). FastMCP.call_tool was annotated as returning Sequence[ContentBlock] | dict[str, Any], but it always passes convert_result=True to the tool manager and the actual return shape from FuncMetadata.convert_result is one of:

  • Sequence[ContentBlock] — tool with no output schema returning a regular value
  • CallToolResult — tool that returned a CallToolResult directly
  • tuple[Sequence[ContentBlock], dict[str, Any]] — tool with an output schema (the second element is the structured content; not a bare dict)

So the existing annotation was wrong on two counts: it claimed a bare dict instead of the tuple shape, and it omitted the CallToolResult branch.

Changes

  • src/mcp/server/mcpserver/server.py:402 — update FastMCP.call_tool return type to the precise three-arm union and add a docstring listing each branch.
  • src/mcp/server/mcpserver/utilities/func_metadata.py:91 — replace Any on convert_result with the same three-arm union and tighten the docstring; reuses the existing Sequence, ContentBlock, and CallToolResult imports already in scope.

No runtime behaviour change — pure typing fix.

Test plan

  • pytest tests/server/mcpserver/test_server.py tests/server/mcpserver/test_func_metadata.py tests/server/mcpserver/test_tool_manager.py — 172 passed
  • inspect.signature round-trip on both functions returns the new annotations as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect typing hint for FastMCP.call_tool

1 participant