fix: correct return type annotation for MCPServer.call_tool()#2159
Closed
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
Closed
fix: correct return type annotation for MCPServer.call_tool()#2159giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
giulio-leone wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
The return type was annotated as Sequence[ContentBlock] | dict[str, Any] but the actual return types from convert_result() are: - Sequence[ContentBlock] (when no output schema) - tuple[Sequence[ContentBlock], dict[str, Any]] (when output schema is set) - CallToolResult (when tool returns CallToolResult directly) The dict[str, Any] variant was unreachable, as noted by a TODO comment in _handle_call_tool. Update the annotation to match the actual behavior and remove the stale TODO. Fixes modelcontextprotocol#1251 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
This is not the way to go, we need to drop the tuple on the return statement. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1251
The return type annotation for
MCPServer.call_tool()wasSequence[ContentBlock] | dict[str, Any], but the actual return types fromconvert_result()are:Sequence[ContentBlock]— when no output schema is definedtuple[Sequence[ContentBlock], dict[str, Any]]— when an output schema is setCallToolResult— when the tool function returns aCallToolResultdirectlyThe
dict[str, Any]variant was unreachable, as noted by an inline TODO comment in_handle_call_tool. This could mislead subclass authors into returning a baredictfromcall_tool()overrides, which would hit the dead-code fallback path instead of being handled correctly.Changes
call_tool()toSequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]] | CallToolResultTest Results
475 server tests pass (2 consecutive clean runs).