{"record":{"id":"958303716f12b919","repo":"Hmbown/CodeWhale","slug":"mcp-server-name-already-exists-in-use-cod","errorCode":null,"errorMessage":"MCP server '{name}' already exists in {}. Use `codewhale mcp remove {name}` first, or choose a different --name.","messagePattern":"MCP server '(.+?)' already exists in (.+?)\\. Use `codewhale mcp remove (.+?)` first, or choose a different --name\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":8783,"sourceCode":"            for (name, err) in errors {\n                eprintln!(\"  - {name}: {err:#}\");\n            }\n            bail!(\"one or more MCP servers failed validation\");\n        }\n        McpCommand::AddSelf { name, workspace } => {\n            let exe_path = std::env::current_exe()\n                .map_err(|e| anyhow!(\"Cannot resolve current binary path: {e}\"))?;\n            let exe_str = exe_path.to_string_lossy().to_string();\n\n            let mut args = vec![\"serve\".to_string(), \"--mcp\".to_string()];\n            if let Some(ref ws) = workspace {\n                args.push(\"--workspace\".to_string());\n                args.push(ws.clone());\n            }\n\n            let mut cfg = load_mcp_config(&config_path)?;\n            if cfg.servers.contains_key(&name) {\n                bail!(\n                    \"MCP server '{name}' already exists in {}. Use `codewhale mcp remove {name}` first, or choose a different --name.\",\n                    config_path.display()\n                );\n            }\n            cfg.servers.insert(\n                name.clone(),\n                McpServerConfig {\n                    command: Some(exe_str.clone()),\n                    args,\n                    env: std::collections::HashMap::new(),\n                    cwd: None,\n                    url: None,\n                    transport: None,\n                    connect_timeout: None,\n                    execute_timeout: None,\n                    read_timeout: None,\n                    disabled: false,\n                    enabled: true,","sourceCodeStart":8765,"sourceCodeEnd":8801,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/lib.rs#L8765-L8801","documentation":"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.","triggerScenarios":"Running `codewhale mcp add-self` twice; re-running an install or setup script; choosing a --name already present in the same config file.","commonSituations":"Bootstrap scripts without existence checks; registering self per-workspace while reusing one name in a shared config.","solutions":["Remove first: `codewhale mcp remove <name>`","Or pick a different --name for the second registration","In scripts, treat this error as 'already installed' and continue"],"exampleFix":"# before\ncodewhale mcp add-self   # second run: MCP server 'codewhale' already exists in ...\n\n# after\ncodewhale mcp remove codewhale 2>/dev/null || true\ncodewhale mcp add-self","handlingStrategy":"validation","validationCode":"codewhale mcp list | grep -Fxq \"$NAME\" && { echo \"'$NAME' already registered -- skipping\"; exit 0; }\ncodewhale mcp add-self","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make install/bootstrap scripts idempotent: check for the entry before adding","Treat 'already exists' as success in re-runnable setup code"],"tags":["mcp","config","duplicate","idempotency"],"backgroundTag":"duplicate-resource","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}