Preserve longer MCP source descriptions in tool search (#37066)

## Why

The 4 KiB aggregate limit can truncate source metadata before it reaches the
model through the tool search description.

## What changed

Raise the aggregate source-description limit to 512 KiB while retaining the
existing character-boundary-safe truncation and bounded output.

## Testing

Expand unit and RMCP round-trip coverage to verify that substantially longer
Unicode descriptions remain complete within the new limit.

GitOrigin-RevId: 002760cdd2e8741e531b45f75f8624ef84334d24
This commit is contained in:
jif
2026-08-05 09:39:05 +00:00
committed by copyberry
parent 757c151a0e
commit fcc4ca552f
2 changed files with 6 additions and 4 deletions
@@ -5,7 +5,7 @@ use codex_tools::ToolSpec;
use codex_utils_string::take_bytes_at_char_boundary;
use std::collections::BTreeMap;
const MAX_TOOL_SEARCH_SOURCE_DESCRIPTION_BYTES: usize = 4 * 1024;
const MAX_TOOL_SEARCH_SOURCE_DESCRIPTION_BYTES: usize = 512 * 1024;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum ToolSearchSourceListing {
@@ -176,10 +176,11 @@ mod tests {
#[test]
fn create_tool_search_tool_bounds_aggregate_source_descriptions() {
let long_description = "🦀".repeat(20_000);
let sources = (0..8)
.map(|index| ToolSearchSourceInfo {
name: format!("source-{index:02}"),
description: Some("🦀".repeat(300)),
description: Some(long_description.clone()),
})
.collect::<Vec<_>>();
let ToolSpec::ToolSearch { description, .. } = create_tool_search_tool(
@@ -198,6 +199,7 @@ mod tests {
.expect("tool search should retain its discovery instructions");
assert!(source_descriptions.len() <= MAX_TOOL_SEARCH_SOURCE_DESCRIPTION_BYTES);
assert!(source_descriptions.starts_with("- source-00: 🦀"));
assert!(source_descriptions.contains(&long_description));
let advertised_names = source_descriptions
.lines()
.map(|line| {
+2 -2
View File
@@ -620,7 +620,7 @@ async fn stdio_server_round_trip() -> anyhow::Result<()> {
.await;
let expected_env_value = "propagated-env";
let expected_description = format!("{}🦀keep the complete MCP metadata", "é".repeat(499));
let expected_description = format!("{}🦀keep the complete MCP metadata", "é".repeat(11_000));
let instructions = expected_description.clone();
let rmcp_test_server_bin = remote_aware_stdio_server_bin()?;
@@ -713,7 +713,7 @@ async fn stdio_server_round_trip() -> anyhow::Result<()> {
.and_then(|tool| tool.get("description").and_then(Value::as_str))
.expect("the model should receive a tool search description");
assert!(
search_description.len() < 5 * 1024,
search_description.len() < 513 * 1024,
"the complete tool search description must remain bounded"
);
assert!(search_description.contains(&format!("- rmcp: {expected_description}")));