{"record":{"id":"949edce09805123c","repo":"rohitg00/ai-engineering-from-scratch","slug":"duplicate-tool-schema-name","errorCode":null,"errorMessage":"duplicate tool: {schema.name}","messagePattern":"duplicate tool: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/13-mcp-server-with-registry/code/main.py","lineNumber":97,"sourceCode":"\n@dataclass\nclass MCPServer:\n    name: str\n    title: str\n    description: str\n    version: str\n    url: str\n    trusted_issuer: str\n    tools: dict[str, ToolSchema] = field(default_factory=dict)\n    handlers: dict[str, Handler] = field(default_factory=dict)\n\n    @property\n    def server_info(self) -> dict:\n        return {\"name\": self.name, \"version\": self.version}\n\n    def register(self, schema: ToolSchema, handler: Handler) -> None:\n        if schema.name in self.tools:\n            raise ValueError(f\"duplicate tool: {schema.name}\")\n        self.tools[schema.name] = schema\n        self.handlers[schema.name] = handler\n\n    def result(self, **fields: object) -> dict:\n        return {\n            \"resultType\": \"complete\",\n            **fields,\n            \"_meta\": {\"io.modelcontextprotocol/serverInfo\": self.server_info},\n        }\n\n    def discover(self, meta: dict) -> dict:\n        invalid = validate_meta(meta)\n        if invalid:\n            return invalid\n        return self.result(\n            supportedVersions=[PROTOCOL_VERSION],\n            capabilities={\"tools\": {\"listChanged\": False}},\n            ttlMs=3_600_000,","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/13-mcp-server-with-registry/code/main.py#L79-L115","documentation":"Uniqueness guard in MCPServer.register: a tool with the same name is already in the server's tools map, and registration is not idempotent by design so handlers cannot be silently swapped. The second register call is rejected before the handler is stored.","triggerScenarios":"Thrown at phases/19-capstone-projects/13-mcp-server-with-registry/code/main.py:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Choose a distinct tool name for the new registration","Unregister or rebuild the server instead of re-registering the same name","Namespace tools by domain (e.g. repo.search vs web.search) to avoid collisions","Assert on registered tool sets in tests to catch accidental double registration"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}