feat(mcp): hide background startup status by default

This commit is contained in:
Felipe Coury
2026-05-30 00:23:43 -03:00
parent 00ca857d3f
commit 3b8aed7525
15 changed files with 309 additions and 64 deletions
+1
View File
@@ -1836,6 +1836,7 @@ impl ChatWidget {
}
pub(crate) fn sync_plugin_mentions_config(&mut self, config: &Config) {
self.sync_mcp_startup_status_config(config.tui_show_mcp_startup_status);
self.config.features = config.features.clone();
self.config.config_layer_stack = config.config_layer_stack.clone();
self.config.realtime = config.realtime.clone();
+31 -2
View File
@@ -1,8 +1,8 @@
//! MCP startup state and status handling for the chat widget.
//!
//! The app server reports MCP server startup as per-server status updates. This
//! module keeps the TUI's buffered startup round state coherent and translates
//! those updates into status headers, warnings, and queued-input release points.
//! module keeps optional diagnostic presentation state coherent when background
//! startup status display is explicitly enabled.
use std::collections::BTreeSet;
@@ -176,6 +176,9 @@ impl ChatWidget {
}
pub(super) fn finish_mcp_startup(&mut self, failed: Vec<String>, cancelled: Vec<String>) {
if !self.config.tui_show_mcp_startup_status {
return;
}
if !cancelled.is_empty() {
self.on_warning(format!(
"MCP startup interrupted. The following servers were not initialized: {}",
@@ -205,6 +208,9 @@ impl ChatWidget {
}
pub(crate) fn finish_mcp_startup_after_lag(&mut self) {
if !self.config.tui_show_mcp_startup_status {
return;
}
if self.mcp_startup_ignore_updates_until_next_start {
if self.mcp_startup_pending_next_round.is_empty() {
self.mcp_startup_pending_next_round_saw_starting = false;
@@ -257,6 +263,9 @@ impl ChatWidget {
&mut self,
notification: McpServerStatusUpdatedNotification,
) {
if !self.config.tui_show_mcp_startup_status {
return;
}
let status = match notification.status {
McpServerStartupState::Starting => McpStartupStatus::Starting,
McpServerStartupState::Ready => McpStartupStatus::Ready,
@@ -273,4 +282,24 @@ impl ChatWidget {
/*complete_when_settled*/ true,
);
}
pub(crate) fn sync_mcp_startup_status_config(&mut self, show_status: bool) {
let was_visible = self.config.tui_show_mcp_startup_status;
self.config.tui_show_mcp_startup_status = show_status;
if was_visible && !show_status {
let mcp_startup_owned_status = self.status_header_is_mcp_startup_owned();
self.mcp_startup_status = None;
self.mcp_startup_expected_servers = None;
self.mcp_startup_ignore_updates_until_next_start = false;
self.mcp_startup_allow_terminal_only_next_round = false;
self.mcp_startup_pending_next_round.clear();
self.mcp_startup_pending_next_round_saw_starting = false;
self.update_task_running_state();
if mcp_startup_owned_status {
self.restore_reasoning_status_header();
}
self.maybe_send_next_queued_input();
self.request_redraw();
}
}
}
@@ -0,0 +1,9 @@
---
source: tui/src/chatwidget/tests/mcp_startup.rs
expression: normalized_backend_snapshot(terminal.backend())
---
" "
" "
"› Ask Codex to do anything "
" "
" gpt-5.5 default · /tmp/project "
@@ -781,8 +781,8 @@ impl ChatWidget {
/// Computes the compact runtime status label used by word-based status items.
///
/// Startup takes precedence over normal task states, and idle state renders
/// as `Ready` regardless of the last active status bucket.
/// Visible diagnostic startup takes precedence over normal task states, and
/// idle state renders as `Ready` regardless of the last active status bucket.
pub(super) fn run_state_status_text(&self) -> String {
if self.mcp_startup_status.is_some() {
return "Starting".to_string();
@@ -2,6 +2,7 @@ use super::*;
use pretty_assertions::assert_eq;
fn notify_mcp_status(chat: &mut ChatWidget, name: &str, status: McpServerStartupState) {
chat.config.tui_show_mcp_startup_status = true;
chat.handle_server_notification(
ServerNotification::McpServerStatusUpdated(McpServerStatusUpdatedNotification {
name: name.to_string(),
@@ -13,6 +14,7 @@ fn notify_mcp_status(chat: &mut ChatWidget, name: &str, status: McpServerStartup
}
fn notify_mcp_status_error(chat: &mut ChatWidget, name: &str, error: &str) {
chat.config.tui_show_mcp_startup_status = true;
chat.handle_server_notification(
ServerNotification::McpServerStatusUpdated(McpServerStatusUpdatedNotification {
name: name.to_string(),
@@ -23,6 +25,47 @@ fn notify_mcp_status_error(chat: &mut ChatWidget, name: &str, error: &str) {
);
}
#[tokio::test]
async fn mcp_startup_status_is_hidden_by_default_snapshot() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.show_welcome_banner = false;
chat.set_mcp_startup_expected_servers(["alpha".to_string()]);
chat.handle_server_notification(
ServerNotification::McpServerStatusUpdated(McpServerStatusUpdatedNotification {
name: "alpha".to_string(),
status: McpServerStartupState::Starting,
error: None,
}),
/*replay_kind*/ None,
);
chat.handle_server_notification(
ServerNotification::McpServerStatusUpdated(McpServerStatusUpdatedNotification {
name: "alpha".to_string(),
status: McpServerStartupState::Failed,
error: Some("MCP client for `alpha` failed to start: handshake failed".to_string()),
}),
/*replay_kind*/ None,
);
assert!(chat.mcp_startup_status.is_none());
assert!(!chat.bottom_pane.is_task_running());
assert!(drain_insert_history(&mut rx).is_empty());
let height = chat.desired_height(/*width*/ 80);
let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(
/*width*/ 80, height,
))
.expect("create terminal");
terminal
.draw(|f| chat.render(f.area(), f.buffer_mut()))
.expect("draw chat widget");
assert_chatwidget_snapshot!(
"mcp_startup_status_is_hidden_by_default",
normalized_backend_snapshot(terminal.backend())
);
}
#[tokio::test]
async fn mcp_startup_header_booting_snapshot() {
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
+2 -2
View File
@@ -8,8 +8,8 @@ use super::*;
impl ChatWidget {
/// Synchronize the bottom-pane "task running" indicator with the current lifecycles.
///
/// The bottom pane only has one running flag, but this module treats it as a derived state of
/// both the agent turn lifecycle and MCP startup lifecycle.
/// The bottom pane only has one running flag, but MCP startup enters this
/// visible lifecycle only when its diagnostic presentation is enabled.
pub(super) fn update_task_running_state(&mut self) {
self.bottom_pane.set_task_running(
self.turn_lifecycle.agent_turn_running || self.mcp_startup_status.is_some(),