mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +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
@@ -6,11 +6,13 @@ use crate::session::turn_context::TurnContext;
|
||||
use crate::turn_diff_tracker::TurnDiffTracker;
|
||||
use crate::unified_exec::format_output_omission_marker;
|
||||
use crate::unified_exec::resolve_max_tokens;
|
||||
use codex_protocol::ResponseItemId;
|
||||
use codex_protocol::mcp::CallToolResult;
|
||||
use codex_protocol::models::FunctionCallOutputBody;
|
||||
use codex_protocol::models::FunctionCallOutputContentItem;
|
||||
use codex_protocol::models::FunctionCallOutputPayload;
|
||||
use codex_protocol::models::ResponseInputItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::models::function_call_output_content_items_to_text;
|
||||
use codex_tools::LoadableToolSpec;
|
||||
use codex_tools::ToolName;
|
||||
@@ -66,6 +68,34 @@ pub struct ToolInvocation {
|
||||
pub payload: ToolPayload,
|
||||
}
|
||||
|
||||
impl ToolInvocation {
|
||||
/// Returns the Responses item that requested this call or started its code-mode cell.
|
||||
pub(crate) async fn originating_item_id(&self) -> Option<ResponseItemId> {
|
||||
if let ToolCallSource::CodeMode { cell_id, .. } = &self.source {
|
||||
return self
|
||||
.session
|
||||
.services
|
||||
.code_mode_service
|
||||
.cell_originating_item_id(&codex_code_mode::CellId::new(cell_id.clone()));
|
||||
}
|
||||
|
||||
self.session
|
||||
.clone_history()
|
||||
.await
|
||||
.raw_items()
|
||||
.rev()
|
||||
.find_map(|item| match item {
|
||||
ResponseItem::FunctionCall { id, call_id, .. }
|
||||
| ResponseItem::CustomToolCall { id, call_id, .. }
|
||||
if call_id == &self.call_id =>
|
||||
{
|
||||
id.clone()
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct McpToolOutput {
|
||||
pub result: CallToolResult,
|
||||
|
||||
Reference in new issue
Block a user