From 8762da8d13df360183389f9f104d56c0a63e5a46 Mon Sep 17 00:00:00 2001 From: martinauyeung-oai <280153141+martinauyeung-oai@users.noreply.github.com> Date: Tue, 7 Jul 2026 13:53:29 -0700 Subject: [PATCH] Preserve disabled MCP App UI capability --- codex-rs/codex-mcp/src/client_capabilities.rs | 36 +++++++++---------- .../src/client_capabilities_tests.rs | 9 +++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/codex-rs/codex-mcp/src/client_capabilities.rs b/codex-rs/codex-mcp/src/client_capabilities.rs index 04d304d3cf..0a9c0666f3 100644 --- a/codex-rs/codex-mcp/src/client_capabilities.rs +++ b/codex-rs/codex-mcp/src/client_capabilities.rs @@ -25,35 +25,35 @@ pub fn supports_mcp_app_ui_webview(extensions: Option<&HashMap>) }) } -/// Adds trusted host capabilities to a Codex Apps request and removes any -/// caller-supplied copy of the reserved metadata key. +/// Adds a trusted host capability profile to a Codex Apps request and removes +/// any caller-supplied copy of the reserved metadata key. +/// +/// An explicit empty profile is important for hosts without WebView support: +/// downstream connector MCP sessions preserve WebView as the legacy default +/// when client capabilities are absent. pub fn with_mcp_app_ui_client_capabilities_meta( meta: Option, supports_mcp_app_ui_webview: bool, ) -> Option { - let meta = match meta { + let mut object = match meta { Some(Value::Object(mut object)) => { object.remove(MCP_CLIENT_CAPABILITIES_META_KEY); - Some(Value::Object(object)) + object } - other => other, - }; - if !supports_mcp_app_ui_webview { - return meta; - } - let mut object = match meta { - Some(Value::Object(object)) => object, _ => Map::new(), }; + let extensions = if supports_mcp_app_ui_webview { + serde_json::json!({ + MCP_APP_UI_EXTENSION_ID: { + "mimeTypes": [MCP_APP_UI_WEBVIEW_MIME_TYPE], + } + }) + } else { + serde_json::json!({}) + }; object.insert( MCP_CLIENT_CAPABILITIES_META_KEY.to_string(), - serde_json::json!({ - "extensions": { - MCP_APP_UI_EXTENSION_ID: { - "mimeTypes": [MCP_APP_UI_WEBVIEW_MIME_TYPE], - } - } - }), + serde_json::json!({ "extensions": extensions }), ); Some(Value::Object(object)) } diff --git a/codex-rs/codex-mcp/src/client_capabilities_tests.rs b/codex-rs/codex-mcp/src/client_capabilities_tests.rs index 4039c90b3f..26d027fd46 100644 --- a/codex-rs/codex-mcp/src/client_capabilities_tests.rs +++ b/codex-rs/codex-mcp/src/client_capabilities_tests.rs @@ -59,7 +59,7 @@ fn trusted_capabilities_replace_spoofed_request_metadata() { } #[test] -fn absent_host_capabilities_remove_spoofed_request_metadata() { +fn disabled_hosts_send_an_explicit_empty_capability_profile() { assert_eq!( with_mcp_app_ui_client_capabilities_meta( Some(json!({ @@ -68,7 +68,12 @@ fn absent_host_capabilities_remove_spoofed_request_metadata() { })), /*supports_mcp_app_ui_webview*/ false, ), - Some(json!({"caller": "preserved"})) + Some(json!({ + "caller": "preserved", + MCP_CLIENT_CAPABILITIES_META_KEY: { + "extensions": {} + } + })) ); }