{"record":{"id":"659210ebf1b06e54","repo":"rohitg00/ai-engineering-from-scratch","slug":"method-not-found-method","errorCode":null,"errorMessage":"Method not found: {method}","messagePattern":"Method not found: (.+?)","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py","lineNumber":304,"sourceCode":"            ]\n            return self._complete(\n                prompts=prompts, ttlMs=300_000, cacheScope=\"public\"\n            ), []\n        if method == \"prompts/get\":\n            name = params[\"name\"]\n            if not isinstance(name, str):\n                raise ValueError(\"name must be a string\")\n            if name not in self.prompts:\n                raise ValueError(\"unknown prompt\")\n            return self._complete(\n                messages=[\n                    {\n                        \"role\": \"user\",\n                        \"content\": {\"type\": \"text\", \"text\": self.prompts[name]},\n                    }\n                ]\n            ), []\n        raise LookupError(f\"Method not found: {method}\")\n\n    def _call_tool(\n        self, params: dict[str, Any], metadata: dict[str, Any]\n    ) -> tuple[dict[str, Any], list[dict[str, Any]]]:\n        name = params[\"name\"]\n        if not isinstance(name, str) or not name:\n            raise ValueError(\"name must be a non-empty string\")\n        tool = self.tools.get(name)\n        if tool is None:\n            raise ValueError(\"unknown tool\")\n        arguments = tool.validate_arguments(params.get(\"arguments\", {}))\n        if name == \"prepare_review\":\n            return self._prepare_review(params, metadata, arguments), []\n\n        token = metadata.get(\"progressToken\")\n        notifications: list[dict[str, Any]] = []\n        if token is not None:\n            if not isinstance(token, (str, int)) or isinstance(token, bool):","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py#L286-L322","documentation":"The teaching MCP server's _dispatch routes only a fixed method set (initialize, tools/list, tools/call, resources/list, resources/read, prompts/list, prompts/get). Any other method string falls through to raise LookupError, mirroring JSON-RPC error -32601 method-not-found. It means the request reached a valid server but named a method outside its implemented surface.","triggerScenarios":"Calling exchange() with methods the server never implements: 'ping', 'notifications/initialized', 'completion/complete', 'logging/setLevel', or a case typo like 'tools/List' (dispatch is case-sensitive).","commonSituations":"Pointing a generic MCP client SDK built against a newer or older spec revision at this lesson server; hand-crafting JSON-RPC requests and misspelling the method; assuming every server supports optional features like ping or completion.","solutions":["Send only the methods _dispatch implements: initialize, tools/list, tools/call, resources/list, resources/read, prompts/list, prompts/get","Inspect the initialize result's capabilities object to learn which feature areas the server exposes before calling them","Catch LookupError in the client and map it to JSON-RPC error code -32601 instead of crashing"],"exampleFix":"# before\nresult = server.exchange(\"ping\", {})  # LookupError\n\n# after\nresult = server.exchange(\"tools/list\", {})","handlingStrategy":"try-catch","validationCode":"SUPPORTED = {\"initialize\", \"tools/list\", \"tools/call\", \"resources/list\", \"resources/read\", \"prompts/list\", \"prompts/get\"}\nif method not in SUPPORTED:\n    raise ValueError(f\"unsupported method: {method}\")\nresult = server.exchange(method, params)","typeGuard":"def is_supported_method(method: object) -> bool:\n    return isinstance(method, str) and method in {\n        \"initialize\", \"tools/list\", \"tools/call\",\n        \"resources/list\", \"resources/read\",\n        \"prompts/list\", \"prompts/get\",\n    }","tryCatchPattern":"try:\n    result = server.exchange(method, params)\nexcept LookupError as exc:\n    respond_error(request_id, -32601, str(exc))","preventionTips":["Read the server's initialize response before sending feature-specific requests","Treat method names as case-sensitive protocol tokens","Centralize dispatch in one client helper so unsupported methods fail in exactly one place"],"tags":["mcp","json-rpc","dispatch","method-routing"],"backgroundTag":"method-not-found","analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}