Skip to content

Python: Propagated MCP isError flag through function middleware pipeline#4511

Merged
moonbox3 merged 3 commits intomicrosoft:mainfrom
dmytrostruk:mcp-error-handling
Mar 5, 2026
Merged

Python: Propagated MCP isError flag through function middleware pipeline#4511
moonbox3 merged 3 commits intomicrosoft:mainfrom
dmytrostruk:mcp-error-handling

Conversation

@dmytrostruk
Copy link
Member

Motivation and Context

Resolves: #1811

  • Raised ToolExecutionException in MCPTool.call_tool() when the MCP server returns isError: True, which was previously silently discarded
  • Added a ToolExecutionException re-raise clause to prevent the error from being swallowed by the generic exception handler
  • Fixed an existing test that used MagicMock instead of CallToolResult, causing a falsely truthy isError

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.

dmytrostruk and others added 2 commits March 5, 2026 11:43
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dmytrostruk dmytrostruk self-assigned this Mar 5, 2026
Copilot AI review requested due to automatic review settings March 5, 2026 19:48
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 5, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _mcp.py4206385%97–98, 108–113, 124, 129, 175–176, 186–191, 201–202, 254, 263, 326, 334, 485, 552, 587, 589, 593–594, 596–597, 651, 666, 684, 725, 830, 843–848, 870, 923–924, 930–932, 951, 976–977, 981–985, 1002–1006, 1150
   _skills.py289897%578, 617–618, 691, 696, 848–849, 1057
TOTAL22676281987% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4695 20 💤 0 ❌ 0 🔥 1m 22s ⏱️

Copy link
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.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moonbox3 moonbox3 added this pull request to the merge queue Mar 5, 2026
Merged via the queue into microsoft:main with commit 8664d19 Mar 5, 2026
31 checks passed
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: Function Middleware Error Propagation

5 participants