Lightweight coding agent that runs in your terminal
Rust
Add `/mcp login <name>` to the TUI (#49290)
Nick Steele4773a132c351
diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rsindex 37b5c788ad..13b7f9abf5 100644--- a/codex-rs/tui/src/app.rs+++ b/codex-rs/tui/src/app.rs@@ -655,6 +655,9 @@ pub(crate) struct App {/// Invalidates in-flight full rate-limit reads when a newer rolling hard stop arrives.rate_limit_hard_stop_generation: u64,rate_limit_refresh_state: rate_limit_refresh::RateLimitRefreshState,+ pending_mcp_login_start: Option<PendingMcpLoginStart>,+ // Latest accepted attempt per server; stale retry completions must not update the UI.+ active_mcp_login_ids: HashMap<String, String>,// Serialize plugin enablement writes per plugin so stale completions cannot// overwrite a newer toggle, even if the plugin is toggled from different// cwd contexts.@@ -668,6 +671,13 @@ pub(crate) struct App {_test_codex_home: Option<tempfile::TempDir>,}+struct PendingMcpLoginStart {+ request_id: String,+ name: String,+ thread_id: ThreadId,+ completions: Vec<codex_app_server_protocol::McpServerOauthLoginCompletedNotification>,+}+#[derive(Debug, Clone, PartialEq)]struct RuntimePermissionProfileOverride {permission_profile: PermissionProfile,diff --git a/codex-rs/tui/src/app/app_server_event_targets.rs b/codex-rs/tui/src/app/app_server_event_targets.rsindex eb5ffa6ecf..cc63496e9e 100644--- a/codex-rs/tui/src/app/app_server_event_targets.rs+++ b/codex-rs/tui/src/app/app_server_event_targets.rs@@ -184,6 +184,12 @@ pub(super) fn server_notification_thread_target(}ServerNotification::Warning(notification) => notification.thread_id.as_deref(),ServerNotification::GuardianWarning(notification) => Some(notification.thread_id.as_str()),+ ServerNotification::McpServerOauthLoginCompleted(notification) => {+ match notification.thread_id.as_deref() {+ Some(thread_id) => Some(thread_id),+ None => return ServerNotificationThreadTarget::AppScoped,+ }+ }ServerNotification::McpServerStatusUpdated(notification) => {match notification.thread_id.as_deref() {Some(thread_id) => Some(thread_id),@@ -192,7 +198,6 @@ pub(super) fn server_notification_thread_target(}ServerNotification::ProjectChanged(_)| ServerNotification::SkillsChanged(_)- | ServerNotification::McpServerOauthLoginCompleted(_)| ServerNotification::AccountUpdated(_)| ServerNotification::GatewayOAuthChanged(_)| ServerNotification::AccountRateLimitsUpdated(_)diff --git a/codex-rs/tui/src/app/app_server_events.rs b/codex-rs/tui/src/app/app_server_events.rsindex 7f569039b8..50a35bff25 100644--- a/codex-rs/tui/src/app/app_server_events.rs+++ b/codex-rs/tui/src/app/app_server_events.rs@@ -278,6 +278,25 @@ impl App {ServerNotification::McpServerStatusUpdated(_) => {self.refresh_mcp_startup_expected_servers_from_config();}+ ServerNotification::McpServerOauthLoginCompleted(notification) => {+ // The start response identifies the new attempt. Hold completions until then+ // so a replacement's cancellation cannot appear as a fresh login failure.+ if let Some(pending) = self.pending_mcp_login_start.as_mut()+ && pending.name == notification.name+ {+ pending.completions.push(notification.clone());+ return;+ }+ if notification.login_id.is_some() {+ if notification.login_id.as_ref()+ != self.active_mcp_login_ids.get(¬ification.name)+ {+ return;+ }+ self.active_mcp_login_ids.remove(¬ification.name);+ }+ }+ServerNotification::AccountRateLimitsUpdated(notification) => {let workspace_hard_stop = matches!(notification.rate_limits.rate_limit_reached_type,diff --git a/codex-rs/tui/src/app/background_requests.rs b/codex-rs/tui/src/app/background_requests.rsindex 8b29753b3c..69f2aeb458 100644--- a/codex-rs/tui/src/app/background_requests.rs+++ b/codex-rs/tui/src/app/background_requests.rs@@ -24,6 +24,7 @@ use codex_app_server_protocol::MarketplaceRemoveParams;use codex_app_server_protocol::MarketplaceRemoveResponse;use codex_app_server_protocol::MarketplaceUpgradeParams;use codex_app_server_protocol::MarketplaceUpgradeResponse;+use codex_app_server_protocol::McpServerOauthLoginParams;use codex_app_server_protocol::RequestId;use crate::hooks_rpc::fetch_hooks_list;@@ -39,6 +40,33 @@ const WORKSPACE_HEADLINE_FETCH_TIMEOUT: std::time::Duration =std::time::Duration::from_millis(/*millis*/ 2000);impl App {+ pub(super) fn start_mcp_login(+ &self,+ app_server: &AppServerSession,+ request_id: String,+ name: String,+ thread_id: ThreadId,+ ) {+ let request_handle = app_server.request_handle();+ let app_event_tx = self.app_event_tx.clone();+ tokio::spawn(async move {+ let result = request_handle+ .request_typed(ClientRequest::McpServerOauthLogin {+ request_id: RequestId::String(request_id.clone()),+ params: McpServerOauthLoginParams {+ name,+ thread_id: Some(thread_id.to_string()),+ client_registration: None,+ scopes: None,+ timeout_secs: None,+ },+ })+ .await+ .map_err(|error| error.to_string());+ app_event_tx.send(AppEvent::McpLoginStarted { request_id, result });+ });+ }+pub(super) fn fetch_mcp_inventory(&mut self,app_server: &AppServerSession,diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rsindex 1a508b94a4..f8fd11d57b 100644--- a/codex-rs/tui/src/app/event_dispatch.rs+++ b/codex-rs/tui/src/app/event_dispatch.rs@@ -1534,6 +1534,81 @@ impl App {AppEvent::FetchMcpInventory { detail, thread_id } => {self.fetch_mcp_inventory(app_server, detail, thread_id);}+ AppEvent::StartMcpLogin { name, thread_id } => {+ if self.pending_mcp_login_start.is_some() {+ self.chat_widget.add_info_message(+ "MCP sign-in is starting. Wait for it to finish before trying again.".to_string(),+ /*hint*/ None,+ );+ return Ok(AppRunControl::Continue);+ }+ let request_id = format!("mcp-login-{}", uuid::Uuid::new_v4());+ self.pending_mcp_login_start = Some(PendingMcpLoginStart {+ request_id: request_id.clone(),+ name: name.clone(),+ thread_id,+ completions: Vec::new(),+ });+ self.start_mcp_login(app_server, request_id, name, thread_id);+ }+ AppEvent::McpLoginStarted { request_id, result } => {+ if let Some(pending) = self+ .pending_mcp_login_start+ .take_if(|pending| pending.request_id == request_id)+ {+ match result {+ Ok(response) => {+ // Track the latest attempt per server: unrelated OAuth logins can+ // remain open while a user retries this server.+ if let Some(login_id) = response.login_id.as_ref() {+ self.active_mcp_login_ids+ .insert(pending.name.clone(), login_id.clone());+ }+ let completed = pending.completions.iter().any(|completion| {+ completion.login_id == response.login_id+ && completion.name == pending.name+ });+ if !completed {+ self.open_url_in_browser(response.authorization_url);+ }+ }+ Err(error) => {+ self.enqueue_thread_notification(+ pending.thread_id,+ ServerNotification::McpServerOauthLoginCompleted(+ codex_app_server_protocol::McpServerOauthLoginCompletedNotification {+ name: pending.name,+ thread_id: Some(pending.thread_id.to_string()),+ login_id: None,+ success: false,+ error: Some(error),+ },+ ),+ ).await?;+ }+ }+ // A rejected start leaves the old attempt current. A successful replacement+ // has changed its ID, so the old cancellation is discarded here.+ for completion in pending.completions {+ if completion.login_id.is_some() {+ if completion.login_id.as_ref()+ != self.active_mcp_login_ids.get(&completion.name)+ {+ continue;+ }+ self.active_mcp_login_ids.remove(&completion.name);+ }+ if let Some(thread_id) = completion.thread_id.as_deref()+ .and_then(|id| ThreadId::from_string(id).ok())+ {+ self.enqueue_thread_notification(+ thread_id,+ ServerNotification::McpServerOauthLoginCompleted(completion),+ ).await?;+ }+ }+ }+ }AppEvent::McpInventoryLoaded {result,detail,diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__slash_picker_overlays_history.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__slash_picker_overlays_history.snapindex f25cc394f3..20e5d5c268 100644--- a/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__slash_picker_overlays_history.snap+++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__owned_transcript__tests__slash_picker_overlays_history.snap@@ -10,7 +10,7 @@ Transcript row 34: content behind the menu› /model choose what model and reasoning effort to use/memories configure memory use and generation/mention mention a file- /mcp list configured MCP tools; use /mcp verbose for details+ /mcp list MCP tools; use /mcp verbose or /mcp login <name>› /mdiff --git a/codex-rs/tui/src/app/startup.rs b/codex-rs/tui/src/app/startup.rsindex 0cdd4ce30c..1f8702fbfb 100644--- a/codex-rs/tui/src/app/startup.rs+++ b/codex-rs/tui/src/app/startup.rs@@ -881,6 +881,8 @@ See the Codex keymap documentation for supported actions and examples."startup_pending_protected_request: false,rate_limit_hard_stop_generation: 0,rate_limit_refresh_state: Default::default(),+ pending_mcp_login_start: None,+ active_mcp_login_ids: HashMap::new(),pending_plugin_enabled_writes: HashMap::new(),pending_hook_enabled_writes: HashMap::new(),recap: recap::RecapState::default(),diff --git a/codex-rs/tui/src/app/test_support.rs b/codex-rs/tui/src/app/test_support.rsindex 135c411dd1..5e6dcf7be5 100644--- a/codex-rs/tui/src/app/test_support.rs+++ b/codex-rs/tui/src/app/test_support.rs@@ -114,6 +114,8 @@ pub(crate) async fn make_test_app() -> App {startup_pending_protected_request: false,rate_limit_hard_stop_generation: 0,rate_limit_refresh_state: Default::default(),+ pending_mcp_login_start: None,+ active_mcp_login_ids: HashMap::new(),pending_plugin_enabled_writes: HashMap::new(),pending_hook_enabled_writes: HashMap::new(),recap: recap::RecapState::default(),diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rsindex ab54b10d05..8d54e52e55 100644--- a/codex-rs/tui/src/app/tests.rs+++ b/codex-rs/tui/src/app/tests.rs@@ -1,5 +1,8 @@//! App-level orchestration tests for the TUI.+#[path = "tests/mcp_login_tests.rs"]+mod mcp_login_tests;+#[path = "tests/daybreak_tests.rs"]mod daybreak_tests;#[path = "tests/math_interruption_tests.rs"]@@ -6090,6 +6093,8 @@ async fn make_test_app() -> Box<App> {startup_pending_protected_request: false,rate_limit_hard_stop_generation: 0,rate_limit_refresh_state: Default::default(),+ pending_mcp_login_start: None,+ active_mcp_login_ids: HashMap::new(),pending_plugin_enabled_writes: HashMap::new(),pending_hook_enabled_writes: HashMap::new(),recap: recap::RecapState::default(),@@ -6207,6 +6212,8 @@ pub(super) async fn make_test_app_with_channels() -> (startup_pending_protected_request: false,rate_limit_hard_stop_generation: 0,rate_limit_refresh_state: Default::default(),+ pending_mcp_login_start: None,+ active_mcp_login_ids: HashMap::new(),pending_plugin_enabled_writes: HashMap::new(),pending_hook_enabled_writes: HashMap::new(),recap: recap::RecapState::default(),diff --git a/codex-rs/tui/src/app/tests/mcp_login_tests.rs b/codex-rs/tui/src/app/tests/mcp_login_tests.rsnew file mode 100644index 0000000000..9b4942ca49--- /dev/null+++ b/codex-rs/tui/src/app/tests/mcp_login_tests.rs@@ -0,0 +1,301 @@+//! Regression coverage for overlapping starts, replacement attempts, and thread-scoped results.+use super::*;+use codex_app_server_protocol::McpServerOauthLoginCompletedNotification;+use codex_app_server_protocol::McpServerOauthLoginResponse;+use pretty_assertions::assert_eq;++#[tokio::test]+async fn overlapping_mcp_login_preserves_first_start() {+ let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;+ while events.try_recv().is_ok() {}+ let mut server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())+ .await+ .unwrap();+ let mut tui = crate::tui::test_support::make_test_tui().unwrap();+ let thread_id = ThreadId::new();+ app.pending_mcp_login_start = Some(PendingMcpLoginStart {+ request_id: "first".into(),+ name: "enterprise".into(),+ thread_id,+ completions: Vec::new(),+ });+ app.handle_event(+ &mut tui,+ &mut server,+ AppEvent::StartMcpLogin {+ name: "typo".into(),+ thread_id,+ },+ )+ .await+ .unwrap();+ assert_eq!(+ app.pending_mcp_login_start.as_ref().unwrap().request_id,+ "first"+ );+ assert_snapshot!("overlapping_mcp_login", next_history_message(&mut events));+ app.handle_event(+ &mut tui,+ &mut server,+ AppEvent::McpLoginStarted {+ request_id: "first".into(),+ result: Err("first start failed".into()),+ },+ )+ .await+ .unwrap();+ let snapshot = app.thread_event_channels[&thread_id]+ .store+ .lock()+ .await+ .snapshot();+ for event in snapshot.events {+ app.handle_thread_event_replay(event);+ }+ assert!(next_history_message(&mut events).contains("first start failed"));+ assert!(app.pending_mcp_login_start.is_none());+ server.shutdown().await.unwrap();+}++#[tokio::test]+async fn mcp_login_retry_suppresses_old_completion_and_late_browser_open() {+ let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;+ while events.try_recv().is_ok() {}+ let mut server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())+ .await+ .unwrap();+ let mut tui = crate::tui::test_support::make_test_tui().unwrap();+ let thread_id = ThreadId::new();+ app.primary_thread_id = Some(thread_id);+ app.active_thread_id = Some(thread_id);+ app.active_mcp_login_ids+ .insert("enterprise".into(), "old".into());+ app.active_mcp_login_ids+ .insert("other".into(), "other-login".into());+ app.pending_mcp_login_start = Some(PendingMcpLoginStart {+ request_id: "retry".into(),+ name: "enterprise".into(),+ thread_id,+ completions: Vec::new(),+ });+ for (login_id, success) in [("old", false), ("new", true)] {+ app.handle_app_server_event(+ &server,+ codex_app_server_client::AppServerEvent::ServerNotification(Box::new(+ ServerNotification::McpServerOauthLoginCompleted(+ McpServerOauthLoginCompletedNotification {+ name: "enterprise".into(),+ thread_id: Some(thread_id.to_string()),+ login_id: Some(login_id.into()),+ success,+ error: (!success).then(|| "Enterprise sign-in failed.".into()),+ },+ ),+ )),+ )+ .await;+ }+ assert!(events.try_recv().is_err());+ app.handle_event(+ &mut tui,+ &mut server,+ AppEvent::McpLoginStarted {+ request_id: "retry".into(),+ result: Ok(McpServerOauthLoginResponse {+ authorization_url: String::new(),+ login_id: Some("new".into()),+ }),+ },+ )+ .await+ .unwrap();+ let snapshot = app.thread_event_channels[&thread_id]+ .store+ .lock()+ .await+ .snapshot();+ assert_eq!(snapshot.events.len(), 1);+ for event in snapshot.events {+ app.handle_thread_event_replay(event);+ }+ assert_snapshot!(+ "mcp_login_retry_completion",+ next_history_message(&mut events)+ );+ assert!(events.try_recv().is_err());+ // A cancellation delivered after the replacement response is stale as well.+ app.handle_app_server_event(+ &server,+ codex_app_server_client::AppServerEvent::ServerNotification(Box::new(+ ServerNotification::McpServerOauthLoginCompleted(+ McpServerOauthLoginCompletedNotification {+ name: "enterprise".into(),+ thread_id: Some(thread_id.to_string()),+ login_id: Some("old".into()),+ success: false,+ error: Some("Enterprise sign-in failed.".into()),+ },+ ),+ )),+ )+ .await;+ assert_eq!(+ app.thread_event_channels[&thread_id]+ .store+ .lock()+ .await+ .snapshot()+ .events+ .len(),+ 1+ );+ // Retrying one server must not discard a different server's outstanding OAuth result.+ app.handle_app_server_event(+ &server,+ codex_app_server_client::AppServerEvent::ServerNotification(Box::new(+ ServerNotification::McpServerOauthLoginCompleted(+ McpServerOauthLoginCompletedNotification {+ name: "other".into(),+ thread_id: Some(thread_id.to_string()),+ login_id: Some("other-login".into()),+ success: true,+ error: None,+ },+ ),+ )),+ )+ .await;+ let snapshot = app.thread_event_channels[&thread_id]+ .store+ .lock()+ .await+ .snapshot();+ assert_eq!(snapshot.events.len(), 2);+ app.handle_thread_event_replay(snapshot.events.last().unwrap().clone());+ assert!(next_history_message(&mut events).contains("Signed in to other."));+ server.shutdown().await.unwrap();+}++#[tokio::test]+async fn mcp_login_results_survive_thread_switch_and_session_refresh() {+ for success in [true, false] {+ let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;+ while events.try_recv().is_ok() {}+ let server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())+ .await+ .unwrap();+ let origin = ThreadId::new();+ app.primary_thread_id = Some(origin);+ app.active_thread_id = Some(ThreadId::new());+ app.active_mcp_login_ids+ .insert("enterprise".into(), "login".into());+ app.handle_app_server_event(+ &server,+ codex_app_server_client::AppServerEvent::ServerNotification(Box::new(+ ServerNotification::McpServerOauthLoginCompleted(+ McpServerOauthLoginCompletedNotification {+ name: "enterprise".into(),+ thread_id: Some(origin.to_string()),+ login_id: Some("login".into()),+ success,+ error: (!success).then(|| "Enterprise sign-in failed.".into()),+ },+ ),+ )),+ )+ .await;+ assert!(events.try_recv().is_err());+ let snapshot = {+ let mut store = app.thread_event_channels[&origin].store.lock().await;+ store.rebase_buffer_after_session_refresh();+ store.snapshot()+ };+ assert_eq!(snapshot.events.len(), 1);+ app.active_thread_id = Some(origin);+ for event in snapshot.events {+ app.handle_thread_event_replay(event);+ }+ assert_snapshot!(+ format!("mcp_login_switched_thread_{success}"),+ next_history_message(&mut events)+ );+ server.shutdown().await.unwrap();+ }+}++#[tokio::test]+async fn rejected_mcp_login_retry_preserves_previous_result() {+ let (mut app, mut events, _op_rx) = make_test_app_with_channels().await;+ while events.try_recv().is_ok() {}+ let mut server = crate::start_embedded_app_server_for_picker(app.chat_widget.config_ref())+ .await+ .unwrap();+ let mut tui = crate::tui::test_support::make_test_tui().unwrap();+ let thread_id = ThreadId::new();+ app.primary_thread_id = Some(thread_id);+ app.active_thread_id = Some(thread_id);+ app.active_mcp_login_ids+ .insert("enterprise".into(), "old".into());+ app.pending_mcp_login_start = Some(PendingMcpLoginStart {+ request_id: "typo".into(),+ name: "typo".into(),+ thread_id,+ completions: Vec::new(),+ });+ app.handle_app_server_event(+ &server,+ codex_app_server_client::AppServerEvent::ServerNotification(Box::new(+ ServerNotification::McpServerOauthLoginCompleted(+ McpServerOauthLoginCompletedNotification {+ name: "enterprise".into(),+ thread_id: Some(thread_id.to_string()),+ login_id: Some("old".into()),+ success: true,+ error: None,+ },+ ),+ )),+ )+ .await;+ // The other server's result is already retained while this start is still pending.+ assert_eq!(+ app.thread_event_channels[&thread_id]+ .store+ .lock()+ .await+ .snapshot()+ .events+ .len(),+ 1+ );+ app.handle_event(+ &mut tui,+ &mut server,+ AppEvent::McpLoginStarted {+ request_id: "typo".into(),+ result: Err("Unknown MCP server typo".into()),+ },+ )+ .await+ .unwrap();+ let snapshot = app.thread_event_channels[&thread_id]+ .store+ .lock()+ .await+ .snapshot();+ assert_eq!(snapshot.events.len(), 2);+ for event in snapshot.events {+ app.handle_thread_event_replay(event);+ }+ let messages = std::iter::from_fn(|| events.try_recv().ok())+ .filter_map(|event| {+ if let AppEvent::InsertHistoryCell(cell) = event {+ Some(lines_to_single_string(&cell.display_lines(/*width*/ 80)))+ } else {+ None+ }+ })+ .collect::<Vec<_>>();+ assert_snapshot!("rejected_mcp_login_retry", messages.join("\n"));+ server.shutdown().await.unwrap();+}diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_retry_completion.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_retry_completion.snapnew file mode 100644index 0000000000..90a48554bc--- /dev/null+++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_retry_completion.snap@@ -0,0 +1,5 @@+---+source: tui/src/app/tests/mcp_login_tests.rs+expression: next_history_message(&mut events)+---+• Signed in to enterprise.diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_switched_thread_false.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_switched_thread_false.snapnew file mode 100644index 0000000000..0e30c178ea--- /dev/null+++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_switched_thread_false.snap@@ -0,0 +1,5 @@+---+source: tui/src/app/tests/mcp_login_tests.rs+expression: next_history_message(&mut events)+---+■ Enterprise sign-in failed.diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_switched_thread_true.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_switched_thread_true.snapnew file mode 100644index 0000000000..90a48554bc--- /dev/null+++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__mcp_login_switched_thread_true.snap@@ -0,0 +1,5 @@+---+source: tui/src/app/tests/mcp_login_tests.rs+expression: next_history_message(&mut events)+---+• Signed in to enterprise.diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__overlapping_mcp_login.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__overlapping_mcp_login.snapnew file mode 100644index 0000000000..3e374865e1--- /dev/null+++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__overlapping_mcp_login.snap@@ -0,0 +1,5 @@+---+source: tui/src/app/tests/mcp_login_tests.rs+expression: next_history_message(&mut events)+---+• MCP sign-in is starting. Wait for it to finish before trying again.diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__rejected_mcp_login_retry.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__rejected_mcp_login_retry.snapnew file mode 100644index 0000000000..367f6a4a39--- /dev/null+++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__mcp_login_tests__rejected_mcp_login_retry.snap@@ -0,0 +1,6 @@+---+source: tui/src/app/tests/mcp_login_tests.rs+expression: "messages.join(\"\\n\")"+---+• Signed in to enterprise.+■ Unknown MCP server typodiff --git a/codex-rs/tui/src/app/thread_events.rs b/codex-rs/tui/src/app/thread_events.rsindex b7d34f637f..602ba745f9 100644--- a/codex-rs/tui/src/app/thread_events.rs+++ b/codex-rs/tui/src/app/thread_events.rs@@ -100,6 +100,7 @@ impl ThreadEventStore {ServerNotification::HookStarted(_)| ServerNotification::HookCompleted(_)| ServerNotification::McpServerStatusUpdated(_)+ | ServerNotification::McpServerOauthLoginCompleted(_)),ThreadBufferedEvent::HistoryEntryResponse(_) => false,}diff --git a/codex-rs/tui/src/app_event.rs b/codex-rs/tui/src/app_event.rsindex 6381d91a2d..9e3a2beb75 100644--- a/codex-rs/tui/src/app_event.rs+++ b/codex-rs/tui/src/app_event.rs@@ -22,6 +22,7 @@ use codex_app_server_protocol::GetAccountRateLimitsResponse;use codex_app_server_protocol::MarketplaceAddResponse;use codex_app_server_protocol::MarketplaceRemoveResponse;use codex_app_server_protocol::MarketplaceUpgradeResponse;+use codex_app_server_protocol::McpServerOauthLoginResponse;use codex_app_server_protocol::McpServerStatus;use codex_app_server_protocol::McpServerStatusDetail;use codex_app_server_protocol::PluginInstallResponse;@@ -1067,6 +1068,16 @@ pub(crate) enum AppEvent {thread_id: Option<ThreadId>,},+ StartMcpLogin {+ name: String,+ thread_id: ThreadId,+ },++ McpLoginStarted {+ request_id: String,+ result: Result<McpServerOauthLoginResponse, String>,+ },+/// Result of fetching MCP inventory via app-server RPCs.McpInventoryLoaded {result: Result<Vec<McpServerStatus>, String>,diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snap b/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snapindex 0e69fbe2aa..bb446cf9e1 100644--- a/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snap+++ b/codex-rs/tui/src/bottom_pane/chat_composer/snapshots/codex_tui__bottom_pane__chat_composer__status_surface__tests__slash_popup_footer_wide.snap@@ -9,7 +9,7 @@ Buffer {" /model choose what model and reasoning effort to use ","› /memories configure memory use and generation "," /mention mention a file ",- " /mcp list configured MCP tools; use /mcp verbose for details ",+ " /mcp list MCP tools; use /mcp verbose or /mcp login <name> "," ","› /m "," ",@@ -32,7 +32,7 @@ Buffer {x: 3, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD,x: 4, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,x: 13, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,- x: 68, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,+ x: 66, y: 3, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,x: 0, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: BOLD,x: 1, y: 5, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,]diff --git a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snap b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snapindex a46aed6b7c..c306d6235e 100644--- a/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snap+++ b/codex-rs/tui/src/bottom_pane/snapshots/codex_tui__bottom_pane__command_popup__tests__command_popup_default_items.snap@@ -41,7 +41,7 @@ expression: commands/statusline - configure which items appear in the status line/theme - choose a syntax highlighting theme/pets - choose or hide the terminal pet-/mcp - list configured MCP tools; use /mcp verbose for details+/mcp - list MCP tools; use /mcp verbose or /mcp login <name>/logout - log out of Codex/exit - exit Codex/feedback - send logs to maintainersdiff --git a/codex-rs/tui/src/chatwidget/protocol.rs b/codex-rs/tui/src/chatwidget/protocol.rsindex ba0d2e4061..51ac5f09b3 100644--- a/codex-rs/tui/src/chatwidget/protocol.rs+++ b/codex-rs/tui/src/chatwidget/protocol.rs@@ -44,6 +44,20 @@ impl ChatWidget {self.restore_retry_status_header_if_present();}match notification {+ ServerNotification::McpServerOauthLoginCompleted(notification) => {+ if notification.success {+ self.add_info_message(+ format!("Signed in to {}.", notification.name),+ /*hint*/ None,+ );+ } else {+ self.add_error_message(+ notification+ .error+ .unwrap_or_else(|| "MCP sign-in failed.".to_string()),+ );+ }+ }ServerNotification::ThreadTokenUsageUpdated(notification) => {self.set_token_info(Some(token_usage_info_from_app_server(notification.token_usage,@@ -359,7 +373,6 @@ impl ChatWidget {| ServerNotification::McpServerEventStream(_)| ServerNotification::FileChangePatchUpdated(_)| ServerNotification::McpToolCallProgress(_)- | ServerNotification::McpServerOauthLoginCompleted(_)| ServerNotification::AppListUpdated(_)| ServerNotification::EnvironmentConnected(_)| ServerNotification::EnvironmentDisconnected(_)diff --git a/codex-rs/tui/src/chatwidget/slash_dispatch.rs b/codex-rs/tui/src/chatwidget/slash_dispatch.rsindex 4fe2ed057b..5546acb955 100644--- a/codex-rs/tui/src/chatwidget/slash_dispatch.rs+++ b/codex-rs/tui/src/chatwidget/slash_dispatch.rs@@ -803,10 +803,27 @@ impl ChatWidget {SlashCommand::Ide => {self.handle_ide_command_args(trimmed);}- SlashCommand::Mcp => match trimmed.to_ascii_lowercase().as_str() {- "verbose" => self.add_mcp_output(McpServerStatusDetail::Full),- _ => self.add_error_message("Usage: /mcp [verbose]".to_string()),- },+ SlashCommand::Mcp => {+ if trimmed.eq_ignore_ascii_case("verbose") {+ self.add_mcp_output(McpServerStatusDetail::Full);+ } else if let Some((command, name)) = trimmed.split_once(' ')+ && command.eq_ignore_ascii_case("login")+ && !name.trim().is_empty()+ {+ if let Some(thread_id) = self.thread_id {+ self.app_event_tx.send(AppEvent::StartMcpLogin {+ name: name.trim().to_string(),+ thread_id,+ });+ } else {+ self.add_error_message(+ "MCP sign-in requires an active session.".to_string(),+ );+ }+ } else {+ self.add_error_message("Usage: /mcp [verbose | login <name>]".to_string());+ }+ }SlashCommand::Keymap => match trimmed.to_ascii_lowercase().as_str() {"" => self.open_keymap_picker(),"debug" => {diff --git a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs b/codex-rs/tui/src/chatwidget/tests/slash_commands.rsindex e8e5b4c459..5cada9f2f8 100644--- a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs+++ b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs@@ -2731,6 +2731,23 @@ async fn slash_mcp_verbose_requests_full_inventory_via_app_server() {assert!(op_rx.try_recv().is_err(), "expected no core op to be sent");}+#[tokio::test]+async fn slash_mcp_login_targets_the_active_thread() {+ let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;+ let thread_id = ThreadId::new();+ chat.thread_id = Some(thread_id);++ submit_composer_text(&mut chat, "/mcp login enterprise");++ assert_matches!(rx.try_recv(), Ok(AppEvent::FollowTranscript));+ assert_matches!(+ rx.try_recv(),+ Ok(AppEvent::StartMcpLogin { name, thread_id: actual_thread_id })+ if name == "enterprise" && actual_thread_id == thread_id+ );+ assert!(op_rx.try_recv().is_err(), "expected no core op to be sent");+}+#[tokio::test]async fn slash_mcp_invalid_args_show_usage() {let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;@@ -2744,7 +2761,7 @@ async fn slash_mcp_invalid_args_show_usage() {.collect::<Vec<_>>().join("\n");assert!(- rendered.contains("Usage: /mcp [verbose]"),+ rendered.contains("Usage: /mcp [verbose | login <name>]"),"expected usage message, got: {rendered:?}");assert_eq!(recall_latest_after_clearing(&mut chat), "/mcp full");diff --git a/codex-rs/tui/src/slash_command.rs b/codex-rs/tui/src/slash_command.rsindex 301de2e054..85eabb59dc 100644--- a/codex-rs/tui/src/slash_command.rs+++ b/codex-rs/tui/src/slash_command.rs@@ -147,7 +147,7 @@ impl SlashCommand {SlashCommand::Experimental => "toggle experimental features",SlashCommand::AutoReview => "approve one retry of a recent auto-review denial",SlashCommand::Memories => "configure memory use and generation",- SlashCommand::Mcp => "list configured MCP tools; use /mcp verbose for details",+ SlashCommand::Mcp => "list MCP tools; use /mcp verbose or /mcp login <name>",SlashCommand::Apps => "manage apps",SlashCommand::Plugins => "browse plugins",SlashCommand::Logout => "log out of Codex",