Python: MCP Error Handling Fix + Added Unit Tests#1621
Merged
giles17 merged 2 commits intomicrosoft:mainfrom Oct 23, 2025
Merged
Python: MCP Error Handling Fix + Added Unit Tests#1621giles17 merged 2 commits intomicrosoft:mainfrom
giles17 merged 2 commits intomicrosoft:mainfrom
Conversation
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
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 |
ekzhu
approved these changes
Oct 22, 2025
moonbox3
approved these changes
Oct 22, 2025
ReubenBond
pushed a commit
to ReubenBond/agent-framework
that referenced
this pull request
Oct 28, 2025
* mcp error fix * test docstring fixes
arisng
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
* mcp error fix * test docstring fixes
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.
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