Hmbown/CodeWhale · error · anyhow::Error

MCP server ' ' already exists in . Use `codewhale mcp…

Error message

MCP server '{name}' already exists in {}. Use `codewhale mcp remove {name}` first, or choose a different --name.

What it means

`codewhale mcp add` refuses to overwrite an existing server entry: `mutate_config` checks `cfg.servers.contains_key(&name)` and bails with a message naming the config file and the remove command. Server names are unique keys in the MCP config map.

Solutions

  1. Run `codewhale mcp remove <name>` then re-run the add command.
  2. Pick a different name with `--name <other-name>`.
  3. Edit the config file directly to replace the entry if you want new settings under the same name.

Example fix

// before (shell)
codewhale mcp add --name fs --command /path/to/mcp-fs
// after
codewhale mcp remove fs
codewhale mcp add --name fs --command /path/to/mcp-fs
Defensive patterns

Strategy: validation

Validate before calling

codewhale mcp list | grep -qx "$name" && codewhale mcp remove "$name"
codewhale mcp add --name "$name" --command "$cmd"

Try / catch

// shell
if ! codewhale mcp add --name "$name" ...; then
  codewhale mcp remove "$name" && codewhale mcp add --name "$name" ...
fi

Prevention

When it happens

Trigger: Calling `codewhale mcp add --name <name> ...` when `cfg.servers` already contains `<name>` at the resolved config path.

Common situations: Re-running an add command after a partial setup, re-adding a server after it was renamed not removed, or setup scripts that run idempotently but don't check existence first.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/958303716f12b919. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/lib.rs:10279

            }
            bail!("one or more MCP servers failed validation");
        }
        McpCommand::AddSelf { name, workspace } => {
            let exe_path = std::env::current_exe()
                .map_err(|e| anyhow!("Cannot resolve current binary path: {e}"))?;
            let exe_str = exe_path.to_string_lossy().to_string();

            let mut args = Vec::with_capacity(if workspace.is_some() { 4 } else { 2 });
            if let Some(ref ws) = workspace {
                args.push("--workspace".to_string());
                args.push(ws.clone());
            }
            args.push("serve".to_string());
            args.push("--mcp".to_string());

            crate::mcp::mutate_config(&config_path, None, |cfg| {
                if cfg.servers.contains_key(&name) {
                    bail!(
                        "MCP server '{name}' already exists in {}. Use `codewhale mcp remove {name}` first, or choose a different --name.",
                        config_path.display()
                    );
                }
                cfg.servers.insert(
                    name.clone(),
                    McpServerConfig {
                        command: Some(exe_str.clone()),
                        args,
                        env: std::collections::HashMap::new(),
                        cwd: None,
                        url: None,
                        transport: None,
                        connect_timeout: None,
                        execute_timeout: None,
                        read_timeout: None,
                        disabled: false,
                        enabled: true,

View on GitHub (pinned to 73e0f67d83)