fix(mcp): handle null JSON-RPC request payloads safely

When the MCP client sends a malformed or null top-level request, prevent the AttributeError on request.get() by explicitly validating that the request is a dictionary. Returns standard JSON-RPC Error -32600 (Invalid Request) instead of crashing the server.
This commit is contained in:
Oleksii Pylypchuk
2026-04-18 01:55:43 +03:00
committed by Igor Lins e Silva
parent 46d9eb5df0
commit 0fdb480e12
+2
View File
@@ -1968,6 +1968,8 @@ SUPPORTED_PROTOCOL_VERSIONS = [
def handle_request(request):
if not isinstance(request, dict):
return {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}}
method = request.get("method") or ""
params = request.get("params") or {}
req_id = request.get("id")