Skip to content

Python: preserve MCP connection errors during cleanup#5886

Open
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/mcp-exception-group-cleanup
Open

Python: preserve MCP connection errors during cleanup#5886
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/mcp-exception-group-cleanup

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

  • keep MCP connection/setup failures as ToolException when exit-stack cleanup raises an ExceptionGroup
  • add a regression test for streamable HTTP cleanup masking the original initialization error

Fixes #5876.

To verify

  • uv run pytest packages\core\tests\core\test_mcp_exception_group.py packages\core\tests\core\test_mcp.py::test_connect_initialization_failure_http_no_command -q --basetemp .tmp\pytest -p no:cacheprovider
  • uv run ruff check packages\core\agent_framework\_mcp.py packages\core\tests\core\test_mcp_exception_group.py
  • uv run ruff format --check packages\core\agent_framework\_mcp.py packages\core\tests\core\test_mcp_exception_group.py
  • uv run pyright packages\core\agent_framework\_mcp.py packages\core\tests\core\test_mcp_exception_group.py
  • uv run python -m py_compile packages\core\agent_framework\_mcp.py packages\core\tests\core\test_mcp_exception_group.py
  • git diff --check

Copilot AI review requested due to automatic review settings May 15, 2026 06:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Incorrect exception raised while MCP server is unreachable

3 participants