mirror of
https://github.com/openai/codex.git
synced 2026-11-24 15:21:20 +00:00
Support MCP form input in full-access user threads (#37864)
## Why Standard MCP forms can require user-entered values even when tool permissions are otherwise auto-approved in full-access sessions. ## What changed - Recognize the `openai/standard-form-input` client extension and surface non-approval forms in full-access, user-initiated root threads. - Keep approval forms, automation and subagent threads, headless sessions, and clients without the capability on their existing decline or review paths. - Treat the capability as client-only so it is not advertised to MCP servers, and enable it after session startup so required servers cannot block startup waiting for form input. ## Testing Add unit and app-server coverage for accepted form round trips, declined cases, approval metadata safeguards, resumed threads, and extension filtering. GitOrigin-RevId: 053bfe397a5c79eceef90a81d13e2aca6353af43
This commit is contained in:
1 parent
ee7815dad2
commit
4b0e2a0bff
14 files changed
+895
-71
No files matched your search
@@ -21,6 +21,8 @@ use async_channel::Sender;
|
||||
use codex_protocol::approvals::ElicitationRequest;
|
||||
use codex_protocol::approvals::ElicitationRequestEvent;
|
||||
use codex_protocol::mcp::RequestId as ProtocolRequestId;
|
||||
use codex_protocol::mcp_approval_meta::APPROVAL_KIND_KEY;
|
||||
use codex_protocol::mcp_approval_meta::APPROVAL_KIND_TOOL_SUGGESTION;
|
||||
use codex_protocol::mcp_approval_meta::APPROVALS_REVIEWER_KEY;
|
||||
use codex_protocol::mcp_approval_meta::STRICT_AUTO_REVIEW_KEY;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
@@ -94,6 +96,7 @@ struct ActiveElicitation {
|
||||
pub(crate) struct ElicitationRequestRouter {
|
||||
requests: Arc<StdMutex<ResponderMap>>,
|
||||
auto_deny: Arc<AtomicBool>,
|
||||
full_access_form_input_enabled: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
struct PendingElicitationRequest {
|
||||
@@ -122,6 +125,15 @@ impl ElicitationRequestRouter {
|
||||
self.auto_deny.store(auto_deny, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn full_access_form_input_enabled(&self) -> bool {
|
||||
self.full_access_form_input_enabled.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
pub(crate) fn enable_full_access_form_input(&self) {
|
||||
self.full_access_form_input_enabled
|
||||
.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
pub(crate) async fn resolve(
|
||||
&self,
|
||||
server_name: String,
|
||||
@@ -213,6 +225,19 @@ impl ElicitationRequestManager {
|
||||
});
|
||||
}
|
||||
|
||||
if elicitation
|
||||
.meta()
|
||||
.and_then(|meta| meta.get(APPROVAL_KIND_KEY))
|
||||
.and_then(serde_json::Value::as_str)
|
||||
== Some(APPROVAL_KIND_TOOL_SUGGESTION)
|
||||
{
|
||||
return Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Decline,
|
||||
content: None,
|
||||
meta: None,
|
||||
});
|
||||
}
|
||||
|
||||
let Ok(authority) = authority.lock().map(|authority| authority.clone()) else {
|
||||
return Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Decline,
|
||||
@@ -273,12 +298,12 @@ impl ElicitationRequestManager {
|
||||
Some(_) => return Ok(strict_auto_review_decline()),
|
||||
}
|
||||
|
||||
if mcp_permission_prompt_is_auto_approved(
|
||||
let permission_prompt_is_auto_approved = mcp_permission_prompt_is_auto_approved(
|
||||
approval_policy,
|
||||
&permission_profile,
|
||||
McpPermissionPromptAutoApproveContext::default(),
|
||||
) && can_auto_accept_elicitation(&elicitation)
|
||||
{
|
||||
);
|
||||
if permission_prompt_is_auto_approved && can_auto_accept_elicitation(&elicitation) {
|
||||
return Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Accept,
|
||||
content: Some(serde_json::json!({})),
|
||||
@@ -286,22 +311,40 @@ impl ElicitationRequestManager {
|
||||
});
|
||||
}
|
||||
|
||||
if elicitation_is_rejected_by_policy(approval_policy) {
|
||||
return Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Decline,
|
||||
content: None,
|
||||
meta: None,
|
||||
});
|
||||
}
|
||||
let should_surface_form_in_full_access = router.full_access_form_input_enabled()
|
||||
&& permission_prompt_is_auto_approved
|
||||
&& matches!(
|
||||
&elicitation,
|
||||
Elicitation::Mcp(
|
||||
rmcp::model::ElicitRequestParams::FormElicitationParams {
|
||||
meta,
|
||||
requested_schema,
|
||||
..
|
||||
}
|
||||
) if !requested_schema.properties.is_empty()
|
||||
&& !meta
|
||||
.as_ref()
|
||||
.is_some_and(|meta| meta.contains_key(APPROVAL_KIND_KEY))
|
||||
);
|
||||
|
||||
if let Some(reviewer) = reviewer {
|
||||
let request = ElicitationReviewRequest {
|
||||
server_name: server_name.clone(),
|
||||
request_id: id.clone(),
|
||||
elicitation: elicitation.clone(),
|
||||
};
|
||||
if let Some(response) = reviewer.review(request).await? {
|
||||
return Ok(response);
|
||||
if !should_surface_form_in_full_access {
|
||||
if elicitation_is_rejected_by_policy(approval_policy) {
|
||||
return Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Decline,
|
||||
content: None,
|
||||
meta: None,
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(reviewer) = reviewer {
|
||||
let request = ElicitationReviewRequest {
|
||||
server_name: server_name.clone(),
|
||||
request_id: id.clone(),
|
||||
elicitation: elicitation.clone(),
|
||||
};
|
||||
if let Some(response) = reviewer.review(request).await? {
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user