fix: when invoking Codex via MCP, use the request id as the Submission id (#1554)
Small quality-of-life improvement when using `codex mcp`.
This commit is contained in:
@@ -9,6 +9,7 @@ use codex_core::protocol::Event;
|
|||||||
use codex_core::protocol::EventMsg;
|
use codex_core::protocol::EventMsg;
|
||||||
use codex_core::protocol::InputItem;
|
use codex_core::protocol::InputItem;
|
||||||
use codex_core::protocol::Op;
|
use codex_core::protocol::Op;
|
||||||
|
use codex_core::protocol::Submission;
|
||||||
use codex_core::protocol::TaskCompleteEvent;
|
use codex_core::protocol::TaskCompleteEvent;
|
||||||
use mcp_types::CallToolResult;
|
use mcp_types::CallToolResult;
|
||||||
use mcp_types::CallToolResultContent;
|
use mcp_types::CallToolResultContent;
|
||||||
@@ -66,14 +67,24 @@ pub async fn run_codex_tool_session(
|
|||||||
.send(codex_event_to_notification(&first_event))
|
.send(codex_event_to_notification(&first_event))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Err(e) = codex
|
// Use the original MCP request ID as the `sub_id` for the Codex submission so that
|
||||||
.submit(Op::UserInput {
|
// 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 {
|
items: vec![InputItem::Text {
|
||||||
text: initial_prompt.clone(),
|
text: initial_prompt.clone(),
|
||||||
}],
|
}],
|
||||||
})
|
},
|
||||||
.await
|
};
|
||||||
{
|
|
||||||
|
if let Err(e) = codex.submit_with_id(submission).await {
|
||||||
tracing::error!("Failed to submit initial prompt: {e}");
|
tracing::error!("Failed to submit initial prompt: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user