fix(types): correct FastMCP.call_tool and convert_result return types (#1251)#2521
Open
SAY-5 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
fix(types): correct FastMCP.call_tool and convert_result return types (#1251)#2521SAY-5 wants to merge 3 commits intomodelcontextprotocol:mainfrom
SAY-5 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
…modelcontextprotocol#1251) Signed-off-by: SAY-5 <say.apm35@gmail.com>
Signed-off-by: SAY-5 <say.apm35@gmail.com>
…arrowing Signed-off-by: SAY-5 <say.apm35@gmail.com>
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 (labelled
ready for work).FastMCP.call_toolwas annotated as returningSequence[ContentBlock] | dict[str, Any], but it always passesconvert_result=Trueto the tool manager and the actual return shape fromFuncMetadata.convert_resultis one of:Sequence[ContentBlock]— tool with no output schema returning a regular valueCallToolResult— tool that returned aCallToolResultdirectlytuple[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
dictinstead of the tuple shape, and it omitted theCallToolResultbranch.Changes
src/mcp/server/mcpserver/server.py:402— updateFastMCP.call_toolreturn type to the precise three-arm union and add a docstring listing each branch.src/mcp/server/mcpserver/utilities/func_metadata.py:91— replaceAnyonconvert_resultwith the same three-arm union and tighten the docstring; reuses the existingSequence,ContentBlock, andCallToolResultimports 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 passedinspect.signatureround-trip on both functions returns the new annotations as expected