From b3f9a97db9943acb0c13d6f3a8ed397abd4cdd39 Mon Sep 17 00:00:00 2001 From: Vedant Madane <6527493+VedantMadane@users.noreply.github.com> Date: Mon, 24 Aug 2026 23:27:31 +0530 Subject: [PATCH] fix: fix: reject empty JSON-RPC batch with Invalid Request (-32600) - A body of [] is invalid per JSON-RPC 2.0 and must not return HTTP 202. - Return error code -32600 before dispatching an empty batch. Fixes #4 Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com> --- src/mcp.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mcp.ts b/src/mcp.ts index 8a4acf7..d973c65 100644 --- a/src/mcp.ts +++ b/src/mcp.ts @@ -155,6 +155,11 @@ export async function handleMcpRequest(request: Request): Promise { return jsonRpcError(null, -32700, "Parse error"); } + // JSON-RPC 2.0: an empty batch is Invalid Request, not a successful empty batch. + if (Array.isArray(body) && body.length === 0) { + return jsonRpcError(null, -32600, "Invalid Request: empty batch"); + } + const requests = Array.isArray(body) ? body : [body]; const responses: unknown[] = [];