From 21bd91a773836a086133353b2bb25317794d9eba Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Tue, 27 May 2025 19:47:44 +0200 Subject: [PATCH] agent: Namespace MCP server tools (#30600) This fixes an issue where requests were failing when MCP servers were registering tools with the same name. We now prefix the tool names with the context server name, in the UI we still show the name that the MCP server gives us Release Notes: - agent: Fix an error were requests would fail if two MCP servers were using an identical tool name --- crates/agent/src/agent_configuration.rs | 2 +- crates/agent/src/agent_configuration/tool_picker.rs | 4 ++-- crates/agent/src/context_server_tool.rs | 4 ++++ crates/assistant_tool/src/assistant_tool.rs | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/agent/src/agent_configuration.rs b/crates/agent/src/agent_configuration.rs index 8f7346c00b2f02ec7e34a5961bd8fa6a1d676133..be2d1da51b22a5811b1f10b20f4735612ccd98c1 100644 --- a/crates/agent/src/agent_configuration.rs +++ b/crates/agent/src/agent_configuration.rs @@ -637,7 +637,7 @@ impl AgentConfiguration { .hover(|style| style.bg(cx.theme().colors().element_hover)) .rounded_sm() .child( - Label::new(tool.name()) + Label::new(tool.ui_name()) .buffer_font(cx) .size(LabelSize::Small), ) diff --git a/crates/agent/src/agent_configuration/tool_picker.rs b/crates/agent/src/agent_configuration/tool_picker.rs index 5ac2d4496b53528e145a9fa92be8ebc42a35e960..b14de9e4475aad18559af084baf9c116c208f2ef 100644 --- a/crates/agent/src/agent_configuration/tool_picker.rs +++ b/crates/agent/src/agent_configuration/tool_picker.rs @@ -117,7 +117,7 @@ impl ToolPickerDelegate { ToolSource::Native => { if mode == ToolPickerMode::BuiltinTools { items.extend(tools.into_iter().map(|tool| PickerItem::Tool { - name: tool.name().into(), + name: tool.ui_name().into(), server_id: None, })); } @@ -129,7 +129,7 @@ impl ToolPickerDelegate { server_id: server_id.clone(), }); items.extend(tools.into_iter().map(|tool| PickerItem::Tool { - name: tool.name().into(), + name: tool.ui_name().into(), server_id: Some(server_id.clone()), })); } diff --git a/crates/agent/src/context_server_tool.rs b/crates/agent/src/context_server_tool.rs index 68ffefb126468b114878e0ed8857425a31fc1dbc..af799838536330b0fb7d6b1e25883ee98a1e42a0 100644 --- a/crates/agent/src/context_server_tool.rs +++ b/crates/agent/src/context_server_tool.rs @@ -30,6 +30,10 @@ impl ContextServerTool { impl Tool for ContextServerTool { fn name(&self) -> String { + format!("{}-{}", self.server_id, self.tool.name) + } + + fn ui_name(&self) -> String { self.tool.name.clone() } diff --git a/crates/assistant_tool/src/assistant_tool.rs b/crates/assistant_tool/src/assistant_tool.rs index ecda105f6dcb2bb3f3a6b7a530c6dfe4399b9a89..3691ad10c39a389131f8e63c5e1811537b0e07c8 100644 --- a/crates/assistant_tool/src/assistant_tool.rs +++ b/crates/assistant_tool/src/assistant_tool.rs @@ -203,6 +203,11 @@ pub trait Tool: 'static + Send + Sync { /// Returns the name of the tool. fn name(&self) -> String; + /// Returns the name to be displayed in the UI for this tool. + fn ui_name(&self) -> String { + self.name() + } + /// Returns the description of the tool. fn description(&self) -> String;