Allow omitting MCP tool prefixes per server (#34991)

## What changed

- Accept a table form of `features.non_prefixed_mcp_tool_names` with an
  optional `server_names` list while preserving the existing boolean form.
- Omit the legacy `mcp__` namespace prefix only for tools from selected MCP
  servers. When no server list is provided, the enabled feature continues to
  omit the prefix for every server.
- Cover configuration resolution, tool normalization, and an MCP stdio
  round trip with selected servers.

GitOrigin-RevId: bdfb7ac54226de5051f06610e2c6b78b23912ef0
This commit is contained in:
sayan-oai authored and copyberry committed 2026-07-23 18:54:55 +00:00
1 parent 0d4910331d
commit 74e9d7efc4
15 files changed
+437 -15

No files matched your search

+74
View File
@@ -443,6 +443,65 @@ async fn load_config_resolves_experimental_request_user_input_enabled() -> std::
Ok(())
}
#[tokio::test]
async fn load_config_resolves_non_prefixed_mcp_tool_servers() -> std::io::Result<()> {
let cases = [
(
"[features]\nnon_prefixed_mcp_tool_names = false\n",
None,
true,
),
(
"[features]\nnon_prefixed_mcp_tool_names = true\n",
None,
false,
),
(
"[features.non_prefixed_mcp_tool_names]\nenabled = true\n",
None,
false,
),
(
"[features.non_prefixed_mcp_tool_names]\nenabled = true\nserver_names = [\"history\", \"notes\"]\n",
Some(vec!["history".to_string(), "notes".to_string()]),
true,
),
(
"[features.non_prefixed_mcp_tool_names]\nenabled = true\nserver_names = []\n",
Some(Vec::new()),
true,
),
(
"[features.non_prefixed_mcp_tool_names]\nenabled = false\nserver_names = [\"history\"]\n",
None,
true,
),
];
for (config_contents, expected_servers, expected_prefix) in cases {
let codex_home = tempdir()?;
let config_toml = toml::from_str::<ConfigToml>(config_contents)
.expect("TOML deserialization should succeed");
let config = Config::load_from_base_config_with_overrides(
config_toml,
ConfigOverrides::default(),
codex_home.abs(),
)
.await?;
assert_eq!(config.non_prefixed_mcp_tool_servers, expected_servers);
assert_eq!(config.prefix_mcp_tool_names(), expected_prefix);
let plugins_manager = PluginsManager::new(codex_home.path().to_path_buf());
let mcp_config = config.to_mcp_config(&plugins_manager).await;
assert_eq!(mcp_config.prefix_mcp_tool_names, expected_prefix);
assert_eq!(
mcp_config.non_prefixed_mcp_tool_servers,
expected_servers.unwrap_or_default()
);
}
Ok(())
}
#[tokio::test]
async fn load_config_resolves_code_mode_config() -> std::io::Result<()> {
let codex_home = tempdir()?;
@@ -6225,10 +6284,25 @@ async fn to_mcp_config_flows_mcp_tool_prefix_from_feature() -> std::io::Result<(
let mcp_config = config.to_mcp_config(&plugins_manager).await;
assert!(mcp_config.prefix_mcp_tool_names);
assert!(mcp_config.non_prefixed_mcp_tool_servers.is_empty());
let _ = config.features.enable(Feature::NonPrefixedMcpToolNames);
let mcp_config = config.to_mcp_config(&plugins_manager).await;
assert!(!mcp_config.prefix_mcp_tool_names);
assert!(mcp_config.non_prefixed_mcp_tool_servers.is_empty());
config.non_prefixed_mcp_tool_servers = Some(vec!["history".to_string(), "notes".to_string()]);
let mcp_config = config.to_mcp_config(&plugins_manager).await;
assert!(mcp_config.prefix_mcp_tool_names);
assert_eq!(
mcp_config.non_prefixed_mcp_tool_servers,
vec!["history".to_string(), "notes".to_string()]
);
let _ = config.features.disable(Feature::NonPrefixedMcpToolNames);
let mcp_config = config.to_mcp_config(&plugins_manager).await;
assert!(mcp_config.prefix_mcp_tool_names);
assert!(mcp_config.non_prefixed_mcp_tool_servers.is_empty());
Ok(())
}
+26
View File
@@ -829,6 +829,9 @@ pub struct Config {
/// Definition for MCP servers that Codex can reach out to for tool calls.
pub mcp_servers: Constrained<HashMap<String, McpServerConfig>>,
/// When present, only these MCP servers omit the legacy `mcp__` namespace prefix.
pub non_prefixed_mcp_tool_servers: Option<Vec<String>>,
/// Preferred store for MCP OAuth credentials.
/// keyring: Use an OS-specific keyring service.
/// Credentials stored in the keyring will only be readable by Codex unless the user explicitly grants access via OS-level keyring access.
@@ -1641,6 +1644,16 @@ impl Config {
use_legacy_landlock: self.features.use_legacy_landlock(),
apps_enabled: self.features.enabled(Feature::Apps),
prefix_mcp_tool_names: self.prefix_mcp_tool_names(),
non_prefixed_mcp_tool_servers: if self
.features
.enabled(Feature::NonPrefixedMcpToolNames)
{
self.non_prefixed_mcp_tool_servers
.clone()
.unwrap_or_default()
} else {
Vec::new()
},
client_elicitation_capability: if self.features.enabled(Feature::AuthElicitation) {
ElicitationCapability {
form: Some(FormElicitationCapability::default()),
@@ -1661,6 +1674,7 @@ impl Config {
pub(crate) fn prefix_mcp_tool_names(&self) -> bool {
!self.features.enabled(Feature::NonPrefixedMcpToolNames)
|| self.non_prefixed_mcp_tool_servers.is_some()
}
pub async fn rebuild_preserving_session_layers(
@@ -3203,6 +3217,17 @@ impl Config {
feature_requirements,
&mut startup_warnings,
)?;
let non_prefixed_mcp_tool_servers = if features.enabled(Feature::NonPrefixedMcpToolNames) {
cfg.features
.as_ref()
.and_then(|features| features.non_prefixed_mcp_tool_names.as_ref())
.and_then(|feature| match feature {
FeatureToml::Enabled(_) => None,
FeatureToml::Config(config) => config.server_names.clone(),
})
} else {
None
};
let respect_system_proxy = features.enabled(Feature::RespectSystemProxy);
let enable_network_proxy = features.enabled(Feature::NetworkProxy);
let configured_windows_sandbox_mode = resolve_windows_sandbox_mode(&cfg);
@@ -3960,6 +3985,7 @@ impl Config {
env!("CARGO_PKG_VERSION"),
),
mcp_servers,
non_prefixed_mcp_tool_servers,
// The config.toml omits "_mode" because it's a config file. However, "_mode"
// is important in code to differentiate the mode from the store implementation.
mcp_oauth_credentials_store_mode: resolve_mcp_oauth_credentials_store_mode(