add token-based tool deferral behind feature flag (#18097)

add new `tool_search_always_defer_mcp_tools` feature flag that always
defers all mcp tools rather than deferring once > 100 deferrable tools.

add new tests, also move `mcp_exposure` tests into dedicated file rather
than polluting `codex_tests`.
This commit is contained in:
sayan-oai authored and GitHub committed 2026-04-17 18:34:06 +08:00
1 parent 20b4b80426
commit d0047de7cb
6 files changed
+332 -177

No files matched your search

+12 -1
View File
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::collections::HashSet;
use codex_features::Feature;
use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_mcp::ToolInfo as McpToolInfo;
use codex_mcp::filter_non_codex_apps_mcp_tools_only;
@@ -32,7 +33,13 @@ pub(crate) fn build_mcp_tool_exposure(
));
}
if !tools_config.search_tool || deferred_tools.len() < DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD {
let should_defer = tools_config.search_tool
&& (config
.features
.enabled(Feature::ToolSearchAlwaysDeferMcpTools)
|| deferred_tools.len() >= DIRECT_MCP_TOOL_EXPOSURE_THRESHOLD);
if !should_defer {
return McpToolExposure {
direct_tools: deferred_tools,
deferred_tools: None,
@@ -75,3 +82,7 @@ fn filter_codex_apps_mcp_tools(
.map(|(name, tool)| (name.clone(), tool.clone()))
.collect()
}
#[cfg(test)]
#[path = "mcp_tool_exposure_test.rs"]
mod tests;