fix(mcp): mark errored MCP tool results as failed (set error_code=-1) - #429
Open
nankingjing wants to merge 2 commits into
Open
fix(mcp): mark errored MCP tool results as failed (set error_code=-1)#429nankingjing wants to merge 2 commits into
nankingjing wants to merge 2 commits into
Conversation
Author
|
Reviewed — the error_code fix correctly signals failures to the agent loop, and the test assertion covers it. Ready for review. |
Author
|
@chao-peng ready for review. Fixes MCP errored results not signaling failure to the agent loop by setting error_code=-1. One regression test covers the assertion. |
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.
Problem
MCPTool.execute(trae_agent/tools/mcp_tool.py) does not propagate a failure code when an MCP server returns an error result:ToolExecResult.error_codedefaults to0(seetrae_agent/tools/base.py).ToolExecutor.execute_tool_callderives success from that field:So when an MCP tool call reports
isError == True, the resultingToolResult.successisTrue. The failure is silently treated as a success:is_error=not success→is_error=False, telling the model the tool succeeded.BaseAgent.reflect_on_result, which keys ontool_result.success) never fires.success: true.Note the
exceptbranch in the same method already setserror_code=-1, and the existingtest_execute_exceptionasserts it — theisErrorbranch was simply missing the same signal.Fix
Set
error_code=-1in theisErrorbranch so failures are propagated consistently with the exception branch.Verification
python -m py_compileon both changed files: passed.MCPTool+ToolExecutorcode with a stubbed client:isErrorresult yieldsToolResult.success == True(bug).ToolResult.success == False; the success path still yieldssuccess == True.test_execute_failureunit test to asserterror_code == -1. (Full pytest suite not run here — repo targets Python 3.12+ and the local interpreter is 3.11; verification used atyping.overrideshim.)