Hmbown/CodeWhale · error · anyhow::Error

MCP server '{name}' 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

add-self registers the current binary as an MCP server; before inserting, it checks cfg.servers for the name and refuses to overwrite an existing entry, pointing at `codewhale mcp remove` first. It is an idempotency guard for bootstrap/install scripts.

Source

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

            for (name, err) in errors {
                eprintln!("  - {name}: {err:#}");
            }
            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!["serve".to_string(), "--mcp".to_string()];
            if let Some(ref ws) = workspace {
                args.push("--workspace".to_string());
                args.push(ws.clone());
            }

            let mut cfg = load_mcp_config(&config_path)?;
            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 0c42157ee5)

Solutions

  1. Remove first: `codewhale mcp remove <name>`
  2. Or pick a different --name for the second registration
  3. In scripts, treat this error as 'already installed' and continue

Example fix

# before
codewhale mcp add-self   # second run: MCP server 'codewhale' already exists in ...

# after
codewhale mcp remove codewhale 2>/dev/null || true
codewhale mcp add-self
Defensive patterns

Strategy: validation

Validate before calling

codewhale mcp list | grep -Fxq "$NAME" && { echo "'$NAME' already registered -- skipping"; exit 0; }
codewhale mcp add-self

Prevention

When it happens

Trigger: Running `codewhale mcp add-self` twice; re-running an install or setup script; choosing a --name already present in the same config file.

Common situations: Bootstrap scripts without existence checks; registering self per-workspace while reusing one name in a shared config.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/958303716f12b919. Report an issue: GitHub.