[MCP] Add configuration options to enable or disable specific tools (#5367)

Some MCP servers expose a lot of tools. In those cases, it is reasonable
to allow/denylist tools for Codex to use so it doesn't get overwhelmed
with too many tools.

The new configuration options available in the `mcp_server` toml table
are:
* `enabled_tools`
* `disabled_tools`

Fixes #4796
This commit is contained in:
Gabriel Peal
2025-10-20 15:35:36 -07:00
committed by GitHub
parent c37469b5ba
commit 740b4a95f4
8 changed files with 361 additions and 81 deletions

View File

@@ -1056,18 +1056,21 @@ pub(crate) fn new_mcp_tools_output(
.collect();
names.sort();
let status = auth_statuses
let auth_status = auth_statuses
.get(server.as_str())
.copied()
.unwrap_or(McpAuthStatus::Unsupported);
lines.push(vec![" Server: ".into(), server.clone().into()].into());
let status_line = if cfg.enabled {
vec![" • Status: ".into(), "enabled".green()].into()
} else {
vec![" • Status: ".into(), "disabled".red()].into()
};
lines.push(status_line);
lines.push(vec![" • Auth: ".into(), status.to_string().into()].into());
let mut header: Vec<Span<'static>> = vec!["".into(), server.clone().into()];
if !cfg.enabled {
header.push(" ".into());
header.push("(disabled)".red());
lines.push(header.into());
lines.push(Line::from(""));
continue;
}
lines.push(header.into());
lines.push(vec![" • Status: ".into(), "enabled".green()].into());
lines.push(vec![" • Auth: ".into(), auth_status.to_string().into()].into());
match &cfg.transport {
McpServerTransportConfig::Stdio {
@@ -1128,15 +1131,6 @@ pub(crate) fn new_mcp_tools_output(
}
}
if !cfg.enabled {
let disabled = "(disabled)".red();
lines.push(vec![" • Tools: ".into(), disabled.clone()].into());
lines.push(vec![" • Resources: ".into(), disabled.clone()].into());
lines.push(vec![" • Resource templates: ".into(), disabled].into());
lines.push(Line::from(""));
continue;
}
if names.is_empty() {
lines.push(" • Tools: (none)".into());
} else {