Skip to content

feat(mcp): preserve CallToolResult.isError flag in MCPToolResult#2118

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

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

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

Description

Adds an optional isError field to MCPToolResult, set to True only when the underlying MCP tool returned CallToolResult.isError=True. This lets callers tell apart application-level errors (the tool ran but reported a failure) from protocol/transport errors (the tool never ran because of a client exception, timeout, or session issue). Right now both surface identically as status="error", which is what #1670 is asking to fix.

Behavior:

  • Tool-reported error (CallToolResult.isError=True): result has status="error" and isError=True
  • Protocol/client exception: result has status="error" and no isError key. This path goes through _handle_tool_execution_error and is unchanged.
  • Successful call: status="success", no isError key

The field is NotRequired, so existing code reading MCPToolResult keeps working without changes.

Related Issues

Closes #1670

Documentation PR

N/A

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • Extended the existing test_call_tool_sync_status and test_call_tool_async_status parametrized tests to assert result.get("isError") == (True if is_error else None)
  • Extended test_mcp_tool_result_type to confirm the field is absent by default and settable when provided
  • Ran hatch run prepare (ruff + mypy + full test suite): 2524 passed, 4 skipped, no new warnings

No new docs needed — this is a small additive field on an existing TypedDict, already documented in the docstring on MCPToolResult.

  • I ran hatch run prepare

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
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • 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.

Adds an optional isError field to MCPToolResult, set to True only when
the underlying MCP tool returned CallToolResult.isError=True. This lets
callers tell apart application-level errors from protocol/transport
errors, which currently both surface as status='error'.

Closes 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