{"record":{"id":"3ee2c71fa9ed0c96","repo":"rohitg00/ai-engineering-from-scratch","slug":"json-rpc-error-requires-integer-code-and-string-me","errorCode":null,"errorMessage":"JSON-RPC error requires integer code and string message","messagePattern":"JSON-RPC error requires integer code and string message","errorType":"validation","errorClass":"ProtocolViolation","httpStatus":null,"severity":"error","filePath":"phases/13-tools-and-protocols/31-mcp-conformance-versioning-and-operations/code/main.py","lineNumber":410,"sourceCode":"    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\")\n    code = error.get(\"code\")\n    if isinstance(code, bool) or not isinstance(code, int) or not isinstance(error.get(\"message\"), str):\n        raise ProtocolViolation(\"JSON-RPC error requires integer code and string message\")\n    expected_status = {-32020: 400, -32021: 400, -32022: 400, -32601: 404}.get(code)\n    if expected_status is not None and status != expected_status:\n        raise ProtocolViolation(f\"JSON-RPC error {code} requires HTTP {expected_status}\")\n\n\ndef validate_protocol_error_evidence(case: Transcript, expected_code: int) -> None:\n    if case.response_body is None:\n        raise ProtocolViolation(\"expected JSON-RPC error response is missing\")\n    validate_response(\n        case.request,\n        case.response_status,\n        case.response_body,\n        case.era,\n        set(case.capabilities),\n    )\n    error = case.response_body.get(\"error\")\n    if not isinstance(error, dict) or error.get(\"code\") != expected_code:\n        raise ProtocolViolation(f\"server did not return JSON-RPC error {expected_code}\")","sourceCodeStart":392,"sourceCodeEnd":428,"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#L392-L428","documentation":"Error \"JSON-RPC error requires integer code and string message\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/13-tools-and-protocols/31-mcp-conformance-versioning-and-operations/code/main.py:410 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"}