{"record":{"id":"d863b744b185ff8c","repo":"rohitg00/ai-engineering-from-scratch","slug":"peer-name-malformed-modern-discovery-result","errorCode":null,"errorMessage":"{peer.name}: malformed modern discovery result","messagePattern":"(.+?): malformed modern discovery result","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/08-building-an-mcp-client/code/main.py","lineNumber":430,"sourceCode":"        )\n        try:\n            response = self._send(peer, probe, self.discovery_timeout_ms)\n        except (TimeoutError, ConnectionError) as exc:\n            self._probe_legacy(peer, type(exc).__name__)\n            return\n\n        if response is None:\n            self._probe_legacy(peer, \"empty discovery response\")\n            return\n        if not isinstance(response, dict):\n            raise RuntimeError(f\"{peer.name}: malformed discovery response\")\n        kind, payload = decode_rpc_response(response, request_id)\n        if kind == \"result\":\n            advertised = payload.get(\"supportedVersions\", [])\n            if not isinstance(advertised, list) or not all(\n                isinstance(version, str) for version in advertised\n            ):\n                raise RuntimeError(f\"{peer.name}: malformed modern discovery result\")\n            selected = self._mutual_version(advertised)\n            if selected is None:\n                raise RuntimeError(f\"{peer.name}: no mutually supported modern version\")\n            self._activate_modern(peer, payload, selected)\n            return\n\n        code = payload[\"code\"]\n        if code in RECOGNIZED_MODERN_ERRORS:\n            if code != -32022:\n                raise RuntimeError(f\"{peer.name}: correct modern request error {code} before retrying\")\n            data = payload.get(\"data\")\n            advertised = data.get(\"supported\", []) if isinstance(data, dict) else []\n            selected = self._mutual_version(advertised)\n            if selected is None:\n                raise RuntimeError(f\"{peer.name}: no mutually supported modern version\")\n            retry_id = self._new_id()\n            retry = modern_request(\n                retry_id,","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/08-building-an-mcp-client/code/main.py#L412-L448","documentation":"The peer answered server/discover with a result, but its supportedVersions field is not a list of strings. The client requires an explicit, well-typed version advertisement before it can pick a mutually supported revision.","triggerScenarios":"decode_rpc_response returns kind='result' and payload.get('supportedVersions') is not a list, or contains entries that are not str.","commonSituations":"Server serializing versions as numbers or nulls; a typo'd field in a custom server build; a discovery payload built by hand in tests.","solutions":["Log the discovery result and inspect supportedVersions","Fix the server to emit supportedVersions as an array of version strings","Validate the server build against the modern discovery schema"],"exampleFix":"// before (server)\n{\"supportedVersions\": [\"1.1\", 1.2]}\n\n// after\n{\"supportedVersions\": [\"1.1\", \"1.2\"]}","handlingStrategy":"validation","validationCode":"adv = probe_supported_versions(peer)\nif not (isinstance(adv, list) and all(isinstance(v, str) for v in adv)):\n    fix_server_discovery_payload(peer)","typeGuard":"def valid_version_advertisement(v) -> bool:\n    return isinstance(v, list) and all(isinstance(x, str) for x in v)","tryCatchPattern":"null","preventionTips":["Contract-test server/discover responses","Serialize versions as strings end to end"],"tags":["mcp","schema-validation","discovery","version-negotiation"],"backgroundTag":"schema-validation-failed","analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}