fix(exceptions): export MCPToolCancellationError from top-level package#3210
Merged
seratch merged 1 commit intoopenai:mainfrom May 8, 2026
Merged
fix(exceptions): export MCPToolCancellationError from top-level package#3210seratch merged 1 commit intoopenai:mainfrom
seratch merged 1 commit intoopenai:mainfrom
Conversation
MCPToolCancellationError is a public exception subclassing AgentsException and is raised from MCP tool invocations, but was missing from the top-level agents package re-exports. Users catching it had to dig into agents.exceptions while every other AgentsException subclass was importable from agents. Add the import and __all__ entry, and add a regression test that asserts all public exception classes are re-exported.
Member
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MCPToolCancellationErroris a public exception subclassingAgentsException(defined insrc/agents/exceptions.pyand raised fromsrc/agents/mcp/util.py), but it was the only such class missing from the top-levelagentspackage re-exports.Every other
AgentsExceptionsubclass (MaxTurnsExceeded,ModelBehaviorError,ModelRefusalError,ToolTimeoutError,UserError, all the guardrail tripwire exceptions, etc.) is importable asfrom agents import X. Users wanting to catch MCP tool cancellations had to fall back tofrom agents.exceptions import MCPToolCancellationError, breaking the convention.This adds the import and
__all__entry so the symbol is reachable fromagentslike its siblings.Changes
src/agents/__init__.py: addMCPToolCancellationErrorto thefrom .exceptions import (...)block and to__all__(2 lines).tests/test_exception_exports.py(new, 30 lines): one direct assertion thatfrom agents import MCPToolCancellationErrorworks and the name appears inagents.__all__, plus a regression guard that walks every concreteAgentsExceptionsubclass inagents.exceptionsand asserts each is re-exported. This prevents the same mistake from recurring if a new exception is added later.Test plan
pytest tests/test_exception_exports.pypasses after the fix.upstream/mainwithout the fix (verified viagit stash).pytest tests/test_run_error_details.py tests/test_tool_context.py tests/mcp/test_mcp_imports.pystill passes (19 tests).