Support per-tool MCP output limits (#41421)

## What changed

- Add a positive `output_token_limit` setting to each entry under an MCP server's `tools` configuration.
- Apply the most restrictive limit when plugin and user policies overlap, while keeping approval policy independent.
- Carry the effective MCP output budget in conversation history so tool output, post-tool hook responses, and resumed sessions use the same truncation limit.

## Testing

- Cover configuration parsing, serialization, schema validation, and plugin policy merging.
- Cover MCP output below and above the configured limit, post-tool hook responses, and session resume.

GitOrigin-RevId: d0beb4fca9ba6055d9e1d31c137373b465d50d61
This commit is contained in:
pakrym-oai authored and copyberry committed 2026-08-28 21:40:23 +00:00
1 parent 03147407e3
commit f742dabc6f
38 files changed
+487 -224

No files matched your search

+8 -1
View File
@@ -37,6 +37,7 @@ use codex_tools::agent_plugin_mcp_tool_to_responses_api_tool;
use codex_tools::mcp_tool_to_responses_api_tool;
use codex_utils_image::PromptImageMode;
use codex_utils_image::load_data_url_for_prompt_uncached;
use codex_utils_output_truncation::TruncationPolicy;
use codex_utils_string::take_bytes_at_char_boundary;
use futures::future::BoxFuture;
use serde_json::Map;
@@ -217,6 +218,12 @@ impl McpHandler {
}
};
// Capture presentation policy from the same config snapshot used for execution.
let truncation_policy = prepared_mcp_call
.as_ref()
.and_then(codex_mcp::PreparedMcpCall::output_token_limit)
.map(TruncationPolicy::Tokens)
.unwrap_or(turn.model_info().truncation_policy.into());
let started = Instant::now();
let result = handle_mcp_tool_call(
Arc::clone(&session),
@@ -237,7 +244,7 @@ impl McpHandler {
tool_input: result.tool_input,
wall_time: started.elapsed(),
original_image_detail_supported: can_request_original_image_detail(turn.model_info()),
truncation_policy: turn.model_info().truncation_policy.into(),
truncation_policy,
}))
}
}