Skip to content

Commit 1bae6b6

Browse files
committed
refines server loading init timeout logic
1 parent 8fdd426 commit 1bae6b6

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
@@ -115,6 +115,7 @@ use tools::{
115115
use tracing::{
116116
debug,
117117
error,
118+
info,
118119
trace,
119120
warn,
120121
};
@@ -344,13 +345,30 @@ impl Agent {
344345
warn!(?self.cached_mcp_configs.overridden_configs, "ignoring overridden configs");
345346
}
346347

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

@@ -362,7 +380,16 @@ impl Agent {
362380
error!("mcp manager handle channel closed");
363381
break;
364382
};
383+
384+
if matches!(evt, McpServerActorEvent::Initialized{ .. } | McpServerActorEvent::InitializeError { .. }) {
385+
total_servers_to_be_loaded = total_servers_to_be_loaded.saturating_sub(1);
386+
}
365387
self.handle_mcp_server_actor_events(evt).await;
388+
389+
if total_servers_to_be_loaded == 0 {
390+
info!("all mcp servers loaded before timeout");
391+
break;
392+
}
366393
},
367394

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

0 commit comments

Comments
 (0)