From 3e7b2863e9486146586cd382d383013a7e93c40e Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Tue, 3 Jun 2025 00:10:07 +0900 Subject: [PATCH] Fix #777 by handling MCPCall events in RunImpl (#799) This pull request resolves #777; If you think we should introduce a new item type for MCP call output, please let me know. As other hosted tools use this event, I believe using the same should be good to go tho. --- examples/hosted_mcp/approvals.py | 2 +- examples/hosted_mcp/simple.py | 2 +- src/agents/_run_impl.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/hosted_mcp/approvals.py b/examples/hosted_mcp/approvals.py index 2cabb3e..3080a1d 100644 --- a/examples/hosted_mcp/approvals.py +++ b/examples/hosted_mcp/approvals.py @@ -48,7 +48,7 @@ async def main(verbose: bool, stream: bool): print(res.final_output) if verbose: - for item in result.new_items: + for item in res.new_items: print(item) diff --git a/examples/hosted_mcp/simple.py b/examples/hosted_mcp/simple.py index 508c3a7..895fdfb 100644 --- a/examples/hosted_mcp/simple.py +++ b/examples/hosted_mcp/simple.py @@ -34,7 +34,7 @@ async def main(verbose: bool, stream: bool): # The repository is primarily written in multiple languages, including Rust and TypeScript... if verbose: - for item in result.new_items: + for item in res.new_items: print(item) diff --git a/src/agents/_run_impl.py b/src/agents/_run_impl.py index 2cfa270..e980105 100644 --- a/src/agents/_run_impl.py +++ b/src/agents/_run_impl.py @@ -33,6 +33,7 @@ from openai.types.responses.response_output_item import ( ImageGenerationCall, LocalShellCall, McpApprovalRequest, + McpCall, McpListTools, ) from openai.types.responses.response_reasoning_item import ResponseReasoningItem @@ -456,6 +457,9 @@ class RunImpl: ) elif isinstance(output, McpListTools): items.append(MCPListToolsItem(raw_item=output, agent=agent)) + elif isinstance(output, McpCall): + items.append(ToolCallItem(raw_item=output, agent=agent)) + tools_used.append("mcp") elif isinstance(output, ImageGenerationCall): items.append(ToolCallItem(raw_item=output, agent=agent)) tools_used.append("image_generation")