Keep effective tool exposure in the registry (#36367)

## Why

`ToolExecutor::exposure()` describes a tool's preferred exposure, while the host
may apply step-specific policy when building a tool plan.

## What changed

- Store each runtime together with its effective exposure in `ToolRegistry`.
- Apply MCP, namespace, and collaboration-tool exposure overrides directly to
  registry entries instead of wrapping runtimes.
- Use the registry-owned exposure when building model-visible specs, deferred
  tool search, code-mode executors, and parallel-call support.

## Testing

- Cover that a hidden MCP tool remains routable but is not eligible for parallel
  tool calls.

GitOrigin-RevId: 1bc2760add8d993f477954269fa13681bfcc2444
This commit is contained in:
jif authored and copyberry committed 2026-07-31 17:24:33 +00:00
1 parent 287e1020ae
commit 775fb21d2a
11 files changed
+235 -269

No files matched your search

+10 -12
View File
@@ -13,16 +13,16 @@ use tracing::warn;
use crate::config::Config;
use crate::connectors;
use crate::tools::handlers::McpHandler;
use crate::tools::registry::CoreToolRuntime;
use crate::tools::registry::override_tool_exposure;
use crate::tools::registry::ToolRegistry;
#[instrument(level = "trace", skip_all)]
pub(crate) fn build_mcp_tool_runtimes<'a>(
all_mcp_tools: &'a [McpToolInfo],
connectors: Option<&'a [connectors::AppInfo]>,
config: &'a Config,
pub(crate) fn append_mcp_tools(
all_mcp_tools: &[McpToolInfo],
connectors: Option<&[connectors::AppInfo]>,
config: &Config,
search_tool_enabled: bool,
) -> impl Iterator<Item = Arc<dyn CoreToolRuntime>> + 'a {
registry: &mut ToolRegistry,
) {
// Keep regular MCP tools first; Apps tools also require connector and policy checks.
let non_app_tools = filter_non_codex_apps_mcp_tools_only(all_mcp_tools);
let app_tools = connectors
@@ -33,19 +33,17 @@ pub(crate) fn build_mcp_tool_runtimes<'a>(
} else {
ToolExposure::Direct
};
non_app_tools.chain(app_tools).filter_map(move |tool| {
for tool in non_app_tools.chain(app_tools) {
let tool_name = tool.canonical_tool_name();
match McpHandler::new(tool.clone()) {
Ok(handler) => {
let handler: Arc<dyn CoreToolRuntime> = Arc::new(handler);
Some(override_tool_exposure(handler, exposure))
registry.register_external_with_exposure(Arc::new(handler), exposure);
}
Err(err) => {
warn!("Skipping MCP tool `{tool_name}`: failed to build tool spec: {err}");
None
}
}
})
}
}
fn filter_non_codex_apps_mcp_tools_only(