bug: Fixed a bug that was duplicating entries of all the functions for agents between MCP and tools

This commit is contained in:
2025-10-20 15:30:29 -06:00
parent 29536f6291
commit 1b504e211a
+25 -3
View File
@@ -1983,6 +1983,10 @@ impl Config {
.functions .functions
.declarations() .declarations()
.iter() .iter()
.filter(|v| {
!v.name.starts_with(MCP_INVOKE_META_FUNCTION_NAME_PREFIX)
&& !v.name.starts_with(MCP_LIST_META_FUNCTION_NAME_PREFIX)
})
.map(|v| v.name.to_string()) .map(|v| v.name.to_string())
.collect(); .collect();
if use_tools == "all" { if use_tools == "all" {
@@ -2017,7 +2021,16 @@ impl Config {
} }
if let Some(agent) = &self.agent { if let Some(agent) = &self.agent {
let mut agent_functions = agent.functions().declarations().to_vec(); let mut agent_functions: Vec<FunctionDeclaration> = agent
.functions()
.declarations()
.to_vec()
.into_iter()
.filter(|v| {
!v.name.starts_with(MCP_INVOKE_META_FUNCTION_NAME_PREFIX)
&& !v.name.starts_with(MCP_LIST_META_FUNCTION_NAME_PREFIX)
})
.collect();
let tool_names: HashSet<String> = agent_functions let tool_names: HashSet<String> = agent_functions
.iter() .iter()
.filter_map(|v| { .filter_map(|v| {
@@ -2064,7 +2077,7 @@ impl Config {
format!("{}_{item}", MCP_INVOKE_META_FUNCTION_NAME_PREFIX); format!("{}_{item}", MCP_INVOKE_META_FUNCTION_NAME_PREFIX);
let item_list_name = let item_list_name =
format!("{}_{item}", MCP_LIST_META_FUNCTION_NAME_PREFIX); format!("{}_{item}", MCP_LIST_META_FUNCTION_NAME_PREFIX);
if let Some(values) = self.mapping_tools.get(item) { if let Some(values) = self.mapping_mcp_servers.get(item) {
server_names.extend( server_names.extend(
values values
.split(',') .split(',')
@@ -2105,7 +2118,16 @@ impl Config {
} }
if let Some(agent) = &self.agent { if let Some(agent) = &self.agent {
let mut agent_functions = agent.functions().declarations().to_vec(); let mut agent_functions: Vec<FunctionDeclaration> = agent
.functions()
.declarations()
.to_vec()
.into_iter()
.filter(|v| {
v.name.starts_with(MCP_INVOKE_META_FUNCTION_NAME_PREFIX)
|| v.name.starts_with(MCP_LIST_META_FUNCTION_NAME_PREFIX)
})
.collect();
let tool_names: HashSet<String> = agent_functions let tool_names: HashSet<String> = agent_functions
.iter() .iter()
.filter_map(|v| { .filter_map(|v| {