From 92f361bf8732c4a01c03ef248f36248d43852473 Mon Sep 17 00:00:00 2001 From: g97iulio1609 Date: Sat, 28 Feb 2026 04:29:52 +0100 Subject: [PATCH] fix: correct return type annotation for MCPServer.call_tool() The return type was annotated as Sequence[ContentBlock] | dict[str, Any] but the actual return types from convert_result() are: - Sequence[ContentBlock] (when no output schema) - tuple[Sequence[ContentBlock], dict[str, Any]] (when output schema is set) - CallToolResult (when tool returns CallToolResult directly) The dict[str, Any] variant was unreachable, as noted by a TODO comment in _handle_call_tool. Update the annotation to match the actual behavior and remove the stale TODO. Fixes #1251 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/mcp/server/mcpserver/server.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mcp/server/mcpserver/server.py b/src/mcp/server/mcpserver/server.py index 9c7105a7b..0f53ac68d 100644 --- a/src/mcp/server/mcpserver/server.py +++ b/src/mcp/server/mcpserver/server.py @@ -315,9 +315,6 @@ async def _handle_call_tool( structured_content=structured_content, # type: ignore[arg-type] ) if isinstance(result, dict): # pragma: no cover - # TODO: this code path is unreachable — convert_result never returns a raw dict. - # The call_tool return type (Sequence[ContentBlock] | dict[str, Any]) is wrong - # and needs to be cleaned up. return CallToolResult( content=[TextContent(type="text", text=json.dumps(result, indent=2))], structured_content=result, @@ -399,7 +396,9 @@ def get_context(self) -> Context[LifespanResultT, Request]: request_context = None return Context(request_context=request_context, mcp_server=self) - async def call_tool(self, name: str, arguments: dict[str, Any]) -> Sequence[ContentBlock] | dict[str, Any]: + async def call_tool( + self, name: str, arguments: dict[str, Any] + ) -> Sequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]] | CallToolResult: """Call a tool by name with arguments.""" context = self.get_context() return await self._tool_manager.call_tool(name, arguments, context=context, convert_result=True)