Skip to content

Commit d945e40

Browse files
committed
refines server loading init timeout logic
1 parent 96a84b4 commit d945e40

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

crates/agent/src/agent/agent_config/definitions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ pub struct RemoteMcpServerConfig {
262262
/// OAuth configuration for this server
263263
#[serde(skip_serializing_if = "Option::is_none")]
264264
pub oauth: Option<OAuthConfig>,
265+
/// A boolean flag to denote whether or not to load this mcp server
266+
#[serde(default)]
267+
pub disabled: bool,
265268
}
266269

267270
pub fn default_timeout() -> u64 {

crates/agent/src/agent/mcp/service.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl McpService {
129129
timeout_ms: timeout,
130130
oauth_scopes: scopes,
131131
oauth: oauth_config,
132+
disabled: _,
132133
} = config;
133134

134135
let start_time = Instant::now();

crates/agent/src/agent/mod.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ use tools::{
114114
use tracing::{
115115
debug,
116116
error,
117+
info,
117118
trace,
118119
warn,
119120
};
@@ -343,13 +344,30 @@ impl Agent {
343344
warn!(?self.cached_mcp_configs.overridden_configs, "ignoring overridden configs");
344345
}
345346

346-
for config in &self.cached_mcp_configs.configs {
347+
let mut total_servers_to_be_loaded = 0_usize;
348+
349+
for config in self
350+
.cached_mcp_configs
351+
.configs
352+
.iter()
353+
.filter(|config| match &config.config {
354+
agent_config::definitions::McpServerConfig::Local(local_mcp_server_config) => {
355+
!local_mcp_server_config.disabled
356+
},
357+
agent_config::definitions::McpServerConfig::Remote(remote_mcp_server_config) => {
358+
!remote_mcp_server_config.disabled
359+
},
360+
})
361+
.collect::<Vec<_>>()
362+
{
347363
if let Err(e) = self
348364
.mcp_manager_handle
349365
.launch_server(config.server_name.clone(), config.config.clone())
350366
.await
351367
{
352368
warn!(?config.server_name, ?e, "failed to launch MCP config, skipping");
369+
} else {
370+
total_servers_to_be_loaded += 1;
353371
}
354372
}
355373

@@ -361,7 +379,16 @@ impl Agent {
361379
error!("mcp manager handle channel closed");
362380
break;
363381
};
382+
383+
if matches!(evt, McpServerActorEvent::Initialized{ .. } | McpServerActorEvent::InitializeError { .. }) {
384+
total_servers_to_be_loaded = total_servers_to_be_loaded.saturating_sub(1);
385+
}
364386
self.handle_mcp_server_actor_events(evt).await;
387+
388+
if total_servers_to_be_loaded == 0 {
389+
info!("all mcp servers loaded before timeout");
390+
break;
391+
}
365392
},
366393

367394
_ = tokio::time::sleep_until(timeout_at) => {

0 commit comments

Comments
 (0)