-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Enhance exception handling in MCP server initialization and cleanup #2268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 65f330839d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
4b6e201 to
07d9678
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef5232b1eb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87c04c0476
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Fixes an issue where MCP server connection failures (e.g., 401 Unauthorized, connection errors, 500 errors) surfaced as confusing
BaseExceptionGroupexceptions withRuntimeErrorabout cancel scopes, masking the actual HTTP errors.What changed:
_extract_http_error_from_exception()helper method to extract HTTP errors from exceptions orBaseExceptionGroupraised by anyio task groups_raise_user_error_for_http_error()helper method to wrap HTTP errors in clear, actionableUserErrormessages with specific guidance for different error types (401, 403, 500+, connection errors, timeouts)connect()to extract HTTP errors from exceptions/ExceptionGroups and wrap them inUserError, while preserving non-HTTP errors (e.g.,ValueError) as-iscleanup()to catchBaseExceptionGroupraised during cleanup, extract HTTP errors from it, and re-raise them asUserErrorwhile suppressingRuntimeErrorabout cancel scopes that would otherwise mask the real errorlist_tools()andcall_tool()to catchhttpx.HTTPStatusErrorandhttpx.ConnectErrorand wrap them inUserErrorwith clear messagesinvoke_mcp_tool()inutil.pyto preserveUserErrorexceptions for better error propagationResult:
Cryptic
BaseExceptionGroupwith nested exceptions andRuntimeError: Attempted to exit cancel scope in a different tasknow become clear, actionable errors like:The original HTTP error is preserved in the exception chain via
from e, maintaining full traceback information for debugging.Current logs examples before and after fix:
Repro Scripts:
main.py
server.py