mirror of
https://github.com/openai/codex.git
synced 2026-11-22 07:13:50 +00:00
Report runtime MCP connection status (#40068)
## Why MCP inventory can be cached or collected separately from a thread's live connections, so tool availability alone does not describe the current runtime state. ## What changed - Add a nullable `runtimeStatus` to `mcpServerStatus/list` for thread-scoped requests, covering not-started, starting, connected, authentication-required, failed, cancelled, and disabled connections. - Observe published connection state without starting or reconnecting servers, and return an unknown status when no thread is supplied or the active configuration no longer matches the published registration. - Show connection state and tool counts in the compact `/mcp` view while retaining the detailed inventory in `/mcp verbose` and compatibility with servers that omit `runtimeStatus`. ## Testing - Cover runtime status transitions, deferred and disabled servers, closed transports, configuration changes, protocol compatibility, and TUI rendering. GitOrigin-RevId: e3bb6efe652f0fa8b3c97d5c53e4729b3a87cd91
This commit is contained in:
1 parent
4f39251a01
commit
343074d420
34 files changed
+899
-48
No files matched your search
@@ -1557,6 +1557,7 @@ mod tests {
|
||||
let statuses = vec![
|
||||
McpServerStatus {
|
||||
name: "docs".to_string(),
|
||||
runtime_status: None,
|
||||
plugin_id: None,
|
||||
server_info: None,
|
||||
tools: HashMap::from([(
|
||||
@@ -1578,6 +1579,7 @@ mod tests {
|
||||
},
|
||||
McpServerStatus {
|
||||
name: "disabled".to_string(),
|
||||
runtime_status: None,
|
||||
plugin_id: None,
|
||||
server_info: None,
|
||||
tools: HashMap::new(),
|
||||
|
||||
@@ -256,6 +256,7 @@ async fn handle_mcp_inventory_result_respects_origin_thread() {
|
||||
app.handle_mcp_inventory_result(
|
||||
Ok(vec![McpServerStatus {
|
||||
name: "docs".to_string(),
|
||||
runtime_status: None,
|
||||
plugin_id: None,
|
||||
server_info: None,
|
||||
tools: HashMap::new(),
|
||||
|
||||
@@ -5,6 +5,10 @@ use super::*;
|
||||
#[path = "mcp_result.rs"]
|
||||
mod result;
|
||||
|
||||
use crate::style::StatusTone;
|
||||
use crate::style::accent_style;
|
||||
use crate::style::status_style;
|
||||
use codex_app_server_protocol::McpServerConnectionStatus;
|
||||
use result::McpResultKind;
|
||||
use result::McpToolResult;
|
||||
|
||||
@@ -518,9 +522,8 @@ pub(crate) fn new_mcp_tools_output(
|
||||
/// alphabetically. The TUI deliberately does not enrich these rows from
|
||||
/// client-local config because the app-server owns the remote MCP state.
|
||||
///
|
||||
/// This mirrors the layout of [`new_mcp_tools_output`] but sources data from
|
||||
/// the paginated RPC response rather than the in-process `McpManager`. The
|
||||
/// `detail` flag controls whether resources and resource templates are rendered.
|
||||
/// Normal output is a compact connection summary. Full detail preserves the
|
||||
/// tool, auth, resource, and resource-template inventory.
|
||||
pub(crate) fn new_mcp_tools_output_from_statuses(
|
||||
statuses: &[McpServerStatus],
|
||||
detail: McpServerStatusDetail,
|
||||
@@ -536,15 +539,54 @@ pub(crate) fn new_mcp_tools_output_from_statuses(
|
||||
statuses.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
|
||||
let has_any_tools = statuses.iter().any(|status| !status.tools.is_empty());
|
||||
if !has_any_tools {
|
||||
if !has_any_tools && matches!(detail, McpServerStatusDetail::Full) {
|
||||
lines.push(" • No MCP tools available.".italic().into());
|
||||
lines.push("".into());
|
||||
}
|
||||
|
||||
for status in statuses {
|
||||
let header: Vec<Span<'static>> = vec![" • ".into(), status.name.clone().into()];
|
||||
|
||||
lines.push(header.into());
|
||||
let (label, style) = match status.runtime_status {
|
||||
Some(McpServerConnectionStatus::Connected) => {
|
||||
("connected", status_style(StatusTone::Success))
|
||||
}
|
||||
Some(McpServerConnectionStatus::Starting) => ("starting", accent_style()),
|
||||
Some(McpServerConnectionStatus::AuthenticationRequired) => (
|
||||
"authentication required",
|
||||
status_style(StatusTone::Attention),
|
||||
),
|
||||
Some(McpServerConnectionStatus::Failed) => {
|
||||
("failed", status_style(StatusTone::Failure))
|
||||
}
|
||||
Some(McpServerConnectionStatus::NotStarted) => ("not started", Style::default().dim()),
|
||||
Some(McpServerConnectionStatus::Disabled) => ("disabled", Style::default().dim()),
|
||||
Some(McpServerConnectionStatus::Cancelled) => ("cancelled", Style::default().dim()),
|
||||
None if matches!(
|
||||
status.auth_status,
|
||||
codex_app_server_protocol::McpAuthStatus::NotLoggedIn
|
||||
) =>
|
||||
{
|
||||
(
|
||||
"authentication required",
|
||||
status_style(StatusTone::Attention),
|
||||
)
|
||||
}
|
||||
None => ("unknown", Style::default().dim()),
|
||||
};
|
||||
let count = status.tools.len();
|
||||
let unit = if count == 1 { "tool" } else { "tools" };
|
||||
lines.push(
|
||||
vec![
|
||||
" • ".set_style(style),
|
||||
status.name.clone().bold(),
|
||||
": ".into(),
|
||||
label.set_style(style),
|
||||
format!(" ({count} {unit})").dim(),
|
||||
]
|
||||
.into(),
|
||||
);
|
||||
if matches!(detail, McpServerStatusDetail::ToolsAndAuthOnly) {
|
||||
continue;
|
||||
}
|
||||
let auth_status = match status.auth_status {
|
||||
codex_app_server_protocol::McpAuthStatus::Unknown => McpAuthStatus::Unknown,
|
||||
codex_app_server_protocol::McpAuthStatus::Unsupported => McpAuthStatus::Unsupported,
|
||||
@@ -613,6 +655,11 @@ pub(crate) fn new_mcp_tools_output_from_statuses(
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
|
||||
if matches!(detail, McpServerStatusDetail::ToolsAndAuthOnly) {
|
||||
lines.push("".into());
|
||||
lines.push(" Use /mcp verbose for tools and resources.".dim().into());
|
||||
}
|
||||
|
||||
PlainHistoryCell { lines }
|
||||
}
|
||||
/// A transient history cell that shows an animated spinner while the MCP
|
||||
|
||||
@@ -7,6 +7,121 @@ use serde_json::json;
|
||||
|
||||
const PNG: &str = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==";
|
||||
|
||||
#[test]
|
||||
fn mcp_inventory_connection_states() {
|
||||
use McpServerConnectionStatus as Status;
|
||||
|
||||
let statuses = [
|
||||
("unknown", None),
|
||||
("starting", Some(Status::Starting)),
|
||||
("failed", Some(Status::Failed)),
|
||||
("disabled", Some(Status::Disabled)),
|
||||
("deferred", Some(Status::NotStarted)),
|
||||
("connected-empty", Some(Status::Connected)),
|
||||
("cancelled", Some(Status::Cancelled)),
|
||||
("auth", Some(Status::AuthenticationRequired)),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, runtime_status)| McpServerStatus {
|
||||
name: name.to_string(),
|
||||
runtime_status,
|
||||
plugin_id: None,
|
||||
server_info: None,
|
||||
tools: HashMap::new(),
|
||||
resources: Vec::new(),
|
||||
resource_templates: Vec::new(),
|
||||
auth_status: McpAuthStatus::Unknown,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let cell =
|
||||
new_mcp_tools_output_from_statuses(&statuses, McpServerStatusDetail::ToolsAndAuthOnly);
|
||||
let rendered = cell
|
||||
.display_lines(/*width*/ 100)
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!(rendered);
|
||||
for (name, expected) in [
|
||||
("auth", status_style(StatusTone::Attention)),
|
||||
("cancelled", Style::default().dim()),
|
||||
("connected-empty", status_style(StatusTone::Success)),
|
||||
("deferred", Style::default().dim()),
|
||||
("disabled", Style::default().dim()),
|
||||
("failed", status_style(StatusTone::Failure)),
|
||||
("starting", accent_style()),
|
||||
("unknown", Style::default().dim()),
|
||||
] {
|
||||
let row = cell
|
||||
.lines
|
||||
.iter()
|
||||
.find(|line| line.spans.get(1).is_some_and(|span| span.content == name))
|
||||
.expect("connection-state row");
|
||||
assert_eq!(
|
||||
(row.spans[0].style, row.spans[3].style),
|
||||
(expected, expected)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mcp_inventory_older_app_server_authentication() {
|
||||
let statuses = serde_json::from_value::<Vec<McpServerStatus>>(json!([
|
||||
{
|
||||
"name": "legacy-auth",
|
||||
"tools": {},
|
||||
"resources": [],
|
||||
"resourceTemplates": [],
|
||||
"authStatus": "notLoggedIn"
|
||||
},
|
||||
{
|
||||
"name": "legacy-healthy",
|
||||
"tools": {"lookup": {"name": "lookup", "inputSchema": {"type": "object"}}},
|
||||
"resources": [],
|
||||
"resourceTemplates": [],
|
||||
"authStatus": "oAuth"
|
||||
},
|
||||
{
|
||||
"name": "runtime-disabled",
|
||||
"runtimeStatus": "disabled",
|
||||
"tools": {},
|
||||
"resources": [],
|
||||
"resourceTemplates": [],
|
||||
"authStatus": "notLoggedIn"
|
||||
}
|
||||
]))
|
||||
.expect("mixed-version MCP statuses");
|
||||
let cell =
|
||||
new_mcp_tools_output_from_statuses(&statuses, McpServerStatusDetail::ToolsAndAuthOnly);
|
||||
let rendered = cell
|
||||
.display_lines(/*width*/ 100)
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::assert_snapshot!(rendered);
|
||||
let styles = cell
|
||||
.lines
|
||||
.iter()
|
||||
.filter(|line| {
|
||||
line.spans
|
||||
.get(1)
|
||||
.is_some_and(|span| statuses.iter().any(|status| span.content == status.name))
|
||||
})
|
||||
.map(|line| (line.spans[0].style, line.spans[3].style))
|
||||
.collect::<Vec<_>>();
|
||||
let attention = status_style(StatusTone::Attention);
|
||||
let neutral = Style::default().dim();
|
||||
assert_eq!(
|
||||
styles,
|
||||
vec![
|
||||
(attention, attention),
|
||||
(neutral, neutral),
|
||||
(neutral, neutral)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
fn result(content: Vec<Value>) -> CallToolResult {
|
||||
CallToolResult {
|
||||
content,
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
---
|
||||
source: tui/src/history_cell/mcp_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
/mcp
|
||||
|
||||
🔌 MCP Tools
|
||||
|
||||
• auth: authentication required (0 tools)
|
||||
• cancelled: cancelled (0 tools)
|
||||
• connected-empty: connected (0 tools)
|
||||
• deferred: not started (0 tools)
|
||||
• disabled: disabled (0 tools)
|
||||
• failed: failed (0 tools)
|
||||
• starting: starting (0 tools)
|
||||
• unknown: unknown (0 tools)
|
||||
|
||||
Use /mcp verbose for tools and resources.
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
---
|
||||
source: tui/src/history_cell/mcp_tests.rs
|
||||
expression: rendered
|
||||
---
|
||||
/mcp
|
||||
|
||||
🔌 MCP Tools
|
||||
|
||||
• legacy-auth: authentication required (0 tools)
|
||||
• legacy-healthy: unknown (1 tool)
|
||||
• runtime-disabled: disabled (0 tools)
|
||||
|
||||
Use /mcp verbose for tools and resources.
|
||||
+3
-3
@@ -6,6 +6,6 @@ expression: rendered
|
||||
|
||||
🔌 MCP Tools
|
||||
|
||||
• plugin_docs
|
||||
• Auth: Unknown
|
||||
• Tools: lookup
|
||||
• plugin_docs: unknown (1 tool)
|
||||
|
||||
Use /mcp verbose for tools and resources.
|
||||
+1
-1
@@ -6,7 +6,7 @@ expression: rendered
|
||||
|
||||
🔌 MCP Tools
|
||||
|
||||
• plugin_docs
|
||||
• plugin_docs: unknown (1 tool)
|
||||
• Auth: Unsupported
|
||||
• Tools: lookup
|
||||
• Resources: Docs (file:///docs)
|
||||
|
||||
@@ -964,6 +964,7 @@ async fn mcp_tools_output_lists_tools_for_hyphenated_server_names() {
|
||||
fn mcp_tools_output_from_statuses_renders_status_only_servers() {
|
||||
let statuses = vec![McpServerStatus {
|
||||
name: "plugin_docs".to_string(),
|
||||
runtime_status: None,
|
||||
plugin_id: None,
|
||||
server_info: None,
|
||||
tools: HashMap::from([(
|
||||
@@ -995,6 +996,7 @@ fn mcp_tools_output_from_statuses_renders_status_only_servers() {
|
||||
fn mcp_tools_output_from_statuses_renders_verbose_inventory() {
|
||||
let statuses = vec![McpServerStatus {
|
||||
name: "plugin_docs".to_string(),
|
||||
runtime_status: None,
|
||||
plugin_id: None,
|
||||
server_info: None,
|
||||
tools: HashMap::from([(
|
||||
|
||||
@@ -4,12 +4,42 @@ use crate::terminal_palette::StdoutColorLevel;
|
||||
use crate::terminal_palette::best_color;
|
||||
use crate::terminal_palette::default_bg;
|
||||
use crate::terminal_palette::default_fg;
|
||||
use crate::terminal_palette::effective_stdout_color_level;
|
||||
use crate::terminal_palette::rgb_color;
|
||||
use crate::terminal_palette::stdout_color_level;
|
||||
use ratatui::style::Color;
|
||||
use ratatui::style::Style;
|
||||
|
||||
const LIGHT_BG_ACCENT_RGB: (u8, u8, u8) = (0, 95, 135);
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum StatusTone {
|
||||
Success,
|
||||
Attention,
|
||||
Failure,
|
||||
}
|
||||
|
||||
/// Semantic status colors that preserve the terminal's configured palette.
|
||||
pub(crate) fn status_style(tone: StatusTone) -> Style {
|
||||
status_style_for(tone, default_bg(), effective_stdout_color_level())
|
||||
}
|
||||
|
||||
fn status_style_for(
|
||||
tone: StatusTone,
|
||||
terminal_bg: Option<(u8, u8, u8)>,
|
||||
color_level: StdoutColorLevel,
|
||||
) -> Style {
|
||||
let light = terminal_bg.is_some_and(is_light);
|
||||
let color = match (tone, color_level) {
|
||||
(_, StdoutColorLevel::Unknown) => Color::Reset,
|
||||
(StatusTone::Success, _) => Color::Green,
|
||||
(StatusTone::Failure, _) => Color::Red,
|
||||
// Yellow can disappear on light themes; use it only with a known dark background.
|
||||
(StatusTone::Attention, _) if light || terminal_bg.is_none() => Color::Reset,
|
||||
(StatusTone::Attention, _) => Color::Yellow,
|
||||
};
|
||||
Style::default().fg(color).bold()
|
||||
}
|
||||
// Decorative table rules should remain visible without competing with cell content.
|
||||
const TABLE_SEPARATOR_FG_ALPHA: f32 = 0.20;
|
||||
|
||||
@@ -96,6 +126,54 @@ mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::style::Modifier;
|
||||
|
||||
#[test]
|
||||
fn status_colors_preserve_light_terminal_themes() {
|
||||
for level in [StdoutColorLevel::TrueColor, StdoutColorLevel::Ansi256] {
|
||||
for bg in [(255, 255, 255), (130, 130, 130), (220, 210, 180)] {
|
||||
for (tone, color) in [
|
||||
(StatusTone::Success, Color::Green),
|
||||
(StatusTone::Attention, Color::Reset),
|
||||
(StatusTone::Failure, Color::Red),
|
||||
] {
|
||||
assert_eq!(
|
||||
status_style_for(tone, Some(bg), level),
|
||||
Style::default().fg(color).bold(),
|
||||
);
|
||||
}
|
||||
}
|
||||
for bg in [(0, 0, 0), (0, 218, 0)] {
|
||||
assert_eq!(
|
||||
status_style_for(StatusTone::Attention, Some(bg), level),
|
||||
Style::default().fg(Color::Yellow).bold(),
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
status_style_for(StatusTone::Attention, /*terminal_bg*/ None, level),
|
||||
Style::default().fg(Color::Reset).bold(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_colors_preserve_ansi16_and_no_color_fallbacks() {
|
||||
for (tone, light, dark) in [
|
||||
(StatusTone::Success, Color::Green, Color::Green),
|
||||
(StatusTone::Attention, Color::Reset, Color::Yellow),
|
||||
(StatusTone::Failure, Color::Red, Color::Red),
|
||||
] {
|
||||
for (bg, expected) in [((255, 255, 255), light), ((0, 0, 0), dark)] {
|
||||
assert_eq!(
|
||||
status_style_for(tone, Some(bg), StdoutColorLevel::Ansi16),
|
||||
Style::default().fg(expected).bold()
|
||||
);
|
||||
assert_eq!(
|
||||
status_style_for(tone, Some(bg), StdoutColorLevel::Unknown),
|
||||
Style::default().fg(Color::Reset).bold()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accent_style_uses_darker_cyan_on_light_backgrounds() {
|
||||
let style = accent_style_for(Some((255, 255, 255)));
|
||||
|
||||
Reference in new issue
Block a user