Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix: improve MCP server initialization error handling #3196 #2346 #2555 (#3243)

Biturdcad37009e155
diff --git a/codex-rs/core/src/mcp_connection_manager.rs b/codex-rs/core/src/mcp_connection_manager.rs
index 563a4e13e9..387ea1730c 100644
--- a/codex-rs/core/src/mcp_connection_manager.rs
+++ b/codex-rs/core/src/mcp_connection_manager.rs
@@ -187,7 +187,13 @@ impl McpConnectionManager {
let mut clients: HashMap<String, ManagedClient> = HashMap::with_capacity(join_set.len());
while let Some(res) = join_set.join_next().await {
- let (server_name, client_res) = res?; // JoinError propagation
+ let (server_name, client_res) = match res {
+ Ok((server_name, client_res)) => (server_name, client_res),
+ Err(e) => {
+ warn!("Task panic when starting MCP server: {e:#}");
+ continue;
+ }
+ };
match client_res {
Ok((client, startup_timeout)) => {
@@ -205,7 +211,13 @@ impl McpConnectionManager {
}
}
- let all_tools = list_all_tools(&clients).await?;
+ let all_tools = match list_all_tools(&clients).await {
+ Ok(tools) => tools,
+ Err(e) => {
+ warn!("Failed to list tools from some MCP servers: {e:#}");
+ Vec::new()
+ }
+ };
let tools = qualify_tools(all_tools);
@@ -270,8 +282,19 @@ async fn list_all_tools(clients: &HashMap<String, ManagedClient>) -> Result<Vec<
let mut aggregated: Vec<ToolInfo> = Vec::with_capacity(join_set.len());
while let Some(join_res) = join_set.join_next().await {
- let (server_name, list_result) = join_res?;
- let list_result = list_result?;
+ let (server_name, list_result) = if let Ok(result) = join_res {
+ result
+ } else {
+ warn!("Task panic when listing tools for MCP server: {join_res:#?}");
+ continue;
+ };
+
+ let list_result = if let Ok(result) = list_result {
+ result
+ } else {
+ warn!("Failed to list tools for MCP server '{server_name}': {list_result:#?}");
+ continue;
+ };
for tool in list_result.tools {
let tool_info = ToolInfo {