[exec] Add MCP tool arguments and results (#5899)

Extends mcp_tool_call item to include arguments and results.
This commit is contained in:
pakrym-oai
2025-10-29 14:23:57 -07:00
committed by GitHub
parent 13e1d0362d
commit 815ae4164a
7 changed files with 784 additions and 39 deletions

View File

@@ -14,6 +14,8 @@ use crate::exec_events::ItemCompletedEvent;
use crate::exec_events::ItemStartedEvent;
use crate::exec_events::ItemUpdatedEvent;
use crate::exec_events::McpToolCallItem;
use crate::exec_events::McpToolCallItemError;
use crate::exec_events::McpToolCallItemResult;
use crate::exec_events::McpToolCallStatus;
use crate::exec_events::PatchApplyStatus;
use crate::exec_events::PatchChangeKind;
@@ -48,6 +50,7 @@ use codex_core::protocol::TaskStartedEvent;
use codex_core::protocol::WebSearchEndEvent;
use codex_protocol::plan_tool::StepStatus;
use codex_protocol::plan_tool::UpdatePlanArgs;
use serde_json::Value as JsonValue;
use tracing::error;
use tracing::warn;
@@ -81,6 +84,7 @@ struct RunningMcpToolCall {
server: String,
tool: String,
item_id: String,
arguments: JsonValue,
}
impl EventProcessorWithJsonOutput {
@@ -220,6 +224,7 @@ impl EventProcessorWithJsonOutput {
let item_id = self.get_next_item_id();
let server = ev.invocation.server.clone();
let tool = ev.invocation.tool.clone();
let arguments = ev.invocation.arguments.clone().unwrap_or(JsonValue::Null);
self.running_mcp_tool_calls.insert(
ev.call_id.clone(),
@@ -227,6 +232,7 @@ impl EventProcessorWithJsonOutput {
server: server.clone(),
tool: tool.clone(),
item_id: item_id.clone(),
arguments: arguments.clone(),
},
);
@@ -235,6 +241,9 @@ impl EventProcessorWithJsonOutput {
details: ThreadItemDetails::McpToolCall(McpToolCallItem {
server,
tool,
arguments,
result: None,
error: None,
status: McpToolCallStatus::InProgress,
}),
};
@@ -249,19 +258,42 @@ impl EventProcessorWithJsonOutput {
McpToolCallStatus::Failed
};
let (server, tool, item_id) = match self.running_mcp_tool_calls.remove(&ev.call_id) {
Some(running) => (running.server, running.tool, running.item_id),
None => {
warn!(
call_id = ev.call_id,
"Received McpToolCallEnd without begin; synthesizing new item"
);
(
ev.invocation.server.clone(),
ev.invocation.tool.clone(),
self.get_next_item_id(),
)
let (server, tool, item_id, arguments) =
match self.running_mcp_tool_calls.remove(&ev.call_id) {
Some(running) => (
running.server,
running.tool,
running.item_id,
running.arguments,
),
None => {
warn!(
call_id = ev.call_id,
"Received McpToolCallEnd without begin; synthesizing new item"
);
(
ev.invocation.server.clone(),
ev.invocation.tool.clone(),
self.get_next_item_id(),
ev.invocation.arguments.clone().unwrap_or(JsonValue::Null),
)
}
};
let (result, error) = match &ev.result {
Ok(value) => {
let result = McpToolCallItemResult {
content: value.content.clone(),
structured_content: value.structured_content.clone(),
};
(Some(result), None)
}
Err(message) => (
None,
Some(McpToolCallItemError {
message: message.clone(),
}),
),
};
let item = ThreadItem {
@@ -269,6 +301,9 @@ impl EventProcessorWithJsonOutput {
details: ThreadItemDetails::McpToolCall(McpToolCallItem {
server,
tool,
arguments,
result,
error,
status,
}),
};