fix(mcp): Validate JSON-RPC response is a dict before accessing keys

Add isinstance check after response.json() to prevent TypeError/
AttributeError if an MCP server returns a non-object JSON response.
This commit is contained in:
Zamil Majdy
2026-02-10 20:31:37 +04:00
parent 6ebd97f874
commit bb8b56c7de

View File

@@ -149,6 +149,11 @@ class MCPClient:
f"MCP server returned non-JSON response: {e}"
) from e
if not isinstance(body, dict):
raise MCPClientError(
f"MCP server returned unexpected JSON type: {type(body).__name__}"
)
# Handle JSON-RPC error
if "error" in body:
error = body["error"]