fix: make McpConnectionManager tolerant of MCPs that fail to start (#854)

I added a typo in my `config.toml` such that the `command` for one of my
`mcp_servers` did not exist and I verified that the error was surfaced
in the TUI (and that I was still able to use Codex).


![image](https://github.com/user-attachments/assets/f13cc08c-f4c6-40ec-9ab4-a9d75e03152f)
This commit is contained in:
Michael Bolin
2025-05-08 23:45:54 -07:00
committed by GitHub
parent b940adae8e
commit 27198bfe11
2 changed files with 56 additions and 20 deletions

View File

@@ -561,15 +561,35 @@ async fn submission_loop(
let writable_roots = Mutex::new(get_writable_roots(&cwd));
let mcp_connection_manager =
// Error messages to dispatch after SessionConfigured is sent.
let mut mcp_connection_errors = Vec::<Event>::new();
let (mcp_connection_manager, failed_clients) =
match McpConnectionManager::new(config.mcp_servers.clone()).await {
Ok(mgr) => mgr,
Ok((mgr, failures)) => (mgr, failures),
Err(e) => {
error!("Failed to create MCP connection manager: {e:#}");
McpConnectionManager::default()
let message = format!("Failed to create MCP connection manager: {e:#}");
error!("{message}");
mcp_connection_errors.push(Event {
id: sub.id.clone(),
msg: EventMsg::Error { message },
});
(McpConnectionManager::default(), Default::default())
}
};
// Surface individual client start-up failures to the user.
if !failed_clients.is_empty() {
for (server_name, err) in failed_clients {
let message =
format!("MCP client for `{server_name}` failed to start: {err:#}");
error!("{message}");
mcp_connection_errors.push(Event {
id: sub.id.clone(),
msg: EventMsg::Error { message },
});
}
}
// Attempt to create a RolloutRecorder *before* moving the
// `instructions` value into the Session struct.
let rollout_recorder = match RolloutRecorder::new(instructions.clone()).await {
@@ -596,12 +616,15 @@ async fn submission_loop(
}));
// ack
let event = Event {
id: sub.id,
let events = std::iter::once(Event {
id: sub.id.clone(),
msg: EventMsg::SessionConfigured { model },
};
if tx_event.send(event).await.is_err() {
return;
})
.chain(mcp_connection_errors.into_iter());
for event in events {
if let Err(e) = tx_event.send(event).await {
error!("failed to send event: {e:?}");
}
}
}
Op::UserInput { items } => {