Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix: when invoking Codex via MCP, use the request id as the Submission id (#1554)

Michael Bolin94f5cad895df
diff --git a/codex-rs/mcp-server/src/codex_tool_runner.rs b/codex-rs/mcp-server/src/codex_tool_runner.rs
index 796a119e5c..7c3b02fe5e 100644
--- a/codex-rs/mcp-server/src/codex_tool_runner.rs
+++ b/codex-rs/mcp-server/src/codex_tool_runner.rs
@@ -9,6 +9,7 @@ use codex_core::protocol::Event;
use codex_core::protocol::EventMsg;
use codex_core::protocol::InputItem;
use codex_core::protocol::Op;
+use codex_core::protocol::Submission;
use codex_core::protocol::TaskCompleteEvent;
use mcp_types::CallToolResult;
use mcp_types::CallToolResultContent;
@@ -66,14 +67,24 @@ pub async fn run_codex_tool_session(
.send(codex_event_to_notification(&first_event))
.await;
- if let Err(e) = codex
- .submit(Op::UserInput {
+ // Use the original MCP request ID as the `sub_id` for the Codex submission so that
+ // any events emitted for this tool-call can be correlated with the
+ // originating `tools/call` request.
+ let sub_id = match &id {
+ RequestId::String(s) => s.clone(),
+ RequestId::Integer(n) => n.to_string(),
+ };
+
+ let submission = Submission {
+ id: sub_id,
+ op: Op::UserInput {
items: vec![InputItem::Text {
text: initial_prompt.clone(),
}],
- })
- .await
- {
+ },
+ };
+
+ if let Err(e) = codex.submit_with_id(submission).await {
tracing::error!("Failed to submit initial prompt: {e}");
}