{"record":{"id":"3795ad581f3449d7","repo":"rohitg00/ai-engineering-from-scratch","slug":"invalid-json-rpc-response-envelope-3795ad","errorCode":null,"errorMessage":"invalid JSON-RPC response envelope","messagePattern":"invalid JSON-RPC response envelope","errorType":"validation","errorClass":"ProtocolViolation","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/31-mcp-conformance-versioning-and-operations/code/main.py","lineNumber":389,"sourceCode":"\n\n@dataclass(frozen=True)\nclass CaseResult:\n    name: str\n    passed: bool\n    detail: str\n    evidence_digest: str\n\n\ndef validate_response(\n    request: dict[str, Any],\n    status: int,\n    response: dict[str, Any],\n    era: str,\n    capabilities: set[str],\n) -> None:\n    if not isinstance(response, dict) or response.get(\"jsonrpc\") != \"2.0\":\n        raise ProtocolViolation(\"invalid JSON-RPC response envelope\")\n    request_id = request.get(\"id\")\n    response_id = response.get(\"id\")\n    if type(response_id) is not type(request_id) or response_id != request_id:\n        raise ProtocolViolation(\"response id does not exactly match request id\")\n    has_result = \"result\" in response\n    has_error = \"error\" in response\n    if has_result == has_error:\n        raise ProtocolViolation(\"response must contain exactly one of result or error\")\n    if has_result:\n        if status != 200:\n            raise ProtocolViolation(\"successful JSON-RPC result requires HTTP 200\")\n        validate_result(response[\"result\"], era, capabilities)\n        validate_method_result(request[\"method\"], response[\"result\"])\n        return\n\n    error = response[\"error\"]\n    if not isinstance(error, dict):\n        raise ProtocolViolation(\"JSON-RPC error must be an object\")","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/31-mcp-conformance-versioning-and-operations/code/main.py#L371-L407","documentation":"Error \"invalid JSON-RPC response envelope\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/13-tools-and-protocols/31-mcp-conformance-versioning-and-operations/code/main.py:389 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"}