Add per-surface MCP tool exposure controls (#36781)

## Why

MCP tools can be exposed directly, discovered through tool search, or called
from Code Mode. Servers need to be able to opt out of any of these surfaces
without disabling their tools everywhere.

## What changed

- Add `omit_tools_from` to MCP server configuration, accepting any combination
  of `direct`, `deferred`, and `code_mode`.
- Apply the exclusions independently when building direct, deferred, and Code
  Mode tool surfaces while keeping omitted tools registered for permitted uses.
- Remove client-private `_meta` fields from MCP results returned to Code Mode.
- Include the new setting in the configuration schema and MCP config
  serialization.

## Testing

- Cover every exposure combination across Code Mode, Code-Mode-only sessions,
  tool search, direct-only namespaces, and prefixed and unprefixed MCP names.
- Verify direct and nested execution paths, parallel-call support, config
  round-tripping, and `_meta` filtering.

GitOrigin-RevId: 12dfcb78bb5c5ecf4d70f38a8b5022792463a27f
This commit is contained in:
tongzhou wang authored and copyberry committed 2026-08-03 18:51:46 +00:00
1 parent 136f75e7b7
commit 51c9ed6d4f
41 files changed
+981 -20

No files matched your search

+7 -2
View File
@@ -7,6 +7,7 @@ use codex_mcp::CODEX_APPS_MCP_SERVER_NAME;
use codex_mcp::ToolInfo as McpToolInfo;
use codex_mcp::tool_is_model_visible;
use codex_tools::ToolExposure;
use codex_tools::ToolName;
use tracing::instrument;
use tracing::warn;
@@ -22,7 +23,7 @@ pub(crate) fn append_mcp_tools(
config: &Config,
search_tool_enabled: bool,
registry: &mut ToolRegistry,
) {
) -> HashSet<ToolName> {
// 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,17 +34,21 @@ pub(crate) fn append_mcp_tools(
} else {
ToolExposure::Direct
};
let mut registered_tools = HashSet::new();
for tool in non_app_tools.chain(app_tools) {
let tool_name = tool.canonical_tool_name();
match McpHandler::new(tool.clone()) {
Ok(handler) => {
registry.register_external_with_exposure(Arc::new(handler), exposure);
if registry.register_external_with_exposure(Arc::new(handler), exposure) {
registered_tools.insert(tool_name);
}
}
Err(err) => {
warn!("Skipping MCP tool `{tool_name}`: failed to build tool spec: {err}");
}
}
}
registered_tools
}
fn filter_non_codex_apps_mcp_tools_only(