Merge pull request #987 from alpiua/fix-mcp-null-payload
fix(mcp): handle null JSON-RPC request payloads safely
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user