Support package-style MCP server names (#41700)

## What changed

- Allow MCP server names to contain `:`, `@`, `/`, and `.`, enabling names such as `npm:@modelcontextprotocol/server-sequential.thinking`.
- Preserve these names across `mcp add`, `get`, `list`, and `remove`, runtime tool namespaces, and OAuth credential lookup.
- Quote non-bare server names in generated `config.toml` recovery hints and keep similarly escaped OAuth credential names isolated.

## Testing

- Add CLI and runtime round-trip coverage for npm-style names.
- Add snapshot coverage for quoted recovery hints and a regression test for OAuth credential-name collisions.

GitOrigin-RevId: 97e9353cdbc544db4eb2377ddbfa1d2d539b1e04
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-30 16:45:34 +00:00
1 parent 88f776588f
commit 94cbbddafc
12 files changed
+159 -13

No files matched your search

+4 -3
View File
@@ -474,6 +474,7 @@ async fn run_add(config_overrides: &CliConfigOverrides, add_args: AddArgs) -> Re
let mut servers = load_global_mcp_servers(&codex_home)
.await
.with_context(|| format!("failed to load MCP servers from {}", codex_home.display()))?;
let credential_name = new_entry.oauth_credential_name(&name);
servers.insert(name.clone(), new_entry);
ConfigEditsBuilder::new(&codex_home)
@@ -495,7 +496,7 @@ async fn run_add(config_overrides: &CliConfigOverrides, add_args: AddArgs) -> Re
oauth_config.discovered_scopes.clone(),
);
perform_oauth_login_retry_without_scopes(
&name,
credential_name.as_ref(),
&oauth_config.url,
config.mcp_oauth_credentials_store_mode,
config.auth_keyring_backend_kind(),
@@ -1123,12 +1124,12 @@ fn validate_server_name(name: &str) -> Result<()> {
let is_valid = !name.is_empty()
&& name
.chars()
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_');
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_' | ':' | '@' | '/' | '.'));
if is_valid {
Ok(())
} else {
bail!("invalid server name '{name}' (use letters, numbers, '-', '_')");
bail!("invalid server name '{name}' (use letters, numbers, '-', '_', ':', '@', '/', '.')");
}
}