Skip to content

fix: propagate is_error flag from SDK MCP tool results#568

Open
Jbermingham1 wants to merge 1 commit intoanthropics:mainfrom
Jbermingham1:fix/propagate-is-error-flag
Open

fix: propagate is_error flag from SDK MCP tool results#568
Jbermingham1 wants to merge 1 commit intoanthropics:mainfrom
Jbermingham1:fix/propagate-is-error-flag

Conversation

@Jbermingham1
Copy link

Summary

Fixes #564 — the is_error flag in SDK MCP tool results is silently discarded.

  • The call_tool handler in create_sdk_mcp_server only extracts content from tool return values, discarding the is_error flag
  • This contradicts the documented API which shows "is_error": True as a supported return value
  • The MCP decorator always wraps the result in CallToolResult(isError=False)

Fix: When is_error is True, raise ValueError with the error text. The MCP decorator catches it and wraps in CallToolResult(isError=True) — matching the existing exception-based error path already tested in test_error_handling.

Changes

  • src/claude_agent_sdk/__init__.py: Check result.get("is_error", False) after building content list; raise ValueError to trigger the MCP error path
  • tests/test_sdk_mcp_integration.py: Add test_is_error_flag verifying both the error case (isError=True propagated) and success case (isError not set)

Test plan

  • New test test_is_error_flag fails before fix (RED), passes after (GREEN)
  • All 157 existing tests pass — no regressions
  • ruff check passes
  • ruff format --check passes
  • mypy src/ passes with no issues

The call_tool handler in create_sdk_mcp_server discards the is_error
flag from tool return values, always producing CallToolResult(isError=False).
This contradicts the documented API (lines 133-140) which shows tools
returning {"is_error": True} to indicate errors.

Fix: when is_error is True, raise ValueError with the error text so
the MCP decorator catches it and wraps in CallToolResult(isError=True),
matching the existing exception-based error path.

Closes anthropics#564
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The tool result does not take into account the is_error flag.

1 participant