Skip to content

Commit 94f5cad

Browse files
authored
fix: when invoking Codex via MCP, use the request id as the Submission id (#1554)
Small quality-of-life improvement when using `codex mcp`.
1 parent 72504f1 commit 94f5cad

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

codex-rs/mcp-server/src/codex_tool_runner.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use codex_core::protocol::Event;
99
use codex_core::protocol::EventMsg;
1010
use codex_core::protocol::InputItem;
1111
use codex_core::protocol::Op;
12+
use codex_core::protocol::Submission;
1213
use codex_core::protocol::TaskCompleteEvent;
1314
use mcp_types::CallToolResult;
1415
use mcp_types::CallToolResultContent;
@@ -66,14 +67,24 @@ pub async fn run_codex_tool_session(
6667
.send(codex_event_to_notification(&first_event))
6768
.await;
6869

69-
if let Err(e) = codex
70-
.submit(Op::UserInput {
70+
// Use the original MCP request ID as the `sub_id` for the Codex submission so that
71+
// any events emitted for this tool-call can be correlated with the
72+
// originating `tools/call` request.
73+
let sub_id = match &id {
74+
RequestId::String(s) => s.clone(),
75+
RequestId::Integer(n) => n.to_string(),
76+
};
77+
78+
let submission = Submission {
79+
id: sub_id,
80+
op: Op::UserInput {
7181
items: vec![InputItem::Text {
7282
text: initial_prompt.clone(),
7383
}],
74-
})
75-
.await
76-
{
84+
},
85+
};
86+
87+
if let Err(e) = codex.submit_with_id(submission).await {
7788
tracing::error!("Failed to submit initial prompt: {e}");
7889
}
7990

0 commit comments

Comments
 (0)