rohitg00/ai-engineering-from-scratch · error · RuntimeError
invalid response correlation
Error message
invalid response correlation
What it means
Raised in MCPClient.send when the JSON-RPC response is None or its id does not match the id stamped on the outgoing request. This guard detects lost, reordered, or misrouted responses on a shared transport before the caller treats an unrelated reply as its own result.
Solutions
- Ensure the server echoes the request id verbatim in the response object
- Check that the transport/connection used to receive the reply is the same one the request was sent on (no cross-instance mixups in MRTR demos)
- Log both request id and response id at the exchange boundary to pinpoint the mismatch
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py:525 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/c7ff1be2aa9776fa.
Report an issue: GitHub.
Appendix: source
Thrown at certifications/claude/lessons/11-mcp-server-design-and-integration/code/main.py:525
"id": self.next_id,
"method": method,
"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],
*,View on GitHub (pinned to 39ea8a1c6d)