fix: correct MCPServer call_tool result type
Summary
Fixes #2695.
MCPServer.call_tool() currently advertises Sequence[ContentBlock] | dict[str, Any], but the convert_result=True path never returns a raw dict. It can return only:
- a direct
CallToolResult, - a
Sequence[ContentBlock]for unstructured tools, or - a
(content, structured_content)tuple for structured tools.
This PR removes the unreachable raw-dict branch in _handle_call_tool(), drops the now-unused json import, and introduces a ToolResult type alias so the public annotation and handler implementation share the same result shape.
Tests
uv run --frozen pytest tests/server/mcpserver/test_server.py -quv run --frozen pytest tests/server/mcpserver/test_server.py::TestServerTools::test_call_tool_returns_declared_result_shapes -quv run --frozen coverage erase && uv run --frozen coverage run -m pytest tests/server/mcpserver/test_server.py && uv run --frozen coverage combine && uv run --frozen coverage report --include='src/mcp/server/mcpserver/server.py' --fail-under=0 && UV_FROZEN=1 uv run --frozen strict-no-coveruv run --frozen ruff format --check .uv run --frozen ruff check .uv run --frozen pyrightuvx --from pre-commit pre-commit run markdownlint --files docs/migration.mduvx --from pre-commit pre-commit run end-of-file-fixer --files docs/migration.md src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_server.py
AI assistance disclosure
I used an AI coding assistant to help trace the result shapes and draft the patch. I reviewed the final diff and ran the validation commands above locally.
Quick follow-up here: this is still ready from my side, with no failing checks showing on the PR. Happy to make changes if there is a preferred typing/API direction for this fix.
This pull request is included in pre-release v2.0.0a3