Remove dead dict branch in _handle_call_tool and fix call_tool return type#2863
Open
agaonker wants to merge 1 commit into
Open
Remove dead dict branch in _handle_call_tool and fix call_tool return type#2863agaonker wants to merge 1 commit into
agaonker wants to merge 1 commit into
Conversation
… type `FuncMetadata.convert_result` only ever returns one of three shapes: a `CallToolResult`, a `Sequence[ContentBlock]`, or a `(unstructured_content, structured_content)` tuple. It never returns a raw `dict`, so the `isinstance(result, dict)` branch in `_handle_call_tool` was unreachable (already marked `# pragma: no cover` with a TODO). Remove the dead branch, correct `call_tool`'s return annotation to reflect the three real shapes, and drop the now-orphaned `json` import (used only inside the removed branch). Closes modelcontextprotocol#2695 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Closes #2695
What
MCPServer._handle_call_toolcontained a deadisinstance(result, dict)branch, already marked# pragma: no coverwith an inline TODO documenting both the dead code and the related incorrect return-type annotation onMCPServer.call_tool.FuncMetadata.convert_resultreturns exactly three shapes:CallToolResult— when the tool function returned one directlySequence[ContentBlock]— no output schema(unstructured_content, structured_content)tuple — output schema setIt never returns a raw
dict, so the branch was unreachable.Changes
isinstance(result, dict)branch.call_tool's return annotation fromSequence[ContentBlock] | dict[str, Any](claims adictit never returns, omits the two shapes it does) toCallToolResult | Sequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]].import json(used only inside the removed branch).The existing
len(result) == 2check and the two pre-existing# type: ignore[arg-type]comments on the tuple branch are left untouched — they silence a real pyrightSequence/tupleoverlap and are out of scope here.Validation
pyright— cleanruff check/ruff format— clean./scripts/test— full suite passes at 100% coverage;strict-no-coverclean (confirms the removed branch was genuinely dead — its removal drops no coverage)🤖 Generated with Claude Code