Preserve disabled MCP App UI capability

This commit is contained in:
martinauyeung-oai
2026-07-07 13:53:29 -07:00
parent ed2012fd06
commit 8762da8d13
2 changed files with 25 additions and 20 deletions
+18 -18
View File
@@ -25,35 +25,35 @@ pub fn supports_mcp_app_ui_webview(extensions: Option<&HashMap<String, Value>>)
})
}
/// 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<Value>,
supports_mcp_app_ui_webview: bool,
) -> Option<Value> {
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))
}
@@ -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": {}
}
}))
);
}