Skip to content

fix(exceptions): export MCPToolCancellationError from top-level package#3210

Merged
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/exc-audit
May 8, 2026
Merged

fix(exceptions): export MCPToolCancellationError from top-level package#3210
seratch merged 1 commit intoopenai:mainfrom
adityasingh2400:fix/exc-audit

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Summary

MCPToolCancellationError is a public exception subclassing AgentsException (defined in src/agents/exceptions.py and raised from src/agents/mcp/util.py), but it was the only such class missing from the top-level agents package re-exports.

Every other AgentsException subclass (MaxTurnsExceeded, ModelBehaviorError, ModelRefusalError, ToolTimeoutError, UserError, all the guardrail tripwire exceptions, etc.) is importable as from agents import X. Users wanting to catch MCP tool cancellations had to fall back to from agents.exceptions import MCPToolCancellationError, breaking the convention.

This adds the import and __all__ entry so the symbol is reachable from agents like its siblings.

Changes

  • src/agents/__init__.py: add MCPToolCancellationError to the from .exceptions import (...) block and to __all__ (2 lines).
  • tests/test_exception_exports.py (new, 30 lines): one direct assertion that from agents import MCPToolCancellationError works and the name appears in agents.__all__, plus a regression guard that walks every concrete AgentsException subclass in agents.exceptions and 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.py passes after the fix.
  • Both tests fail on upstream/main without the fix (verified via git stash).
  • pytest tests/test_run_error_details.py tests/test_tool_context.py tests/mcp/test_mcp_imports.py still passes (19 tests).
  • No public API change beyond surfacing an existing class.

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.
@github-actions github-actions Bot added bug Something isn't working feature:core labels May 8, 2026
@seratch
Copy link
Copy Markdown
Member

seratch commented May 8, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@seratch seratch added this to the 0.17.x milestone May 8, 2026
@seratch seratch merged commit 8b04ee0 into openai:main May 8, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants