Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/jp_cli/src/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
collections::HashSet,
io::{self, IsTerminal as _},
sync::Arc,
};
Expand Down Expand Up @@ -124,7 +125,7 @@ impl Ctx {
pub(crate) async fn configure_active_mcp_servers(
&mut self,
) -> Result<JoinSet<std::result::Result<(), jp_mcp::Error>>> {
let mut server_ids = vec![];
let mut server_ids = HashSet::new();

for (name, cfg) in self.config.conversation.tools.iter() {
if !cfg.enable() {
Expand All @@ -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)
}
Expand Down
20 changes: 13 additions & 7 deletions crates/jp_mcp/src/client.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -174,7 +181,7 @@ impl Client {

pub async fn run_services(
&mut self,
server_ids: &[McpServerId],
server_ids: HashSet<McpServerId>,
handle: Handle,
) -> Result<JoinSet<Result<()>>> {
let mut clients = self.services.write().await;
Expand All @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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"
);
})
Expand Down
Loading