mirror of
https://github.com/openai/codex.git
synced 2026-12-04 00:51:02 +00:00
Preserve metadata in native user verification requests (#46952)
## Why Native `openai/userVerification` requests need to carry optional `_meta` to clients for extension-specific presentation. ## What changed - Accept optional metadata objects with the same validation as MCP elicitation. - Restore metadata from the MCP request context, excluding `progressToken`, and forward it through `mcpServer/elicitation/request`. - Update protocol types, schemas, and documentation while retaining support for requests without metadata. Challenge bytes and acceptance proofs remain unchanged. ## Testing Add coverage for metadata validation, transport context restoration, and protocol round trips. Extend MCP integration tests to check that verification metadata reaches the client. GitOrigin-RevId: 5d04004244cf33effac675c19e543157c48d1504
This commit is contained in:
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -758,6 +758,9 @@ pub enum McpServerElicitationRequest {
|
||||
#[serde(rename = "openai/userVerification", rename_all = "camelCase")]
|
||||
#[ts(rename = "openai/userVerification", rename_all = "camelCase")]
|
||||
UserVerification {
|
||||
#[serde(rename = "_meta")]
|
||||
#[ts(rename = "_meta")]
|
||||
meta: Option<JsonValue>,
|
||||
title: String,
|
||||
description: String,
|
||||
challenge: String,
|
||||
@@ -808,10 +811,12 @@ impl TryFrom<CoreElicitationRequest> for McpServerElicitationRequest {
|
||||
fn try_from(value: CoreElicitationRequest) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
CoreElicitationRequest::UserVerification {
|
||||
meta,
|
||||
title,
|
||||
description,
|
||||
challenge,
|
||||
} => Ok(Self::UserVerification {
|
||||
meta,
|
||||
title,
|
||||
description,
|
||||
challenge,
|
||||
|
||||
@@ -2323,6 +2323,41 @@ fn mcp_server_elicitation_request_from_core_url_request() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mcp_server_user_verification_metadata_round_trips_from_core() {
|
||||
for meta in [
|
||||
None,
|
||||
Some(json!({"example/display": {"label": "Operation"}})),
|
||||
] {
|
||||
let mut wire = json!({
|
||||
"mode": "openai/userVerification",
|
||||
"title": "Approve",
|
||||
"description": "Review operation",
|
||||
"challenge": "AQID",
|
||||
});
|
||||
if let Some(meta) = &meta {
|
||||
wire["_meta"] = meta.clone();
|
||||
}
|
||||
let core: CoreElicitationRequest = serde_json::from_value(wire.clone()).unwrap();
|
||||
let request = McpServerElicitationRequest::try_from(core).unwrap();
|
||||
assert_eq!(
|
||||
request,
|
||||
McpServerElicitationRequest::UserVerification {
|
||||
meta: meta.clone(),
|
||||
title: "Approve".into(),
|
||||
description: "Review operation".into(),
|
||||
challenge: "AQID".into(),
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<McpServerElicitationRequest>(wire.clone()).unwrap(),
|
||||
request
|
||||
);
|
||||
wire["_meta"] = json!(meta);
|
||||
assert_eq!(serde_json::to_value(request).unwrap(), wire);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mcp_server_elicitation_request_from_core_form_request() {
|
||||
let request = McpServerElicitationRequest::try_from(CoreElicitationRequest::Form {
|
||||
|
||||
@@ -96,6 +96,12 @@ Before sending verification requests to desktop sessions, deploy a GUI that
|
||||
handles the typed verification request, cancellation, and late proofs. The general
|
||||
`experimentalApi` opt-in does not identify a compatible GUI version.
|
||||
|
||||
Native `openai/userVerification` elicitation requests preserve optional `_meta`
|
||||
JSON through MCP transport and `mcpServer/elicitation/request`. Clients may use
|
||||
this metadata for extension-specific presentation and must continue to accept
|
||||
requests without it. Metadata does not change the challenge bytes or the proof
|
||||
returned in the acceptance response.
|
||||
|
||||
Local UI clients use five methods. They require the existing
|
||||
`experimentalApi` opt-in. The local provider reports
|
||||
`unavailable/providerUnavailable` on unsupported platforms or without the required
|
||||
|
||||
@@ -78,6 +78,7 @@ async fn user_verification_initialize_owns_advertisement_and_eligibility() -> Re
|
||||
turn_id: None,
|
||||
server_name: "codex_apps".into(),
|
||||
request: rpc::McpServerElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
challenge: "AQ".into(),
|
||||
title: "Approve".into(),
|
||||
description: String::new(),
|
||||
|
||||
@@ -24,6 +24,7 @@ fn request() -> rpc::ServerRequestPayload {
|
||||
turn_id: None,
|
||||
server_name: "codex_apps".into(),
|
||||
request: rpc::McpServerElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve".into(),
|
||||
description: String::new(),
|
||||
challenge: "AQ".into(),
|
||||
|
||||
@@ -18,6 +18,7 @@ fn request(thread_id: ThreadId) -> ServerRequestPayload {
|
||||
turn_id: Some("turn-1".into()),
|
||||
server_name: "plugin-service".into(),
|
||||
request: McpServerElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve".into(),
|
||||
description: String::new(),
|
||||
challenge: "AQID".into(),
|
||||
|
||||
@@ -99,6 +99,7 @@ impl ServerHandler for VerificationServer {
|
||||
"title": "Approve purchase",
|
||||
"description": "Pay $200 to Example Store",
|
||||
"challenge": "AAECA_7_",
|
||||
"_meta": {"example/display": {"label": "Operation"}},
|
||||
})),
|
||||
)))
|
||||
.await
|
||||
@@ -182,6 +183,7 @@ async fn user_verification_mcp_round_trip_requires_proof_in_full_access() -> Res
|
||||
assert_eq!(
|
||||
request.request,
|
||||
ElicitationRequest::UserVerification {
|
||||
meta: Some(json!({"example/display": {"label": "Operation"}})),
|
||||
title: "Approve purchase".into(),
|
||||
description: "Pay $200 to Example Store".into(),
|
||||
challenge: "AAECA_7_".into(),
|
||||
|
||||
@@ -291,6 +291,7 @@ impl ElicitationRequestManager {
|
||||
.ok()
|
||||
.and_then(|authority| authority.clone());
|
||||
if let Elicitation::UserVerification {
|
||||
meta,
|
||||
title,
|
||||
description,
|
||||
challenge,
|
||||
@@ -309,6 +310,7 @@ impl ElicitationRequestManager {
|
||||
authority,
|
||||
server_name,
|
||||
ElicitationRequest::UserVerification {
|
||||
meta,
|
||||
title,
|
||||
description,
|
||||
challenge,
|
||||
|
||||
@@ -604,6 +604,7 @@ async fn user_verification_requires_the_app_even_when_policy_would_approve_or_de
|
||||
let pending = tokio::spawn(sender(
|
||||
RequestId::Number(7),
|
||||
Elicitation::UserVerification {
|
||||
meta: Some(json!({"example/display": {"label": "Operation"}})),
|
||||
title: "Approve purchase".into(),
|
||||
description: "Pay $200".into(),
|
||||
challenge: "AQID".into(),
|
||||
@@ -616,6 +617,7 @@ async fn user_verification_requires_the_app_even_when_policy_would_approve_or_de
|
||||
assert_eq!(
|
||||
request.request,
|
||||
ElicitationRequest::UserVerification {
|
||||
meta: Some(json!({"example/display": {"label": "Operation"}})),
|
||||
title: "Approve purchase".into(),
|
||||
description: "Pay $200".into(),
|
||||
challenge: "AQID".into(),
|
||||
@@ -665,6 +667,7 @@ async fn user_verification_cancels_when_no_app_can_receive_the_request() {
|
||||
sender(
|
||||
RequestId::Number(7),
|
||||
Elicitation::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve".into(),
|
||||
description: String::new(),
|
||||
challenge: "AQID".into(),
|
||||
@@ -694,6 +697,7 @@ async fn user_verification_cancels_for_an_event_receiver_without_host_activation
|
||||
sender(
|
||||
RequestId::Number(7),
|
||||
Elicitation::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve".into(),
|
||||
description: String::new(),
|
||||
challenge: "AQID".into(),
|
||||
@@ -734,6 +738,7 @@ async fn user_verification_drops_pending_response_when_the_request_is_cancelled(
|
||||
let pending = tokio::spawn(sender(
|
||||
RequestId::Number(7),
|
||||
Elicitation::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve".into(),
|
||||
description: String::new(),
|
||||
challenge: "AQID".into(),
|
||||
@@ -779,6 +784,7 @@ async fn user_verification_rejects_attached_servers_even_if_they_use_the_plugin_
|
||||
sender(
|
||||
RequestId::Number(7),
|
||||
Elicitation::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve".into(),
|
||||
description: String::new(),
|
||||
challenge: "AQID".into()
|
||||
|
||||
@@ -95,6 +95,7 @@ fn realtime_user_verification_notice_excludes_request_payload() {
|
||||
server_name: "private-server-name".to_string(),
|
||||
id: codex_protocol::mcp::RequestId::String("private-request-id".to_string()),
|
||||
request: codex_protocol::approvals::ElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "private-title".to_string(),
|
||||
description: "private-description".to_string(),
|
||||
challenge: "private-challenge".to_string(),
|
||||
|
||||
@@ -271,6 +271,7 @@ async fn hosted_apps_protocol_override_preserves_native_verification() -> anyhow
|
||||
assert_eq!(
|
||||
request.request,
|
||||
ElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "Verify action".into(),
|
||||
description: "Verify the requested operation".into(),
|
||||
challenge: "AQID".into(),
|
||||
|
||||
@@ -405,6 +405,9 @@ pub enum ElicitationRequest {
|
||||
#[serde(rename = "openai/userVerification")]
|
||||
#[ts(rename = "openai/userVerification")]
|
||||
UserVerification {
|
||||
#[serde(rename = "_meta", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional, rename = "_meta")]
|
||||
meta: Option<JsonValue>,
|
||||
title: String,
|
||||
description: String,
|
||||
challenge: String,
|
||||
|
||||
@@ -381,12 +381,13 @@ fn restore_context_meta(
|
||||
}
|
||||
|
||||
match &mut request {
|
||||
Elicitation::UserVerification { .. } => {}
|
||||
Elicitation::Mcp(request) => request
|
||||
.meta_mut()
|
||||
.get_or_insert_with(RequestMetaObject::new)
|
||||
.extend(context_meta),
|
||||
Elicitation::OpenAiForm { meta, .. } | Elicitation::OpenAiElicitationForm { meta, .. } => {
|
||||
Elicitation::OpenAiForm { meta, .. }
|
||||
| Elicitation::OpenAiElicitationForm { meta, .. }
|
||||
| Elicitation::UserVerification { meta, .. } => {
|
||||
let meta = meta
|
||||
.get_or_insert_with(|| Value::Object(Map::new()))
|
||||
.as_object_mut();
|
||||
|
||||
@@ -319,6 +319,7 @@ pub enum Elicitation {
|
||||
requested_schema: serde_json::Value,
|
||||
},
|
||||
UserVerification {
|
||||
meta: Option<serde_json::Value>,
|
||||
title: String,
|
||||
description: String,
|
||||
challenge: String,
|
||||
@@ -329,10 +330,11 @@ impl Elicitation {
|
||||
pub fn meta(&self) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||
match self {
|
||||
Self::Mcp(request) => request.meta().map(|meta| &meta.0.0),
|
||||
Self::OpenAiForm { meta, .. } | Self::OpenAiElicitationForm { meta, .. } => {
|
||||
Self::OpenAiForm { meta, .. }
|
||||
| Self::OpenAiElicitationForm { meta, .. }
|
||||
| Self::UserVerification { meta, .. } => {
|
||||
meta.as_ref().and_then(serde_json::Value::as_object)
|
||||
}
|
||||
Self::UserVerification { .. } => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ pub(crate) const MODE: &str = "openai/userVerification";
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct RequestParams {
|
||||
mode: String,
|
||||
#[serde(rename = "_meta")]
|
||||
meta: Option<serde_json::Map<String, serde_json::Value>>,
|
||||
title: String,
|
||||
description: String,
|
||||
challenge: String,
|
||||
@@ -42,6 +44,7 @@ pub(crate) fn parse_request(request: CustomRequest) -> Result<Elicitation, rmcp:
|
||||
return Err(invalid_request());
|
||||
}
|
||||
Ok(Elicitation::UserVerification {
|
||||
meta: params.meta.map(serde_json::Value::Object),
|
||||
title: params.title,
|
||||
description: params.description,
|
||||
challenge: params.challenge,
|
||||
|
||||
@@ -27,6 +27,51 @@ fn service() -> ElicitationClientService {
|
||||
)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_verification_dispatch_preserves_context_metadata() -> anyhow::Result<()> {
|
||||
let mut service = service();
|
||||
service.send_elicitation = Arc::new(Box::new(|_, request| {
|
||||
assert_eq!(
|
||||
request,
|
||||
Elicitation::UserVerification {
|
||||
meta: Some(json!({"example/display": {"label": "Operation"}})),
|
||||
title: "Approve".into(),
|
||||
description: "Review operation".into(),
|
||||
challenge: "AQID".into(),
|
||||
}
|
||||
);
|
||||
Box::pin(async {
|
||||
Ok(ElicitationResponse {
|
||||
action: ElicitationAction::Cancel,
|
||||
content: None,
|
||||
meta: None,
|
||||
})
|
||||
})
|
||||
}));
|
||||
let (client_transport, server_transport) = tokio::io::duplex(/*max_buf_size*/ 4096);
|
||||
let client = serve_directly(service, client_transport, /*peer_info*/ None);
|
||||
let mut server = IntoTransport::<RoleServer, _, _>::into_transport(server_transport);
|
||||
server
|
||||
.send(serde_json::from_value::<ServerJsonRpcMessage>(json!({
|
||||
"jsonrpc": "2.0", "id": 1, "method": OPENAI_ELICITATION_METHOD,
|
||||
"params": {
|
||||
"mode": crate::user_verification::MODE,
|
||||
"title": "Approve", "description": "Review operation", "challenge": "AQID",
|
||||
"_meta": {"progressToken": 7, "example/display": {"label": "Operation"}}
|
||||
}
|
||||
}))?)
|
||||
.await?;
|
||||
let response = timeout(Duration::from_secs(/*secs*/ 5), server.receive())
|
||||
.await?
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
serde_json::to_value(response)?,
|
||||
json!({"jsonrpc": "2.0", "id": 1, "result": {"action": "cancel"}})
|
||||
);
|
||||
client.cancel().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn user_verification_remembers_cancellation_before_request_handler_runs() -> anyhow::Result<()>
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ fn user_verification_request_preserves_signed_bytes_and_display_text() {
|
||||
))
|
||||
.unwrap(),
|
||||
Elicitation::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve purchase".to_string(),
|
||||
description: "Pay $200 to Example Store".to_string(),
|
||||
challenge: "AQID".to_string(),
|
||||
@@ -23,6 +24,54 @@ fn user_verification_request_preserves_signed_bytes_and_display_text() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_verification_request_metadata_matches_mcp_elicitation() {
|
||||
for meta in [
|
||||
None,
|
||||
Some(json!(null)),
|
||||
Some(json!({})),
|
||||
Some(json!({"example/display": {"label": "Operation", "details": [1, true, null]}})),
|
||||
Some(json!(true)),
|
||||
Some(json!(7)),
|
||||
Some(json!("scalar")),
|
||||
Some(json!([])),
|
||||
] {
|
||||
let mut params = json!({
|
||||
"mode": MODE,
|
||||
"title": "Approve",
|
||||
"description": "Review operation",
|
||||
"challenge": "AQID",
|
||||
});
|
||||
let mut mcp_params = json!({
|
||||
"mode": "form",
|
||||
"message": "Approve",
|
||||
"requestedSchema": {"type": "object", "properties": {}},
|
||||
});
|
||||
if let Some(meta) = &meta {
|
||||
params["_meta"] = meta.clone();
|
||||
mcp_params["_meta"] = meta.clone();
|
||||
}
|
||||
let mcp_request = serde_json::from_value::<rmcp::model::ElicitRequestParams>(mcp_params);
|
||||
let expected = if mcp_request.is_ok() {
|
||||
Ok(Elicitation::UserVerification {
|
||||
meta: meta.filter(serde_json::Value::is_object),
|
||||
title: "Approve".into(),
|
||||
description: "Review operation".into(),
|
||||
challenge: "AQID".into(),
|
||||
})
|
||||
} else {
|
||||
Err(invalid_request())
|
||||
};
|
||||
assert_eq!(
|
||||
parse_request(CustomRequest::new(
|
||||
"openai/elicitation/create",
|
||||
Some(params),
|
||||
)),
|
||||
expected,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_verification_rejects_invalid_or_unbounded_requests_without_echoing_values() {
|
||||
for (field, value) in [
|
||||
|
||||
@@ -13,7 +13,8 @@ fn native_request() -> Value {
|
||||
"method": "openai/elicitation/create",
|
||||
"params": {
|
||||
"mode": "openai/userVerification", "title": "Verify action",
|
||||
"description": "Verify the requested operation", "challenge": "AQID"
|
||||
"description": "Verify the requested operation", "challenge": "AQID",
|
||||
"_meta": {"example/display": {"label": "Operation"}}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -206,6 +207,7 @@ async fn native_mrtr_returns_validated_proof_or_cancellation_in_content() -> any
|
||||
assert_eq!(
|
||||
request,
|
||||
Elicitation::UserVerification {
|
||||
meta: Some(json!({"example/display": {"label": "Operation"}})),
|
||||
title: "Verify action".into(),
|
||||
description: "Verify the requested operation".into(),
|
||||
challenge: "AQID".into(),
|
||||
|
||||
@@ -928,6 +928,7 @@ mod tests {
|
||||
&& let ServerRequest::McpServerElicitationRequest { params, .. } = &mut request
|
||||
{
|
||||
params.request = McpServerElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "Verify".to_string(),
|
||||
description: "Approve deployment".to_string(),
|
||||
challenge: "AQID".to_string(),
|
||||
|
||||
@@ -9,6 +9,7 @@ fn user_verification_server_request(thread_id: ThreadId, request_id: i64) -> Ser
|
||||
turn_id: Some("turn-verification".to_string()),
|
||||
server_name: "deployments".to_string(),
|
||||
request: McpServerElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve deployment?".to_string(),
|
||||
description: "Verify the production deployment.".to_string(),
|
||||
challenge: "AQID".to_string(),
|
||||
|
||||
@@ -44,6 +44,7 @@ impl UserVerificationRequests {
|
||||
title,
|
||||
description,
|
||||
challenge,
|
||||
..
|
||||
} = ¶ms.request
|
||||
{
|
||||
self.pending.insert(
|
||||
|
||||
@@ -19,6 +19,7 @@ fn verification_request() -> ServerRequest {
|
||||
turn_id: None,
|
||||
server_name: "deployments".to_string(),
|
||||
request: McpServerElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve deployment?".to_string(),
|
||||
description: "Deploy the reviewed change.".to_string(),
|
||||
challenge: "AQID".to_string(),
|
||||
|
||||
@@ -16,6 +16,7 @@ fn verification_request() -> ServerRequest {
|
||||
turn_id: None,
|
||||
server_name: "deployments".to_string(),
|
||||
request: McpServerElicitationRequest::UserVerification {
|
||||
meta: None,
|
||||
title: "Approve deployment?".to_string(),
|
||||
description: "Deploy the reviewed change.".to_string(),
|
||||
challenge: "AQID".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user