{"record":{"id":"d40135fdca657976","repo":"rohitg00/ai-engineering-from-scratch","slug":"json-rpc-result-must-be-an-object","errorCode":null,"errorMessage":"JSON-RPC result must be an object","messagePattern":"JSON-RPC result must be an object","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/08-building-an-mcp-client/code/main.py","lineNumber":115,"sourceCode":"    response: dict[str, Any],\n    expected_id: int | str,\n) -> tuple[str, dict[str, Any]]:\n    response_id = response.get(\"id\")\n    if (\n        response.get(\"jsonrpc\") != \"2.0\"\n        or type(response_id) not in (int, str)\n        or type(response_id) is not type(expected_id)\n        or response_id != expected_id\n    ):\n        raise RuntimeError(\"invalid JSON-RPC response envelope\")\n    has_result = \"result\" in response\n    has_error = \"error\" in response\n    if has_result == has_error:\n        raise RuntimeError(\"JSON-RPC response must contain exactly one of result or error\")\n    if has_result:\n        result = response[\"result\"]\n        if not isinstance(result, dict):\n            raise RuntimeError(\"JSON-RPC result must be an object\")\n        return \"result\", result\n    error = response[\"error\"]\n    if not isinstance(error, dict):\n        raise RuntimeError(\"JSON-RPC error must be an object\")\n    code = error.get(\"code\")\n    if not isinstance(code, int) or isinstance(code, bool) or not isinstance(error.get(\"message\"), str):\n        raise RuntimeError(\"JSON-RPC error requires an integer code and string message\")\n    return \"error\", error\n\n\ndef validate_modern_request(message: dict[str, Any], supported: list[str]) -> None:\n    if message.get(\"jsonrpc\") != \"2.0\" or not isinstance(message.get(\"method\"), str):\n        raise RpcFault(-32600, \"Invalid Request\")\n    params = message.get(\"params\")\n    if not isinstance(params, dict) or not isinstance(params.get(\"_meta\"), dict):\n        raise RpcFault(-32602, \"Modern params._meta is required\")\n    meta = params[\"_meta\"]\n    requested = meta.get(VERSION_KEY)","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/08-building-an-mcp-client/code/main.py#L97-L133","documentation":"Error \"JSON-RPC result must be an object\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/13-tools-and-protocols/08-building-an-mcp-client/code/main.py:115 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"}