Merge pull request #987 from alpiua/fix-mcp-null-payload

fix(mcp): handle null JSON-RPC request payloads safely
This commit is contained in:
Igor Lins e Silva
2026-05-06 03:33:45 -03:00
committed by GitHub
2 changed files with 40 additions and 0 deletions
+15
View File
@@ -1968,6 +1968,12 @@ SUPPORTED_PROTOCOL_VERSIONS = [
def handle_request(request):
if not isinstance(request, dict):
return {
"jsonrpc": "2.0",
"id": None,
"error": {"code": -32600, "message": "Invalid Request"},
}
method = request.get("method") or ""
params = request.get("params") or {}
req_id = request.get("id")
@@ -2005,6 +2011,15 @@ def handle_request(request):
},
}
elif method == "tools/call":
if not isinstance(params, dict) or "name" not in params:
return {
"jsonrpc": "2.0",
"id": req_id,
"error": {
"code": -32602,
"message": "Invalid params: 'name' is required for tools/call",
},
}
tool_name = params.get("name")
tool_args = params.get("arguments") or {}
if tool_name not in TOOLS: