Skip to content

Python: MCP Error Handling Fix + Added Unit Tests#1621

Merged
giles17 merged 2 commits intomicrosoft:mainfrom
giles17:mcp_error_fix
Oct 23, 2025
Merged

Python: MCP Error Handling Fix + Added Unit Tests#1621
giles17 merged 2 commits intomicrosoft:mainfrom
giles17:mcp_error_fix

Conversation

@giles17
Copy link
Copy Markdown
Contributor

@giles17 giles17 commented Oct 22, 2025

Motivation and Context

This PR improves error handling in the MCP connection logic by providing more specific and actionable error messages.
Resolves #1564

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings October 22, 2025 06:25
@github-actions github-actions bot changed the title MCP Error Handling Fix Python: MCP Error Handling Fix Oct 22, 2025
@markwallace-microsoft
Copy link
Copy Markdown
Contributor

markwallace-microsoft commented Oct 22, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _mcp.py3365483%132, 142–143, 164, 189, 204, 210, 214, 216, 298, 325, 356–357, 359–365, 367–369, 372–373, 417, 432, 450, 491, 504, 507–508, 512, 536, 539–540, 544, 575, 594, 596, 603–604, 623, 625, 631–634, 651–655, 780
TOTAL11681190183% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
1371 98 💤 0 ❌ 0 🔥 28.340s ⏱️

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.

Pull Request Overview

This PR improves error handling in the MCP (Model Context Protocol) connection logic by providing more specific and actionable error messages. The changes make it easier for developers to diagnose connection and initialization failures by including command details and distinguishing between different failure scenarios.

  • Enhanced error messages in the connect() method to include command information and specific failure context
  • Added comprehensive test coverage for error handling paths including connection failures, initialization failures, and cleanup verification
  • Added tests for various edge cases in message handling, sampling callbacks, and client configuration

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
python/packages/core/agent_framework/_mcp.py Enhanced error messages in connect() method to provide command-specific context and wrapped initialization in try-catch for better error handling
python/packages/core/tests/core/test_mcp.py Added extensive test coverage for error handling scenarios including connection failures, message handlers, sampling callbacks, and client parameter verification

@giles17 giles17 changed the title Python: MCP Error Handling Fix Python: MCP Error Handling Fix + Added Unit Tests Oct 22, 2025
@moonbox3 moonbox3 added this pull request to the merge queue Oct 22, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 22, 2025
@giles17 giles17 added this pull request to the merge queue Oct 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 23, 2025
@giles17 giles17 added this pull request to the merge queue Oct 23, 2025
Merged via the queue into microsoft:main with commit 1f19a6d Oct 23, 2025
20 checks passed
ReubenBond pushed a commit to ReubenBond/agent-framework that referenced this pull request Oct 28, 2025
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
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: MCP error hides root cause

5 participants