feat: preserve CallToolResult.isError flag in MCPToolResult#1943
Open
Exploreunive wants to merge 1 commit intostrands-agents:mainfrom
Open
feat: preserve CallToolResult.isError flag in MCPToolResult#1943Exploreunive wants to merge 1 commit intostrands-agents:mainfrom
Exploreunive wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Addresses review feedback from strands-agents#1943: 1. **Clean split**: Only isError-related changes, no unrelated commits from AgentResult.text (PR strands-agents#1942) or other work. 2. **isError propagation**: MCPToolResult now exposes isError field: - True when MCP server reports CallToolResult.isError (application error) - True when a Python exception occurs during tool execution (protocol error) - False/absent on success Updated docstring clarifies both error sources. 3. **Exception propagation** (maintainer feedback from strands-agents#1670): MCPAgentTool.stream() now passes the original exception via ToolResultEvent(result, exception=e), matching the pattern used by decorated tools. Added _invoke_tool() helper that calls the MCP client internals directly to capture exceptions. Files changed: - mcp_types.py: Added isError: NotRequired[bool], updated docstring - mcp_client.py: Propagated isError in _handle_tool_result and _handle_tool_execution_error - mcp_agent_tool.py: Added _invoke_tool() for exception capture, stream() yields ToolResultEvent(result, exception=...) - Tests: Added isError assertions, exception propagation tests
e8d89a9 to
afc5a74
Compare
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.
What
The
isErrorflag from MCP'sCallToolResultis now preserved in the framework'sMCPToolResult, enabling consumers to distinguish between:CallToolResult.isError=True)Previously, both error types ended up as
status="error"with no way to tell them apart.Changes
isError: NotRequired[bool]toMCPToolResultTypedDict inmcp_types.py_handle_tool_result()now propagatesisErrorfrom the MCPCallToolResult_handle_tool_execution_error()setsisError=Truefor execution exceptionsHow to test
All 53 tests pass (including new assertions for
isErrorin both success/error and exception scenarios).Fixes
Fixes #1670