From 521ffc3a9175a84e970976b7f47cffedaeeb0db6 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Thu, 12 Feb 2026 21:46:46 +0800 Subject: [PATCH] agent: Check is_error flag in MCP tool responses (#47095) Previously, when an MCP server returned a tool response with `is_error: true`, the error content was incorrectly treated as a successful result. This could mislead the LLM into thinking the tool call succeeded when it actually failed. Now we check the `is_error` flag and propagate the error message properly, allowing the agent to handle failures appropriately. Release Notes: - N/A --------- Co-authored-by: Ben Brandt --- crates/agent/src/tools/context_server_registry.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/agent/src/tools/context_server_registry.rs b/crates/agent/src/tools/context_server_registry.rs index 12ad642cfca6d87aa29f219951e45d402d98943d..c7aa697ed6c5dc9eb176e154243fbed61aa2eb3b 100644 --- a/crates/agent/src/tools/context_server_registry.rs +++ b/crates/agent/src/tools/context_server_registry.rs @@ -380,6 +380,12 @@ impl AnyAgentTool for ContextServerTool { } }; + if response.is_error == Some(true) { + let error_message: String = + response.content.iter().filter_map(|c| c.text()).collect(); + anyhow::bail!(error_message); + } + let mut result = String::new(); for content in response.content { match content {