{"record":{"id":"fa45e80675f13cb5","repo":"rohitg00/ai-engineering-from-scratch","slug":"name-must-be-a-string","errorCode":null,"errorMessage":"name must be a string","messagePattern":"name must be a string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py","lineNumber":293,"sourceCode":"                        \"mimeType\": \"application/json\",\n                        \"text\": self.resources[uri],\n                    }\n                ],\n                ttlMs=30_000,\n                cacheScope=\"private\",\n            ), []\n        if method == \"prompts/list\":\n            prompts = [\n                {\"name\": name, \"description\": self.prompts[name]}\n                for name in sorted(self.prompts)\n            ]\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\")","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py#L275-L311","documentation":"For prompts/get, the server does params[\"name\"] and requires a str. Like error 106's URI check, a missing name key raises KeyError, so this message specifically means name is present but not a string — an int, dict, None, or list. The type check runs before the registry lookup, so a string name with no matching prompt gives error 109 instead.","triggerScenarios":"prompts/get with name set to 123, [\"summary\"], {\"id\": \"summary\"}, or None; passing a prompt object instead of its name field.","commonSituations":"Loading prompt identifiers from typed configs where they deserialize as non-strings; refactors that changed name from str to an enum/object without updating call sites; None defaults leaking into requests.","solutions":["Pass the prompt name as a string, e.g. \"code-review\"","If the name comes from structured data, extract and stringify it first (str(prompt[\"name\"]))","Guard with isinstance(name, str) before the exchange call"],"exampleFix":"# before\nserver.exchange(\"prompts/get\", {\"name\": {\"id\": \"code-review\"}, \"_meta\": meta})\n# after\nserver.exchange(\"prompts/get\", {\"name\": \"code-review\", \"_meta\": meta})","handlingStrategy":"type-guard","validationCode":"name = payload.get(\"name\")\nif not isinstance(name, str):\n    raise TypeError(\"prompt name must be a string\")\npayload[\"name\"] = name","typeGuard":"def is_valid_prompt_name(params: dict) -> bool:\n    return isinstance(params.get(\"name\"), str)","tryCatchPattern":null,"preventionTips":["Keep prompt identifiers as strings end-to-end; convert at the config boundary","Add a client-side type check in the prompts/get request builder","Write one integration test per prompt call so type regressions surface early"],"tags":["mcp","prompts","name","type-validation"],"backgroundTag":"wrong-argument-type","analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}