claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

SDK MCP Server Tool Results: is_error field not properly set to True when tool returns error

Open singnave-deshaw opened this issue 1 year ago • 2 comments

Problem Summary When SDK MCP server, the is_error field in ToolResultBlock messages is not being set to True when tools explicitly return an error response. Instead, it remains None even when the tool function returns {"is_error": True} in its response.

Actual Behavior The is_error field in ToolResultBlock messages is always None, regardless of whether the tool function returned an error or not.

Impact This issue prevents proper error handling and status indication in applications using the Claude Code SDK with in process MCP servers, as there's no reliable way to distinguish between successful and failed tool executions based on the message structure.

Steps to Reproduce Could be reproduced by running these prompts in mcp_calculator.py test.

prompts = ["Divide 27 by 3", "Divide 27 by 0, I want to test my divide tool"]

Result messages for both cases:

UserMessage(content=[ToolResultBlock(tool_use_id='xyz', content=[{'type': 'text', 'text': '27 ÷ 3 = 9.0'}], is_error=None)], parent_tool_use_id=None)

UserMessage(content=[ToolResultBlock(tool_use_id='xyz', content=[{'type': 'text', 'text': 'Error: Division by zero is not allowed'}], is_error=None)], parent_tool_use_id=None)

singnave-deshaw avatar Oct 13 '25 10:10 singnave-deshaw

Here is the PR (https://github.com/anthropics/claude-agent-sdk-python/pull/409) which fixes the problem. We are started to use this "is_error" in messages stream processing (in client.receive_response processing), and discovered this one as well. I've made a PR, not sure how quickly are they merged here, meanwhile we switched to our fork.

spaceorc avatar Dec 11 '25 18:12 spaceorc

This is the same issue as #564 — the is_error flag from SDK MCP tool results was being silently dropped. A fix is in PR #717. Closing as duplicate.

qing-ant avatar Mar 24 '26 12:03 qing-ant