mirror of
https://github.com/openai/codex.git
synced 2026-11-05 08:28:29 +00:00
Include originating item IDs in MCP request metadata (#40866)
## What changed - Add the originating Responses item ID to MCP tool request metadata as `_meta.itemId`. - Preserve the initiating `exec` item ID across code-mode cells so nested MCP calls carry the same origin. ## Testing - Cover metadata generation for direct and code-mode MCP tool calls. GitOrigin-RevId: 1161cac64f1cc3a6d4dac4368e63804bd9d2c417
This commit is contained in:
1 parent
74772623db
commit
f5420174da
9 files changed
+175
-49
No files matched your search
@@ -1209,14 +1209,11 @@ async fn code_mode_only_guides_all_tools_search_and_calls_deferred_app_tools() -
|
||||
|
||||
let server = responses::start_mock_server().await;
|
||||
let apps_server = AppsTestServer::mount_searchable(&server).await?;
|
||||
let resp_mock = responses::mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_custom_tool_call(
|
||||
"call-1",
|
||||
"exec",
|
||||
r#"
|
||||
let originating_item_id = "ctc_code_mode_origin";
|
||||
let mut exec_call = ev_custom_tool_call(
|
||||
"call-1",
|
||||
"exec",
|
||||
r#"
|
||||
const tool = ALL_TOOLS.find(
|
||||
({ name }) => name === "mcp__codex_apps__calendar_timezone_option_99"
|
||||
);
|
||||
@@ -1231,7 +1228,13 @@ if (!tool) {
|
||||
}));
|
||||
}
|
||||
"#,
|
||||
),
|
||||
);
|
||||
exec_call["item"]["id"] = serde_json::json!(originating_item_id);
|
||||
let resp_mock = responses::mount_sse_once(
|
||||
&server,
|
||||
sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
exec_call,
|
||||
ev_completed("resp-1"),
|
||||
]),
|
||||
)
|
||||
@@ -1325,6 +1328,13 @@ if (!tool) {
|
||||
"text": "called calendar_timezone_option_99 for at with ",
|
||||
})
|
||||
);
|
||||
let apps_tool_calls = recorded_apps_tool_calls(&server).await;
|
||||
assert!(
|
||||
apps_tool_calls.iter().any(|call| {
|
||||
call.pointer("/params/_meta/itemId") == Some(&serde_json::json!(originating_item_id))
|
||||
}),
|
||||
"the nested MCP call should inherit its code cell's originating Responses item"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -170,6 +170,7 @@ async fn approved_mcp_tool_call_metadata_records_prior_user_input_request(
|
||||
let server = start_mock_server().await;
|
||||
let apps_server = AppsTestServer::mount(&server).await?;
|
||||
let call_id = "calendar-call-approval";
|
||||
let originating_item_id = "fc_calendar_approval_origin";
|
||||
let calendar_args = serde_json::to_string(&json!({
|
||||
"title": "Lunch",
|
||||
"starts_at": "2026-03-10T12:00:00Z"
|
||||
@@ -196,14 +197,16 @@ async fn approved_mcp_tool_call_metadata_records_prior_user_input_request(
|
||||
ev_completed("resp-permissions"),
|
||||
]));
|
||||
}
|
||||
let mut calendar_call = ev_function_call_with_namespace(
|
||||
call_id,
|
||||
SEARCH_CALENDAR_NAMESPACE,
|
||||
SEARCH_CALENDAR_CREATE_TOOL,
|
||||
&calendar_args,
|
||||
);
|
||||
calendar_call["item"]["id"] = json!(originating_item_id);
|
||||
response_sequence.push(sse(vec![
|
||||
ev_response_created("resp-1"),
|
||||
ev_function_call_with_namespace(
|
||||
call_id,
|
||||
SEARCH_CALENDAR_NAMESPACE,
|
||||
SEARCH_CALENDAR_CREATE_TOOL,
|
||||
&calendar_args,
|
||||
),
|
||||
calendar_call,
|
||||
ev_completed("resp-1"),
|
||||
]));
|
||||
if strict_auto_review {
|
||||
@@ -351,6 +354,10 @@ async fn approved_mcp_tool_call_metadata_records_prior_user_input_request(
|
||||
apps_tool_call.pointer("/params/_meta/callId"),
|
||||
Some(&json!(call_id))
|
||||
);
|
||||
assert_eq!(
|
||||
apps_tool_call.pointer("/params/_meta/itemId"),
|
||||
Some(&json!(originating_item_id))
|
||||
);
|
||||
assert_eq!(
|
||||
apps_tool_call
|
||||
.pointer("/params/_meta/x-codex-turn-metadata/user_input_requested_during_turn"),
|
||||
|
||||
Reference in new issue
Block a user