diff --git a/src/agents/mcp/server.py b/src/agents/mcp/server.py index 7ce6bbb15b..7f152676a2 100644 --- a/src/agents/mcp/server.py +++ b/src/agents/mcp/server.py @@ -712,13 +712,12 @@ def _extract_http_error_from_exception(self, e: BaseException) -> Exception | No if isinstance(e, httpx.HTTPStatusError | httpx.ConnectError | httpx.TimeoutException): return e - # Check if it's an ExceptionGroup containing HTTP errors + # Recursively check ExceptionGroups for HTTP errors if isinstance(e, BaseExceptionGroup): for exc in e.exceptions: - if isinstance( - exc, httpx.HTTPStatusError | httpx.ConnectError | httpx.TimeoutException - ): - return exc + result = self._extract_http_error_from_exception(exc) + if result is not None: + return result return None