{"record":{"id":"79c3fefc5bf77958","repo":"Hmbown/CodeWhale","slug":"mcp-server-collides-with-already-registered-s","errorCode":null,"errorMessage":"MCP server '{}' collides with already-registered server '{existing}': both qualify tools as 'mcp__{}__*'","messagePattern":"MCP server '(.+?)' collides with already-registered server '(.+?)': both qualify tools as 'mcp__(.+?)__\\*'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/mcp/src/lib.rs","lineNumber":262,"sourceCode":"}\n\nimpl McpManager {\n    /// Register an MCP server with its config, tool filter, and client implementation.\n    ///\n    /// Fails when the server's name collides with an already-registered server\n    /// after `sanitize_component` folding. Qualified tool names are built\n    /// from the sanitized name, so `my-server`, `my_server`, and `My.Server`\n    /// all produce `mcp__my_server__*`: registering two of them would let\n    /// either server answer a qualified name meant for the other. Re-registering\n    /// the same name replaces it, which is how restart works.\n    pub fn register_server(\n        &mut self,\n        config: McpServerConfig,\n        filter: ToolFilter,\n        client: Box<dyn McpManagedClient>,\n    ) -> Result<()> {\n        if let Some(existing) = self.colliding_server_name(&config.name) {\n            bail!(\n                \"MCP server '{}' collides with already-registered server '{existing}': \\\n                 both qualify tools as 'mcp__{}__*'\",\n                config.name,\n                sanitize_component(&config.name)\n            );\n        }\n        self.clients.insert(config.name.clone(), client);\n        self.configs.insert(config.name.clone(), (config, filter));\n        Ok(())\n    }\n\n    /// Returns a registered server whose sanitized name matches `name`'s but\n    /// which is not `name` itself.\n    fn colliding_server_name(&self, name: &str) -> Option<&str> {\n        let sanitized = sanitize_component(name);\n        self.configs\n            .keys()\n            .find(|existing| existing.as_str() != name && sanitize_component(existing) == sanitized)","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/mcp/src/lib.rs#L244-L280","documentation":"Raised by `McpManager::register_server` (crates/mcp/src/lib.rs): the new server's name, after sanitizing to a tool-namespace component, is already claimed by a previously registered server, so both would qualify tools as `mcp__<sanitized>__*` and calls could hit the wrong server. Registration fails closed before any tool is exposed.","triggerScenarios":"Calling `register_server` with a `McpServerConfig` whose `name` differs from an existing one only in characters removed by `sanitize_component` (e.g. 'my-server' vs 'my.server' vs 'my server'), or literally re-registering a colliding name while intending a new server.","commonSituations":"Config files defining multiple MCP servers whose names normalize to the same prefix (dashes, dots, underscores, case); renaming a server without removing the old entry; merging two config sources with overlapping server names.","solutions":["Rename the new server so its sanitized form is unique (use only characters that survive sanitizing distinctly, e.g. letters/underscores).","Unregister the conflicting server first if it is no longer needed.","Audit all server names in your config for collisions after sanitizing before loading them.","If replacement is intended, use the replace path — re-registering the exact same name replaces it; only distinct-but-colliding names are rejected."],"exampleFix":"// before: both sanitize to 'github'\n{\"mcpServers\": {\"github\": {...}, \"github.com\": {...}}}\n// after\n{\"mcpServers\": {\"github\": {...}, \"github_enterprise\": {...}}}","handlingStrategy":"validation","validationCode":"// Rust: check sanitized-name uniqueness across configs before register\nlet sanitized = sanitize_component(&config.name);\nfor existing in manager.server_names() {\n    anyhow::ensure!(sanitize_component(existing) != sanitized,\n        \"sanitized collision: {} vs {}\", existing, config.name);\n}","typeGuard":"fn names_distinct(a: &str, b: &str) -> bool {\n    sanitize_component(a) != sanitize_component(b)\n}","tryCatchPattern":"match manager.register_server(config, filter, client) {\n    Err(e) if e.to_string().contains(\"collides with already-registered server\") => {\n        // rename and retry\n    }\n    other => other?,\n}","preventionTips":["Use only letters, digits, and underscores in MCP server names.","Lint all server names in merged configs for sanitized collisions at load time.","Unregister servers you intend to replace instead of adding variants."],"tags":["mcp","naming-collision","config"],"backgroundTag":"tool-namespace-collision","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"}