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:
committed by
Igor Lins e Silva
parent
46d9eb5df0
commit
0fdb480e12
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user