Skip to content

Return CallToolResult from convert_result instead of a tuple#2175

Open
Kludex wants to merge 2 commits intomainfrom
return-call-tool-result-from-convert-result
Open

Return CallToolResult from convert_result instead of a tuple#2175
Kludex wants to merge 2 commits intomainfrom
return-call-tool-result-from-convert-result

Conversation

@Kludex
Copy link
Member

@Kludex Kludex commented Feb 28, 2026

Summary

  • convert_result() now returns a CallToolResult directly when structured output is present, instead of a bare (unstructured, structured) tuple that leaked through the public API.
  • MCPServer.call_tool return type corrected from Sequence[ContentBlock] | dict[str, Any] to CallToolResult | Sequence[ContentBlock].
  • Removed the tuple-unpacking and unreachable dict branches from _handle_call_tool.

Closes #1251

Test plan

  • Existing tests in test_func_metadata.py, test_tool_manager.py, and test_server.py updated and passing (170 tests)
  • ruff check and pyright clean on all changed files

`convert_result()` was returning a bare `(unstructured, structured)` tuple
when an output schema was present, leaking an internal detail through
`MCPServer.call_tool`'s public API. The declared return type
`Sequence[ContentBlock] | dict[str, Any]` was also wrong - the `dict`
branch was unreachable.

Now `convert_result()` returns a `CallToolResult` directly, and
`MCPServer.call_tool` is typed as `CallToolResult | Sequence[ContentBlock]`.
The tuple-unpacking and dead `dict` branches in `_handle_call_tool` are
removed.

Github-Issue: #1251
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