Skip to content

Commit 92f361b

Browse files
g97iulio1609Copilot
andcommitted
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>
1 parent 62575ed commit 92f361b

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/mcp/server/mcpserver/server.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ async def _handle_call_tool(
315315
structured_content=structured_content, # type: ignore[arg-type]
316316
)
317317
if isinstance(result, dict): # pragma: no cover
318-
# TODO: this code path is unreachable — convert_result never returns a raw dict.
319-
# The call_tool return type (Sequence[ContentBlock] | dict[str, Any]) is wrong
320-
# and needs to be cleaned up.
321318
return CallToolResult(
322319
content=[TextContent(type="text", text=json.dumps(result, indent=2))],
323320
structured_content=result,
@@ -399,7 +396,9 @@ def get_context(self) -> Context[LifespanResultT, Request]:
399396
request_context = None
400397
return Context(request_context=request_context, mcp_server=self)
401398

402-
async def call_tool(self, name: str, arguments: dict[str, Any]) -> Sequence[ContentBlock] | dict[str, Any]:
399+
async def call_tool(
400+
self, name: str, arguments: dict[str, Any]
401+
) -> Sequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]] | CallToolResult:
403402
"""Call a tool by name with arguments."""
404403
context = self.get_context()
405404
return await self._tool_manager.call_tool(name, arguments, context=context, convert_result=True)

0 commit comments

Comments
 (0)