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:
Eric Traut authored and copyberry committed 2026-08-22 05:54:43 +00:00
1 parent 4f39251a01
commit 343074d420
34 files changed
+899 -48

No files matched your search

@@ -30,6 +30,19 @@ v2_enum_from_core!(
}
);
v2_enum_from_core!(
#[ts(rename_all = "camelCase")]
pub enum McpServerConnectionStatus from codex_protocol::mcp::McpServerConnectionStatus {
NotStarted,
Starting,
Connected,
AuthenticationRequired,
Failed,
Cancelled,
Disabled
}
);
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
@@ -61,6 +74,8 @@ pub enum McpServerStatusDetail {
#[ts(export_to = "v2/")]
pub struct McpServerStatus {
pub name: String,
/// Current thread-runtime connection state; null when unavailable or the configuration changed.
pub runtime_status: Option<McpServerConnectionStatus>,
pub plugin_id: Option<String>,
pub server_info: Option<McpServerInfo>,
pub tools: std::collections::HashMap<String, McpTool>,
@@ -2506,6 +2506,7 @@ fn mcp_server_status_serializes_absent_server_info_as_null() {
let response = ListMcpServerStatusResponse {
data: vec![McpServerStatus {
name: "not-ready".to_string(),
runtime_status: None,
plugin_id: None,
server_info: None,
tools: HashMap::new(),
@@ -2521,6 +2522,7 @@ fn mcp_server_status_serializes_absent_server_info_as_null() {
json!({
"data": [{
"name": "not-ready",
"runtimeStatus": null,
"pluginId": null,
"serverInfo": null,
"tools": {},
@@ -2533,6 +2535,33 @@ fn mcp_server_status_serializes_absent_server_info_as_null() {
);
}
#[test]
fn mcp_server_status_accepts_older_inventory_without_runtime_status() {
let status: McpServerStatus = serde_json::from_value(json!({
"name": "older-server",
"pluginId": null,
"serverInfo": null,
"tools": {},
"resources": [],
"resourceTemplates": [],
"authStatus": "unknown",
}))
.expect("older app-server inventory should deserialize");
assert_eq!(
status,
McpServerStatus {
name: "older-server".to_string(),
runtime_status: None,
plugin_id: None,
server_info: None,
tools: HashMap::new(),
resources: Vec::new(),
resource_templates: Vec::new(),
auth_status: McpAuthStatus::Unknown,
}
);
}
#[test]
fn mcp_server_status_updated_accepts_missing_thread_id() {
let notification: McpServerStatusUpdatedNotification = serde_json::from_value(json!({
@@ -2593,6 +2622,7 @@ fn mcp_server_status_serializes_absent_server_info_metadata_as_null() {
let response = ListMcpServerStatusResponse {
data: vec![McpServerStatus {
name: "initialized".to_string(),
runtime_status: None,
plugin_id: Some("lookup@test".to_string()),
server_info: Some(McpServerInfo {
name: "lookup-server".to_string(),
@@ -2615,6 +2645,7 @@ fn mcp_server_status_serializes_absent_server_info_metadata_as_null() {
json!({
"data": [{
"name": "initialized",
"runtimeStatus": null,
"pluginId": "lookup@test",
"serverInfo": {
"name": "lookup-server",