---
type: email
from: gn00295120 <notifications@github.com>
subject: Re: [openai/openai-agents-python] MCP tools turn upstream HTTP errors

 into AgentsException, crashing the run (Issue #879)
received: 2026-03-06 08:10:04
date_header: Mon, 20 Oct 2025 15:31:58 -0700
priority: normal
status: awaiting_approval
uid: 33112
---

## Email Content

**From:** gn00295120 <notifications@github.com>
**Subject:** Re: [openai/openai-agents-python] MCP tools turn upstream HTTP errors

 into AgentsException, crashing the run (Issue #879)
**Date:** Mon, 20 Oct 2025 15:31:58 -0700

### Body (preview)

gn00295120 left a comment (openai/openai-agents-python#879)



## Analysis of This Issue



I attempted to fix this by converting exceptions to JSON error messages at the tool level, but this approach has a **critical flaw**:



### Problem with Simple JSON Conversion



Converting `AgentsException` to JSON strings at the `invoke_mcp_tool` level creates **silent failures**:



1. ❌ **Breaks existing tests**: `test_mcp_invocation_crash_causes_error` expects `AgentsException` to be raised

2. ❌ **Silent failures**: The agent treats error JSON as normal tool output, potentially causing incorrect behavior

3. ❌ **Backward incompatible**: Any code expecting `AgentsException` will no longer detect failures



### Correct Solution Approach



The proper fix should be at the **agent loop level**, not the tool level:



1. **Catch `AgentsException` in the agent execution loop** (e.g., in `_run_impl.py` or `run.py`)

2. **Convert to a function call result** with error information

3. **Pass the error to the LLM** as a tool result, allowing the agent to handle it gracefully

4. **Update tests** to verify this new error handling behavior



This way:

- ✅ The agent can decide how to respond to tool failures

- ✅ Tests can still verify error detection

- ✅ Backward compatibility is maintained through opt-in behavior



### Implementation Suggestion



The fix would involve modifying the function tool execution logic to catch `AgentsException` and return it as a structured error result, similar to how other agent frameworks handle tool failures.



Would the maintainers be open to this approach? I can work on a proper implementation if this direction makes sense.



-- 

Reply to this email directly or view it on GitHub:

https://github.com/openai/openai-agents-python/issues/879#issuecomment-3423964963

You are receiving this because you are subscribed to this thread.



Message ID: <openai/openai-agents-python/issues/879/3423964963@github.com>

---

## Suggested Actions
- [ ] Reply
- [ ] Archive
- [ ] Escalate
