2626from ...types import PaginatedList
2727from ...types .exceptions import MCPClientInitializationError
2828from ...types .media import ImageFormat
29- from ...types .tools import ToolResult , ToolResultContent , ToolResultStatus
29+ from ...types .tools import ToolResultContent , ToolResultStatus
3030from .mcp_agent_tool import MCPAgentTool
31- from .mcp_types import MCPTransport
31+ from .mcp_types import MCPToolResult , MCPTransport
3232
3333logger = logging .getLogger (__name__ )
3434
@@ -171,7 +171,7 @@ def call_tool_sync(
171171 name : str ,
172172 arguments : dict [str , Any ] | None = None ,
173173 read_timeout_seconds : timedelta | None = None ,
174- ) -> ToolResult :
174+ ) -> MCPToolResult :
175175 """Synchronously calls a tool on the MCP server.
176176
177177 This method calls the asynchronous call_tool method on the MCP session
@@ -186,7 +186,7 @@ def call_tool_sync(
186186 read_timeout_seconds: Optional timeout for the tool call
187187
188188 Returns:
189- ToolResult : The result of the tool call
189+ MCPToolResult : The result of the tool call
190190 """
191191 self ._log_debug_with_thread ("calling MCP tool '%s' synchronously with tool_use_id=%s" , name , tool_use_id )
192192 if not self ._is_session_active ():
@@ -208,13 +208,11 @@ async def call_tool_async(
208208 name : str ,
209209 arguments : dict [str , Any ] | None = None ,
210210 read_timeout_seconds : timedelta | None = None ,
211- ) -> ToolResult :
211+ ) -> MCPToolResult :
212212 """Asynchronously calls a tool on the MCP server.
213213
214214 This method calls the asynchronous call_tool method on the MCP session
215- and converts the result to the ToolResult format. If the MCP tool returns
216- structured content, it will be included as the last item in the content array
217- of the returned ToolResult.
215+ and converts the result to the MCPToolResult format.
218216
219217 Args:
220218 tool_use_id: Unique identifier for this tool use
@@ -223,7 +221,7 @@ async def call_tool_async(
223221 read_timeout_seconds: Optional timeout for the tool call
224222
225223 Returns:
226- ToolResult : The result of the tool call
224+ MCPToolResult : The result of the tool call
227225 """
228226 self ._log_debug_with_thread ("calling MCP tool '%s' asynchronously with tool_use_id=%s" , name , tool_use_id )
229227 if not self ._is_session_active ():
@@ -240,27 +238,26 @@ async def _call_tool_async() -> MCPCallToolResult:
240238 logger .exception ("tool execution failed" )
241239 return self ._handle_tool_execution_error (tool_use_id , e )
242240
243- def _handle_tool_execution_error (self , tool_use_id : str , exception : Exception ) -> ToolResult :
241+ def _handle_tool_execution_error (self , tool_use_id : str , exception : Exception ) -> MCPToolResult :
244242 """Create error ToolResult with consistent logging."""
245- return ToolResult (
243+ return MCPToolResult (
246244 status = "error" ,
247245 toolUseId = tool_use_id ,
248246 content = [{"text" : f"Tool execution failed: { str (exception )} " }],
249247 )
250248
251- def _handle_tool_result (self , tool_use_id : str , call_tool_result : MCPCallToolResult ) -> ToolResult :
252- """Maps MCP tool result to the agent's ToolResult format.
249+ def _handle_tool_result (self , tool_use_id : str , call_tool_result : MCPCallToolResult ) -> MCPToolResult :
250+ """Maps MCP tool result to the agent's MCPToolResult format.
253251
254252 This method processes the content from the MCP tool call result and converts it to the format
255- expected by the agent framework. If structured content is available in the MCP tool result,
256- it will be appended as the last item in the content array of the returned ToolResult.
253+ expected by the framework.
257254
258255 Args:
259256 tool_use_id: Unique identifier for this tool use
260257 call_tool_result: The result from the MCP tool call
261258
262259 Returns:
263- ToolResult : The converted tool result
260+ MCPToolResult : The converted tool result
264261 """
265262 self ._log_debug_with_thread ("received tool result with %d content items" , len (call_tool_result .content ))
266263
@@ -270,12 +267,14 @@ def _handle_tool_result(self, tool_use_id: str, call_tool_result: MCPCallToolRes
270267 if (mapped_content := self ._map_mcp_content_to_tool_result_content (content )) is not None
271268 ]
272269
273- if call_tool_result .structuredContent :
274- mapped_content .append ({"json" : call_tool_result .structuredContent })
275-
276270 status : ToolResultStatus = "error" if call_tool_result .isError else "success"
277271 self ._log_debug_with_thread ("tool execution completed with status: %s" , status )
278- return ToolResult (status = status , toolUseId = tool_use_id , content = mapped_content )
272+ return MCPToolResult (
273+ status = status ,
274+ toolUseId = tool_use_id ,
275+ content = mapped_content ,
276+ structuredContent = call_tool_result .structuredContent ,
277+ )
279278
280279 async def _async_background_thread (self ) -> None :
281280 """Asynchronous method that runs in the background thread to manage the MCP connection.
0 commit comments