Make MCP and Code Mode input schema budgets configurable (#47936)

## Why

Fixed schema budgets can strip parameter descriptions from large MCP tools or render their Code Mode input types as `unknown`. Allow larger budgets to preserve that guidance.

## What changed

- Add `mcp_servers.<name>.tool_input_schema_max_bytes` to configure the UTF-8 byte threshold for best-effort input schema compaction, retaining the 5,000-byte default.
- Add `features.code_mode.tool_input_schema_max_bytes` for rendered input types. Use the largest of the 16,000-byte default, the Code Mode setting, and the ordinary MCP server's explicit setting.
- Apply rendering budgets to prompt declarations and the runtime tool catalog, and avoid reusing cached declarations after the Code Mode budget changes.

## Testing

Add coverage for UTF-8 compaction thresholds, budget precedence, configuration round trips, and preservation of parameter guidance in both the Code Mode prompt and `ALL_TOOLS`.

GitOrigin-RevId: 0ef2823a614d4794e636f518b09c0b03a5239b45
This commit is contained in:
Vivian Fang
2026-09-24 20:39:37 +00:00
committed by copyberry
parent b62fcd3c4b
commit 339e981ba7
63 changed files with 670 additions and 86 deletions
@@ -48,18 +48,24 @@ impl CodeModeExecuteHandler {
session,
turn: Arc::clone(&step_context.turn),
};
let code_mode_input_schema_max_bytes = step_context
.turn
.config
.code_mode
.tool_input_schema_max_bytes;
let mut enabled_tools = Vec::with_capacity(self.nested_tool_specs.len());
for (spec, cached_runtime) in &self.nested_tool_specs {
if let Some(cached_definitions) = cached_runtime
.as_ref()
.and_then(|runtime| runtime.cached_code_mode_definitions())
{
if let Some(cached_definitions) = cached_runtime.as_ref().and_then(|runtime| {
runtime.cached_code_mode_definitions(code_mode_input_schema_max_bytes)
}) {
enabled_tools.extend_from_slice(cached_definitions);
continue;
}
let definitions =
codex_tools::collect_code_mode_tool_definitions(std::iter::once(spec.as_ref()));
let definitions = codex_tools::collect_code_mode_tool_definitions(
std::iter::once(spec.as_ref()),
code_mode_input_schema_max_bytes,
);
enabled_tools.extend(definitions.into_iter().map(|mut definition| {
definition.input_schema = None;
definition.output_schema = None;
@@ -59,6 +59,7 @@ mod tests {
description: "Update the plan".to_string(),
kind: codex_code_mode::CodeModeToolKind::Function,
input_schema: None,
input_schema_max_bytes: None,
output_schema: None,
}];