Add model and reasoning effort to MCP turn metadata (#21219)

## Why
- Similar change as https://github.com/openai/codex/pull/19473.
- Without change: MCP tool calls receive
`_meta["x-codex-turn-metadata"]` with `session_id`, `turn_id`, and
`turn_started_at_unix_ms`.
- Issue: MCP servers may want the model and reasoning effort to better
understand tool-call behavior and latency relative to turn start.

## What Changed
- With change: MCP turn metadata now includes `model` and
`reasoning_effort`, propagated in `_meta["x-codex-turn-metadata"]`.
- Normal `/responses` turn metadata headers are unchanged.

## Verification
- `codex-rs/core/src/mcp_tool_call_tests.rs`
- `codex-rs/core/src/turn_metadata_tests.rs`
- `codex-rs/core/tests/suite/search_tool.rs`
This commit is contained in:
mchen-oai
2026-05-05 17:37:48 -07:00
committed by GitHub
Unverified
parent 2c1a361a2e
commit 794c240f25
6 changed files with 168 additions and 34 deletions
+9 -8
View File
@@ -119,20 +119,21 @@ impl TurnContext {
)
}
pub(crate) fn effective_reasoning_effort_for_tracing(&self) -> String {
pub(crate) fn effective_reasoning_effort(&self) -> Option<ReasoningEffortConfig> {
if self.model_info.supports_reasoning_summaries {
match self
.reasoning_effort
self.reasoning_effort
.or(self.model_info.default_reasoning_level)
{
Some(effort) => effort.to_string(),
None => "default".to_string(),
}
} else {
"default".to_string()
None
}
}
pub(crate) fn effective_reasoning_effort_for_tracing(&self) -> String {
self.effective_reasoning_effort()
.map(|effort| effort.to_string())
.unwrap_or_else(|| "default".to_string())
}
pub(crate) fn model_context_window(&self) -> Option<i64> {
let effective_context_window_percent = self.model_info.effective_context_window_percent;
self.model_info