Skip to content

fix(mcp): expose CallToolResult.isError in MCPToolResult#2059

Open
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/mcp-is-error-flag
Open

fix(mcp): expose CallToolResult.isError in MCPToolResult#2059
Zelys-DFKH wants to merge 1 commit intostrands-agents:mainfrom
Zelys-DFKH:fix/mcp-is-error-flag

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

@Zelys-DFKH Zelys-DFKH commented Apr 4, 2026

Description

MCP tools can return `isError=True` to signal an application-level failure (the tool ran but reported an error). This flag was used internally in `_handle_tool_result()` to set `MCPToolResult.status="error"` but was not preserved in the result, making it impossible for callers to distinguish between:

  • An application error (`isError=True` from the MCP server, meaning the tool executed and returned a failure)
  • A protocol error (a Python exception raised before the tool could return a result)

Both produce `status="error"` today, but they are fundamentally different failure modes.

Changes:

  • Add `isError: NotRequired[bool]` to `MCPToolResult` in `mcp_types.py`
  • Populate it from `call_tool_result.isError` in `_handle_tool_result()`, only set when `True`, matching the existing pattern used by `structuredContent` and `metadata`

Related Issues

Fixes #1670

Documentation PR

N/A

Type of Change

Bug fix

Testing

  • Added `test_call_tool_sync_preserves_is_error`, parametrized over `isError=True` and `isError=False`, verifying the field is present only when `True`
  • All 136 existing MCP tests pass

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

MCP tools can return isError=True to signal an application-level failure
(the tool ran but reported an error). This flag was used internally to set
MCPToolResult.status="error" but was not preserved in the result, making
it impossible for callers to distinguish between an application error
(isError=True from the MCP server) and a protocol error (Python exception
during invocation).

Add isError: NotRequired[bool] to MCPToolResult and populate it from
CallToolResult.isError in _handle_tool_result(). The field is only present
when True, matching the existing pattern used by structuredContent and
metadata.

Fixes strands-agents#1670
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.

[FEATURE] Preserve CallToolResult.isError flag in MCPToolResult to distinguish application errors from protocol errors

1 participant