mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Preserve disabled MCP App UI capability
This commit is contained in:
@@ -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": {}
|
||||
}
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user