diff --git a/crates/jp_cli/src/ctx.rs b/crates/jp_cli/src/ctx.rs index c471da58..adb4e608 100644 --- a/crates/jp_cli/src/ctx.rs +++ b/crates/jp_cli/src/ctx.rs @@ -1,4 +1,5 @@ use std::{ + collections::HashSet, io::{self, IsTerminal as _}, sync::Arc, }; @@ -124,7 +125,7 @@ impl Ctx { pub(crate) async fn configure_active_mcp_servers( &mut self, ) -> Result>> { - let mut server_ids = vec![]; + let mut server_ids = HashSet::new(); for (name, cfg) in self.config.conversation.tools.iter() { if !cfg.enable() { @@ -145,11 +146,11 @@ impl Ctx { } }; - server_ids.push(server_id); + server_ids.insert(server_id); } self.mcp_client - .run_services(&server_ids, self.handle().clone()) + .run_services(server_ids, self.handle().clone()) .await .map_err(Into::into) } diff --git a/crates/jp_mcp/src/client.rs b/crates/jp_mcp/src/client.rs index 4775c1ff..723db508 100644 --- a/crates/jp_mcp/src/client.rs +++ b/crates/jp_mcp/src/client.rs @@ -1,4 +1,11 @@ -use std::{collections::HashMap, env, path::Path, process::Stdio, sync::Arc, time::Duration}; +use std::{ + collections::{HashMap, HashSet}, + env, + path::Path, + process::Stdio, + sync::Arc, + time::Duration, +}; use indexmap::IndexMap; use jp_config::providers::mcp::{AlgorithmConfig, McpProviderConfig}; @@ -174,7 +181,7 @@ impl Client { pub async fn run_services( &mut self, - server_ids: &[McpServerId], + server_ids: HashSet, handle: Handle, ) -> Result>> { let mut clients = self.services.write().await; @@ -195,7 +202,7 @@ impl Client { for server_id in server_ids { // Determine which servers to start (in configs but not currently // active) - if clients.contains_key(server_id) { + if clients.contains_key(&server_id) { continue; } @@ -204,7 +211,6 @@ impl Client { joins.spawn({ let servers = self.servers.clone(); let clients = self.services.clone(); - let server_id = server_id.clone(); async move { let servers = servers.read().await; let server = servers @@ -243,11 +249,11 @@ impl Client { .iter() .filter_map(|key| { env::var(key) - .inspect(|error| { + .inspect_err(|error| { warn!( key, - error, - server = %id, + error = error.to_string(), + server = id.to_string(), "Failed to read MCP server environment variable" ); })