fix: propagate is_error flag from SDK MCP tool results#568
Open
Jbermingham1 wants to merge 1 commit intoanthropics:mainfrom
Open
fix: propagate is_error flag from SDK MCP tool results#568Jbermingham1 wants to merge 1 commit intoanthropics:mainfrom
Jbermingham1 wants to merge 1 commit intoanthropics:mainfrom
Conversation
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
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.
Summary
Fixes #564 — the
is_errorflag in SDK MCP tool results is silently discarded.call_toolhandler increate_sdk_mcp_serveronly extractscontentfrom tool return values, discarding theis_errorflag"is_error": Trueas a supported return valueCallToolResult(isError=False)Fix: When
is_errorisTrue, raiseValueErrorwith the error text. The MCP decorator catches it and wraps inCallToolResult(isError=True)— matching the existing exception-based error path already tested intest_error_handling.Changes
src/claude_agent_sdk/__init__.py: Checkresult.get("is_error", False)after building content list; raiseValueErrorto trigger the MCP error pathtests/test_sdk_mcp_integration.py: Addtest_is_error_flagverifying both the error case (isError=Truepropagated) and success case (isErrornot set)Test plan
test_is_error_flagfails before fix (RED), passes after (GREEN)ruff checkpassesruff format --checkpassesmypy src/passes with no issues