Skip to content

Commit 51f2cd5

Browse files
committed
fix: clear implicit context from mapped MCP errors
1 parent da5f6d8 commit 51f2cd5

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/agents/mcp/server.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,12 @@ def _user_error_for_http_error(
11711171
@staticmethod
11721172
def _raise_mapped_transport_error(error: UserError, cause: Exception | None) -> NoReturn:
11731173
"""Raise a mapped transport error without retaining unsafe URL data."""
1174-
if cause is None:
1175-
raise error from None
1176-
raise error from cause
1174+
try:
1175+
raise error from cause
1176+
finally:
1177+
# Python 3.10 task runners can retain an active exception while resuming a coroutine.
1178+
# Clear implicit context after raising; retain only the explicitly approved cause.
1179+
error.__context__ = None
11771180

11781181
def _user_error_for_request_operation(
11791182
self,

0 commit comments

Comments
 (0)