{"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":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":10279,"sourceCode":"            }\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::with_capacity(if workspace.is_some() { 4 } else { 2 });\n            if let Some(ref ws) = workspace {\n                args.push(\"--workspace\".to_string());\n                args.push(ws.clone());\n            }\n            args.push(\"serve\".to_string());\n            args.push(\"--mcp\".to_string());\n\n            crate::mcp::mutate_config(&config_path, None, |cfg| {\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":10261,"sourceCodeEnd":10297,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L10261-L10297","documentation":"`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.","triggerScenarios":"Calling `codewhale mcp add --name <name> ...` when `cfg.servers` already contains `<name>` at the resolved config path.","commonSituations":"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.","solutions":["Run `codewhale mcp remove <name>` then re-run the add command.","Pick a different name with `--name <other-name>`.","Edit the config file directly to replace the entry if you want new settings under the same name."],"exampleFix":"// before (shell)\ncodewhale mcp add --name fs --command /path/to/mcp-fs\n// after\ncodewhale mcp remove fs\ncodewhale mcp add --name fs --command /path/to/mcp-fs","handlingStrategy":"validation","validationCode":"codewhale mcp list | grep -qx \"$name\" && codewhale mcp remove \"$name\"\ncodewhale mcp add --name \"$name\" --command \"$cmd\"\n","typeGuard":null,"tryCatchPattern":"// shell\nif ! codewhale mcp add --name \"$name\" ...; then\n  codewhale mcp remove \"$name\" && codewhale mcp add --name \"$name\" ...\nfi\n","preventionTips":["Make idempotent setup scripts do remove-then-add or check `mcp list` first.","Adopt a naming convention per environment to avoid collisions.","Inspect the config path in the error message before re-adding."],"tags":["mcp","config","cli","duplicate"],"backgroundTag":"file-already-exists","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}