Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codex-rs/exec/src/event_processor_with_jsonl_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ impl EventProcessorWithJsonOutput {
arguments,
result: result.map(|result| McpToolCallItemResult {
content: result.content,
meta: result.meta,
structured_content: result.structured_content,
}),
error: error.map(|error| McpToolCallItemError {
Expand Down
51 changes: 51 additions & 0 deletions codex-rs/exec/src/event_processor_with_jsonl_output_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;
use pretty_assertions::assert_eq;
use serde_json::json;
use tempfile::tempdir;

#[test]
Expand Down Expand Up @@ -57,3 +58,53 @@ fn failed_turn_does_not_overwrite_output_last_message_file() {
"keep existing contents"
);
}

#[test]
fn mcp_tool_call_result_preserves_meta_in_jsonl_event() {
let mut processor = EventProcessorWithJsonOutput::new(/*last_message_path*/ None);

let collected = processor.collect_thread_events(ServerNotification::ItemCompleted(
codex_app_server_protocol::ItemCompletedNotification {
item: ThreadItem::McpToolCall {
id: "mcp-1".to_string(),
server: "search service".to_string(),
tool: "web_run".to_string(),
status: McpToolCallStatus::Completed,
arguments: json!({"search_query": [{"q": "OpenAI Codex CLI documentation"}]}),
mcp_app_resource_uri: None,
result: Some(Box::new(codex_app_server_protocol::McpToolCallResult {
content: vec![json!({"type": "text", "text": "search result"})],
structured_content: None,
meta: Some(json!({"raw_messages": [{"ref_id": "turn0search0"}]})),
})),
error: None,
duration_ms: Some(42),
},
thread_id: "thread-1".to_string(),
turn_id: "turn-1".to_string(),
completed_at_ms: 0,
},
));

assert_eq!(collected.status, CodexStatus::Running);
assert_eq!(collected.events.len(), 1);

let ThreadEvent::ItemCompleted(ItemCompletedEvent { item }) = &collected.events[0] else {
panic!("expected item.completed event");
};
let ThreadItemDetails::McpToolCall(item) = &item.details else {
panic!("expected MCP tool call item");
};
let result = item.result.as_ref().expect("expected MCP tool result");
assert_eq!(
result.meta,
Some(json!({"raw_messages": [{"ref_id": "turn0search0"}]}))
);

let serialized = serde_json::to_value(&collected.events[0]).expect("serialize event");
assert_eq!(
serialized["item"]["result"]["_meta"],
json!({"raw_messages": [{"ref_id": "turn0search0"}]})
);
assert!(serialized["item"]["result"].get("meta").is_none());
}
3 changes: 3 additions & 0 deletions codex-rs/exec/src/exec_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ pub struct McpToolCallItemResult {
// representations). Using `JsonValue` keeps the payload wire-shaped and
// easy to export.
pub content: Vec<JsonValue>,
#[serde(rename = "_meta", skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub meta: Option<JsonValue>,
Comment on lines +269 to +271

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update existing result literals for the new field

Adding meta as a normal public field means every existing McpToolCallItemResult { ... } struct literal must provide it; the integration tests in codex-rs/exec/tests/event_processor_with_json_output.rs still construct expected results with only content and structured_content, so cargo test -p codex-exec will fail to compile those tests with a missing meta field. Please update those literals (for example with meta: None) or otherwise make the field non-breaking for existing constructors.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field is optional in the serialized/TS shape, but Rust struct literals still need to specify Option fields. I updated the
(1) in tests: expected McpToolCallItemResult literals with meta: None
(2) The Rust production path was already covered:
exec_events.rs (line 269) defines meta as optional and serializes it as _meta.
event_processor_with_jsonl_output.rs (line 224) already copies result.meta

pub structured_content: Option<JsonValue>,
}

Expand Down
2 changes: 2 additions & 0 deletions codex-rs/exec/tests/event_processor_with_json_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ fn mcp_tool_call_begin_and_end_emit_item_events() {
arguments: json!({ "key": "value" }),
result: Some(McpToolCallItemResult {
content: Vec::new(),
meta: None,
structured_content: None,
}),
error: None,
Expand Down Expand Up @@ -681,6 +682,7 @@ fn mcp_tool_call_defaults_arguments_and_preserves_structured_content() {
"type": "text",
"text": "done",
})],
meta: None,
structured_content: Some(json!({ "status": "ok" })),
}),
error: None,
Expand Down
1 change: 1 addition & 0 deletions sdk/typescript/src/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type McpToolCallItem = {
/** Result payload returned by the MCP server for successful calls. */
result?: {
content: McpContentBlock[];
_meta?: unknown;
structured_content: unknown;
};
/** Error message reported for failed calls. */
Expand Down
Loading