mirror of
https://github.com/openai/codex.git
synced 2026-11-17 22:10:37 +00:00
Handle Xcode 26.4 MCP elicitation compatibility
This commit is contained in:
@@ -17,6 +17,7 @@ use crate::codex_apps::CodexAppsToolsCacheContext;
|
||||
use crate::codex_apps::CodexAppsToolsCacheKey;
|
||||
use crate::codex_apps::write_cached_codex_apps_tools_if_needed;
|
||||
use crate::elicitation::ElicitationRequestManager;
|
||||
use crate::elicitation::McpElicitationCompatibility;
|
||||
use crate::mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use crate::mcp::ToolPluginProvenance;
|
||||
use crate::rmcp_client::AsyncManagedClient;
|
||||
@@ -142,13 +143,17 @@ impl McpConnectionManager {
|
||||
codex_apps_tools_cache_key: CodexAppsToolsCacheKey,
|
||||
tool_plugin_provenance: ToolPluginProvenance,
|
||||
auth: Option<&CodexAuth>,
|
||||
elicitation_compatibility: McpElicitationCompatibility,
|
||||
) -> (Self, CancellationToken) {
|
||||
let cancel_token = CancellationToken::new();
|
||||
let mut clients = HashMap::new();
|
||||
let mut server_origins = HashMap::new();
|
||||
let mut join_set = JoinSet::new();
|
||||
let elicitation_requests =
|
||||
ElicitationRequestManager::new(approval_policy.value(), initial_permission_profile);
|
||||
let elicitation_requests = ElicitationRequestManager::new_with_compatibility(
|
||||
approval_policy.value(),
|
||||
initial_permission_profile,
|
||||
elicitation_compatibility,
|
||||
);
|
||||
let tool_plugin_provenance = Arc::new(tool_plugin_provenance);
|
||||
let startup_submit_id = submit_id.clone();
|
||||
let codex_apps_auth_provider = auth
|
||||
@@ -197,6 +202,7 @@ impl McpConnectionManager {
|
||||
cancel_token.clone(),
|
||||
tx_event.clone(),
|
||||
elicitation_requests.clone(),
|
||||
elicitation_compatibility,
|
||||
codex_apps_tools_cache_context,
|
||||
Arc::clone(&tool_plugin_provenance),
|
||||
runtime_environment.clone(),
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::codex_apps::read_cached_codex_apps_tools;
|
||||
use crate::codex_apps::write_cached_codex_apps_tools;
|
||||
use crate::declared_openai_file_input_param_names;
|
||||
use crate::elicitation::ElicitationRequestManager;
|
||||
use crate::elicitation::McpElicitationCompatibility;
|
||||
use crate::elicitation::elicitation_is_rejected_by_policy;
|
||||
use crate::rmcp_client::AsyncManagedClient;
|
||||
use crate::rmcp_client::ManagedClient;
|
||||
@@ -266,6 +267,47 @@ async fn disabled_permissions_do_not_auto_accept_elicitation_with_requested_fiel
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn codex_apps_only_custom_server_elicitation_is_declined_without_event() {
|
||||
let manager = ElicitationRequestManager::new_with_compatibility(
|
||||
AskForApproval::OnRequest,
|
||||
PermissionProfile::default(),
|
||||
McpElicitationCompatibility::CodexAppsOnly,
|
||||
);
|
||||
let (tx_event, rx_event) = async_channel::bounded(1);
|
||||
let sender = manager.make_sender("custom_mcp".to_string(), tx_event);
|
||||
|
||||
let response = sender(
|
||||
NumberOrString::Number(1),
|
||||
CreateElicitationRequestParams::FormElicitationParams {
|
||||
meta: None,
|
||||
message: "What should I say?".to_string(),
|
||||
requested_schema: rmcp::model::ElicitationSchema::builder()
|
||||
.required_property(
|
||||
"message",
|
||||
rmcp::model::PrimitiveSchema::String(rmcp::model::StringSchema::new()),
|
||||
)
|
||||
.build()
|
||||
.expect("schema should build"),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("elicitation should auto decline");
|
||||
|
||||
assert_eq!(
|
||||
response,
|
||||
ElicitationResponse {
|
||||
action: ElicitationAction::Decline,
|
||||
content: None,
|
||||
meta: None,
|
||||
}
|
||||
);
|
||||
assert!(matches!(
|
||||
rx_event.try_recv(),
|
||||
Err(async_channel::TryRecvError::Empty)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_qualify_tools_short_non_duplicated_names() {
|
||||
let tools = vec![
|
||||
@@ -802,7 +844,8 @@ async fn list_all_tools_uses_startup_snapshot_when_client_startup_fails() {
|
||||
#[test]
|
||||
fn elicitation_capability_uses_2025_06_18_shape_for_all_servers() {
|
||||
for server_name in [CODEX_APPS_MCP_SERVER_NAME, "custom_mcp"] {
|
||||
let capability = elicitation_capability_for_server(server_name);
|
||||
let capability =
|
||||
elicitation_capability_for_server(server_name, McpElicitationCompatibility::Default);
|
||||
assert_eq!(capability, Some(ElicitationCapability::default()));
|
||||
assert_eq!(
|
||||
serde_json::to_value(capability).expect("serialize elicitation capability"),
|
||||
@@ -811,6 +854,21 @@ fn elicitation_capability_uses_2025_06_18_shape_for_all_servers() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codex_apps_only_elicitation_capability_keeps_codex_apps_enabled() {
|
||||
assert_eq!(
|
||||
elicitation_capability_for_server(
|
||||
CODEX_APPS_MCP_SERVER_NAME,
|
||||
McpElicitationCompatibility::CodexAppsOnly,
|
||||
),
|
||||
Some(ElicitationCapability::default())
|
||||
);
|
||||
assert_eq!(
|
||||
elicitation_capability_for_server("custom_mcp", McpElicitationCompatibility::CodexAppsOnly,),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mcp_init_error_display_prompts_for_github_pat() {
|
||||
let server_name = "github";
|
||||
|
||||
@@ -9,6 +9,7 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex as StdMutex;
|
||||
|
||||
use crate::mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use crate::mcp::McpPermissionPromptAutoApproveContext;
|
||||
use crate::mcp::mcp_permission_prompt_is_auto_approved;
|
||||
use anyhow::Context;
|
||||
@@ -36,17 +37,31 @@ pub(crate) struct ElicitationRequestManager {
|
||||
requests: Arc<Mutex<ResponderMap>>,
|
||||
pub(crate) approval_policy: Arc<StdMutex<AskForApproval>>,
|
||||
pub(crate) permission_profile: Arc<StdMutex<PermissionProfile>>,
|
||||
compatibility: McpElicitationCompatibility,
|
||||
}
|
||||
|
||||
impl ElicitationRequestManager {
|
||||
pub(crate) fn new(
|
||||
approval_policy: AskForApproval,
|
||||
permission_profile: PermissionProfile,
|
||||
) -> Self {
|
||||
Self::new_with_compatibility(
|
||||
approval_policy,
|
||||
permission_profile,
|
||||
McpElicitationCompatibility::Default,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_compatibility(
|
||||
approval_policy: AskForApproval,
|
||||
permission_profile: PermissionProfile,
|
||||
compatibility: McpElicitationCompatibility,
|
||||
) -> Self {
|
||||
Self {
|
||||
requests: Arc::new(Mutex::new(HashMap::new())),
|
||||
approval_policy: Arc::new(StdMutex::new(approval_policy)),
|
||||
permission_profile: Arc::new(StdMutex::new(permission_profile)),
|
||||
compatibility,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +88,7 @@ impl ElicitationRequestManager {
|
||||
let elicitation_requests = self.requests.clone();
|
||||
let approval_policy = self.approval_policy.clone();
|
||||
let permission_profile = self.permission_profile.clone();
|
||||
let compatibility = self.compatibility;
|
||||
Box::new(move |id, elicitation| {
|
||||
let elicitation_requests = elicitation_requests.clone();
|
||||
let tx_event = tx_event.clone();
|
||||
@@ -80,6 +96,14 @@ impl ElicitationRequestManager {
|
||||
let approval_policy = approval_policy.clone();
|
||||
let permission_profile = permission_profile.clone();
|
||||
async move {
|
||||
if !compatibility.allows_server_elicitation(&server_name) {
|
||||
return Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Decline,
|
||||
content: None,
|
||||
meta: None,
|
||||
});
|
||||
}
|
||||
|
||||
let approval_policy = approval_policy
|
||||
.lock()
|
||||
.map(|policy| *policy)
|
||||
@@ -169,6 +193,28 @@ impl ElicitationRequestManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Compatibility policy for the MCP elicitation capability surface.
|
||||
///
|
||||
/// The default behavior advertises MCP elicitation support to every server.
|
||||
/// `CodexAppsOnly` preserves the pre-PR #17043 capability surface by keeping
|
||||
/// support for the built-in `codex_apps` server while suppressing support for
|
||||
/// custom MCP servers.
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
pub enum McpElicitationCompatibility {
|
||||
#[default]
|
||||
Default,
|
||||
CodexAppsOnly,
|
||||
}
|
||||
|
||||
impl McpElicitationCompatibility {
|
||||
pub(crate) fn allows_server_elicitation(self, server_name: &str) -> bool {
|
||||
match self {
|
||||
Self::Default => true,
|
||||
Self::CodexAppsOnly => server_name == CODEX_APPS_MCP_SERVER_NAME,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn elicitation_is_rejected_by_policy(approval_policy: AskForApproval) -> bool {
|
||||
match approval_policy {
|
||||
AskForApproval::Never => true,
|
||||
|
||||
@@ -34,6 +34,7 @@ pub use mcp::resolve_oauth_scopes;
|
||||
pub use mcp::should_retry_without_scopes;
|
||||
|
||||
pub use codex_apps::filter_non_codex_apps_mcp_tools_only;
|
||||
pub use elicitation::McpElicitationCompatibility;
|
||||
pub use mcp::McpPermissionPromptAutoApproveContext;
|
||||
pub use mcp::mcp_permission_prompt_is_auto_approved;
|
||||
pub use mcp::qualified_mcp_tool_name_prefix;
|
||||
|
||||
@@ -255,6 +255,7 @@ pub async fn read_mcp_resource(
|
||||
codex_apps_tools_cache_key(auth),
|
||||
tool_plugin_provenance(config),
|
||||
auth,
|
||||
crate::McpElicitationCompatibility::default(),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -320,6 +321,7 @@ pub async fn collect_mcp_server_status_snapshot_with_detail(
|
||||
codex_apps_tools_cache_key(auth),
|
||||
tool_plugin_provenance,
|
||||
auth,
|
||||
crate::McpElicitationCompatibility::default(),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ use crate::codex_apps::normalize_codex_apps_callable_namespace;
|
||||
use crate::codex_apps::normalize_codex_apps_tool_title;
|
||||
use crate::codex_apps::write_cached_codex_apps_tools_if_needed;
|
||||
use crate::elicitation::ElicitationRequestManager;
|
||||
use crate::elicitation::McpElicitationCompatibility;
|
||||
use crate::mcp::CODEX_APPS_MCP_SERVER_NAME;
|
||||
use crate::mcp::ToolPluginProvenance;
|
||||
use crate::runtime::McpRuntimeEnvironment;
|
||||
@@ -138,6 +139,7 @@ impl AsyncManagedClient {
|
||||
cancel_token: CancellationToken,
|
||||
tx_event: Sender<Event>,
|
||||
elicitation_requests: ElicitationRequestManager,
|
||||
elicitation_compatibility: McpElicitationCompatibility,
|
||||
codex_apps_tools_cache_context: Option<CodexAppsToolsCacheContext>,
|
||||
tool_plugin_provenance: Arc<ToolPluginProvenance>,
|
||||
runtime_environment: McpRuntimeEnvironment,
|
||||
@@ -180,6 +182,7 @@ impl AsyncManagedClient {
|
||||
tool_filter: startup_tool_filter,
|
||||
tx_event,
|
||||
elicitation_requests,
|
||||
elicitation_compatibility,
|
||||
codex_apps_tools_cache_context,
|
||||
},
|
||||
)
|
||||
@@ -318,8 +321,16 @@ impl From<anyhow::Error> for StartupOutcomeError {
|
||||
}
|
||||
|
||||
pub(crate) fn elicitation_capability_for_server(
|
||||
_server_name: &str,
|
||||
server_name: &str,
|
||||
compatibility: McpElicitationCompatibility,
|
||||
) -> Option<ElicitationCapability> {
|
||||
// Keep capability advertising aligned with the client compatibility flags.
|
||||
// The sender has a matching defensive decline path for servers that send
|
||||
// elicitations despite this advertised capability.
|
||||
if !compatibility.allows_server_elicitation(server_name) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation#capabilities
|
||||
// indicates this should be an empty object.
|
||||
Some(ElicitationCapability::default())
|
||||
@@ -455,9 +466,10 @@ async fn start_server_task(
|
||||
tool_filter,
|
||||
tx_event,
|
||||
elicitation_requests,
|
||||
elicitation_compatibility,
|
||||
codex_apps_tools_cache_context,
|
||||
} = params;
|
||||
let elicitation = elicitation_capability_for_server(&server_name);
|
||||
let elicitation = elicitation_capability_for_server(&server_name, elicitation_compatibility);
|
||||
let params = InitializeRequestParams {
|
||||
meta: None,
|
||||
capabilities: ClientCapabilities {
|
||||
@@ -540,6 +552,7 @@ struct StartServerTaskParams {
|
||||
tool_filter: ToolFilter,
|
||||
tx_event: Sender<Event>,
|
||||
elicitation_requests: ElicitationRequestManager,
|
||||
elicitation_compatibility: McpElicitationCompatibility,
|
||||
codex_apps_tools_cache_context: Option<CodexAppsToolsCacheContext>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user