{"record":{"id":"41bb17c6521a2ec0","repo":"OpenBB-finance/OpenBB","slug":"duplicate-prompt-names-found-set-duplicates","errorCode":null,"errorMessage":"Duplicate prompt names found: {set(duplicates)}","messagePattern":"Duplicate prompt names found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/mcp_server/openbb_mcp_server/models/mcp_config.py","lineNumber":223,"sourceCode":"        \"\"\"Validate overall configuration consistency.\"\"\"\n        # If expose is False, other configurations don't matter much, but we still validate them\n        if self.expose is False:\n            # Could add warnings here if other fields are set when expose=False\n            pass\n\n        # Validate prompt names are unique within this config\n        if self.prompts:\n            prompt_names = []\n            for prompt in self.prompts:\n                if prompt.name:\n                    prompt_names.append(prompt.name)\n\n            # Check for duplicate names\n            if len(prompt_names) != len(set(prompt_names)):\n                duplicates = [\n                    name for name in prompt_names if prompt_names.count(name) > 1\n                ]\n                raise ValueError(f\"Duplicate prompt names found: {set(duplicates)}\")\n\n        return self\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"Convert to dictionary format compatible with existing code.\"\"\"\n        return self.model_dump(exclude_none=True)\n\n\ndef validate_mcp_config(\n    config_dict: dict[str, Any], *, strict: bool = True\n) -> MCPConfigModel:\n    \"\"\"\n    Validate an MCP configuration dictionary.\n\n    Args:\n        config_dict: The configuration dictionary to validate\n        strict: If True, raise validation errors. If False, log warnings and return best-effort model.\n","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/mcp_server/openbb_mcp_server/models/mcp_config.py#L205-L241","documentation":"Raised by the model_validator on MCPConfigModel when two or more prompts inside one mcp_config block share the same 'name'. Prompt names must be unique within a config because they become the MCP prompt identifiers clients call by name.","triggerScenarios":"Defining prompts: [{name: \"summary\", ...}, {name: \"summary\", ...}] in a single route's openapi_extra mcp_config, or merging prompt lists from multiple files where the same name appears twice. Only prompts with a non-empty name are counted.","commonSituations":"Copy-pasting a prompt definition and forgetting to rename it, composing configs from shared libraries/templates that each define a 'default' prompt, refactors that centralize prompts but keep duplicates in the merged result.","solutions":["Rename one of the duplicate prompts so every name in the prompts list is unique","If the duplicates are identical, keep only one entry","When merging prompt configs programmatically, de-duplicate by name before validation and log which one won"],"exampleFix":"# before\n\"mcp_config\": {\"prompts\": [{\"name\": \"summary\", ...}, {\"name\": \"summary\", ...}]}\n\n# after\n\"mcp_config\": {\"prompts\": [{\"name\": \"summary\", ...}, {\"name\": \"detailed_summary\", ...}]}","handlingStrategy":"validation","validationCode":"names = [p[\"name\"] for p in cfg.get(\"prompts\", []) if p.get(\"name\")]\ndups = {n for n in names if names.count(n) > 1}\nif dups:\n    raise ValueError(f\"duplicate prompt names: {dups}\")\n# or auto-deduplicate keeping the first occurrence:\nseen = set()\ncfg[\"prompts\"] = [\n    p for p in cfg.get(\"prompts\", [])\n    if (p.get(\"name\") in seen) is False and not seen.add(p.get(\"name\"))\n]","typeGuard":"def prompt_names_unique(cfg: dict) -> bool:\n    names = [p[\"name\"] for p in cfg.get(\"prompts\", []) if p.get(\"name\")]\n    return len(names) == len(set(names))","tryCatchPattern":"try:\n    model = validate_mcp_config(cfg)\nexcept ValidationError as e:\n    if \"Duplicate prompt names\" in str(e):\n        seen, unique = set(), []\n        for p in cfg[\"prompts\"]:\n            if p.get(\"name\") not in seen:\n                seen.add(p.get(\"name\"))\n                unique.append(p)\n        cfg[\"prompts\"] = unique\n        model = validate_mcp_config(cfg)\n    else:\n        raise","preventionTips":["De-duplicate by name whenever merging prompt lists from files/templates","Name prompts after their purpose to make collisions obvious in review","Add a unit test asserting uniqueness over your shipped prompt configs"],"tags":["pydantic","validation","mcp","prompts","duplicates"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}