Skip to content

fix: remove dead code path in _handle_call_tool and correct call_tool return type#2855

Open
wahajahmed010 wants to merge 1 commit into
modelcontextprotocol:mainfrom
wahajahmed010:fix/2695-remove-dead-dict-branch
Open

fix: remove dead code path in _handle_call_tool and correct call_tool return type#2855
wahajahmed010 wants to merge 1 commit into
modelcontextprotocol:mainfrom
wahajahmed010:fix/2695-remove-dead-dict-branch

Conversation

@wahajahmed010

Copy link
Copy Markdown

Summary

Remove a dead isinstance(result, dict) branch in _handle_call_tool and correct the call_tool return type annotation. Per the issue analysis, FuncMetadata.convert_result returns exactly three shapes:

  1. CallToolResult (when the tool returned one directly)
  2. Sequence[ContentBlock] (no output schema)
  3. 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

  • Remove the dead isinstance(result, dict) branch in _handle_call_tool
  • Remove the now-unused import json
  • Correct call_tool's return type from Sequence[ContentBlock] | dict[str, Any] to CallToolResult | Sequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]]

Testing

  • All 89 server tests pass
  • All 33 func_metadata tests pass
  • All 335 mcpserver tests pass

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

… 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>
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.

Dead code path in MCPServer._handle_call_tool and incorrect call_tool return type

1 participant