rohitg00/ai-engineering-from-scratch · error · RuntimeError
error
Error message
error
What it means
A sentinel error re-raised in MCPClient.send when the correlated JSON-RPC response carries an 'error' member instead of a 'result'. It surfaces the server-side failure (protocol error, tool failure, or bad params) to the caller of request/call_with_mrtr instead of silently returning a malformed payload.
Solutions
- Inspect the response error.code and error.message to identify which JSON-RPC error the server returned
- Fix the request params or method that triggered the server-side error
- For transient server errors (overloaded, timeout), retry the request with the same client id sequencing
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py:527 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/2be3532407520c95.
Report an issue: GitHub.
Appendix: source
Thrown at certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py:527
"params": {**request_params, "_meta": metadata},
}
self.next_id += 1
return request
def send(
self,
method: str,
params: dict[str, Any] | None = None,
*,
server: MCPServer | None = None,
) -> tuple[dict[str, Any], dict[str, Any]]:
request = self.build_request(method, params)
response, notifications = (server or self.server).exchange(request)
self.notifications.extend(notifications)
if response is None or response.get("id") != request["id"]:
raise RuntimeError("invalid response correlation")
if "error" in response:
raise RuntimeError(json.dumps(response["error"], sort_keys=True))
return request, response["result"]
def request(
self,
method: str,
params: dict[str, Any] | None = None,
*,
server: MCPServer | None = None,
) -> dict[str, Any]:
_request, result = self.send(method, params, server=server)
return result
def call_with_mrtr(
self,
params: dict[str, Any],
*,
first_server: MCPServer,
retry_server: MCPServer,View on GitHub (pinned to 39ea8a1c6d)