{"record":{"id":"7ec550c4898b811a","repo":"rohitg00/ai-engineering-from-scratch","slug":"tools-list-failed","errorCode":null,"errorMessage":"tools/list failed","messagePattern":"tools/list failed","errorType":"exception","errorClass":"ContractViolation","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/28-mcp-tool-contracts-and-content/code/main.py","lineNumber":699,"sourceCode":"        self.server = server\n        self.principal = principal\n        self.max_list_pages = max_list_pages\n        self.rejections: list[dict[str, str]] = []\n        self.cursor_trace: list[str | None] = []\n        self.tools: dict[str, dict[str, Any]] = {}\n\n    def discover_tools(self) -> dict[str, dict[str, Any]]:\n        cursor: str | None = None\n        request_id = 1\n        seen_cursors: set[str] = set()\n        for _ in range(self.max_list_pages):\n            params: dict[str, Any] = {}\n            if cursor is not None:\n                params[\"cursor\"] = cursor\n            self.cursor_trace.append(cursor)\n            response = self.server.dispatch(make_request(request_id, \"tools/list\", params))\n            if response is None or \"error\" in response:\n                raise ContractViolation(\"tools/list failed\")\n            result = response[\"result\"]\n            for tool in result[\"tools\"]:\n                try:\n                    validate_tool_descriptor(tool)\n                except ContractViolation as exc:\n                    self.rejections.append({\"tool\": tool.get(\"name\", \"<unknown>\"), \"reason\": str(exc)})\n                    continue\n                self.tools[tool[\"name\"]] = tool\n            next_cursor = result.get(\"nextCursor\")\n            if next_cursor is None:\n                return self.tools\n            if not isinstance(next_cursor, str):\n                raise ContractViolation(\"tools/list nextCursor must be a string or null\")\n            if next_cursor in seen_cursors:\n                raise ContractViolation(\"tools/list returned a repeated or cyclic nextCursor\")\n            seen_cursors.add(next_cursor)\n            cursor = next_cursor\n            request_id += 1","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/28-mcp-tool-contracts-and-content/code/main.py#L681-L717","documentation":"Error \"tools/list failed\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/13-tools-and-protocols/28-mcp-tool-contracts-and-content/code/main.py:699 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}