fix: remove dead code path in _handle_call_tool and correct call_tool return type#2855
Open
wahajahmed010 wants to merge 1 commit into
Open
Conversation
… return type The isinstance(result, dict) branch in _handle_call_tool is unreachable because FuncMetadata.convert_result never returns a raw dict -- it returns CallToolResult, Sequence[ContentBlock], or a tuple of (Sequence[ContentBlock], dict[str, Any]). This change: - Removes the dead dict branch - Drops the now-unused import json - Corrects call_tool's return type annotation to reflect the actual return shapes Closes modelcontextprotocol#2695 Co-authored-by: AI assistant (code review and diff structuring) Signed-off-by: Wahaj Ahmed <wahaj.ahmed010@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
Remove a dead
isinstance(result, dict)branch in_handle_call_tooland correct thecall_toolreturn type annotation. Per the issue analysis,FuncMetadata.convert_resultreturns exactly three shapes:CallToolResult(when the tool returned one directly)Sequence[ContentBlock](no output schema)tuple[Sequence[ContentBlock], dict[str, Any]](with output schema)It never returns a raw
dict, making the dict branch unreachable (it was already marked# pragma: no cover).Changes
isinstance(result, dict)branch in_handle_call_toolimport jsoncall_tool's return type fromSequence[ContentBlock] | dict[str, Any]toCallToolResult | Sequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]]Testing
AI assistance disclosure
I used an AI assistant to help trace the call path and structure the diff. I have reviewed every changed line and validated the diagnosis against the source.
Closes #2695