Skip to content

Commit 3e7b286

Browse files
authored
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.
1 parent cfe9099 commit 3e7b286

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

examples/hosted_mcp/approvals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async def main(verbose: bool, stream: bool):
4848
print(res.final_output)
4949

5050
if verbose:
51-
for item in result.new_items:
51+
for item in res.new_items:
5252
print(item)
5353

5454

examples/hosted_mcp/simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def main(verbose: bool, stream: bool):
3434
# The repository is primarily written in multiple languages, including Rust and TypeScript...
3535

3636
if verbose:
37-
for item in result.new_items:
37+
for item in res.new_items:
3838
print(item)
3939

4040

src/agents/_run_impl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
ImageGenerationCall,
3434
LocalShellCall,
3535
McpApprovalRequest,
36+
McpCall,
3637
McpListTools,
3738
)
3839
from openai.types.responses.response_reasoning_item import ResponseReasoningItem
@@ -456,6 +457,9 @@ def process_model_response(
456457
)
457458
elif isinstance(output, McpListTools):
458459
items.append(MCPListToolsItem(raw_item=output, agent=agent))
460+
elif isinstance(output, McpCall):
461+
items.append(ToolCallItem(raw_item=output, agent=agent))
462+
tools_used.append("mcp")
459463
elif isinstance(output, ImageGenerationCall):
460464
items.append(ToolCallItem(raw_item=output, agent=agent))
461465
tools_used.append("image_generation")

0 commit comments

Comments
 (0)