Repository navigation
fix(models): mark failed MCP tool results as errors for Claude - #7665
Open
AkshayShah03 wants to merge 1 commit into
Open
AkshayShah03 wants to merge 1 commit into
AkshayShah03 wants to merge 1 commit into
Conversation
AnthropicLlm hardcoded is_error=False on every tool_result block, so a CallToolResult with isError reached Claude as a successful result. Read the flag (isError, or is_error in MCP SDK 2.x dumps) instead. Fixes google#7664
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
_part_to_message_blockinanthropic_llm.pybuilds everytool_resultblock withis_error=False. When an MCP server reports a failed call (CallToolResult.isError),McpToolpasses that result on, and Claude receives the error text as a successful result.Solution:
Set
is_errorfrom the function response'sisErrorflag, also acceptingis_error(the MCP SDK 2.x field name), the same two spellingsMcpTool._detect_error_in_responsereads. Everything else in the block is unchanged.The question in #7664 about
contentresponses dropping sibling keys is left out of this PR.Testing Plan
Unit Tests:
Added
test_part_to_message_block_marks_mcp_error_result_as_error(parametrized forisErrorandis_error) totests/unittests/models/test_anthropic_llm.py. Both cases fail onmain(is_errorisFalse) and pass with this change. The existing tests that assertnot result["is_error"]for successful results still pass.The 4 failures are
test_google_llm.py::test_generate_content_async_leaves_continuation_to_sdk, which also fail onmainin my environment (google-genai 2.29; that feature needs a newer SDK).pyinkandisortreport no changes.Manual End-to-End (E2E) Tests:
Ran the snippet from #7664 (an MCP
CallToolResultdump withisError: truethroughpart_to_message_block):main:'file not found: notes.txt' is_error = False'file not found: notes.txt' is_error = TrueChecklist