In JSON-RPC 2.0, omitting the id member transforms a request into a fire-and-forget notification—meaning a naive MCP server that checks id presence after routing will happily execute a state-mutating tools/call and return 202 Accepted with an empty body, leaving the AI agent blind to the mutation it just triggered.
Unlike REST, where HTTP verbs and status codes carry transport-level semantics, Model Context Protocol (MCP) multiplexes all requests and notifications over a single JSON-RPC 2.0 message stream. Per the MCP specification, notifications are strictly methods prefixed with notifications/ (such as notifications/initialized) and must omit id, whereas every standard procedure call ( initialize, tools/list, tools/call) must include a non-null String or Integer id. When resolving Issue #638380 in MR !268112 (fix(mcp): reject invalid JSON-RPC request IDs), I traced how malformed JSON-RPC envelopes interacted with both GitLab's core MCP endpoint (lib/api/mcp/base.rb) and the GitLab Orbit MCP endpoint ( ee/lib/api/orbit/mcp.rb).
Two subtle traps existed at the Grape/Ruby boundary. First, in Ruby, checking params[:id].nil? cannot distinguish between an omitted "id" key (a JSON-RPC notification) and an explicit "id": null (which the MCP spec forbids for requests). Distinguishing the two requires inspecting key presence on the parsed parameter hash via params.key?(:id) before type validation. Second, if id validation is deferred until response serialization or after rate-limiting and gRPC/tool dispatch, a request with "method": "tools/call" and no "id" (or boolean, float, or array id) either consumes rate-limit budgets and executes side effects before failing, or gets misclassified as a notification and returns 202 Accepted with no payload.
In MR !268112, I implemented reject_invalid_jsonrpc_request_id! inside lib/api/helpers/mcp/json_rpc.rb and placed it at the top of the post block in both lib/api/mcp/base.rb and ee/lib/api/orbit/mcp.rb—executing before status :ok, rate_limit_mcp_command!, Orbit gRPC client initialization, or tool handler invocation. Legitimate notifications/* methods without an id short-circuit cleanly with 202 Accepted, while any non-notification missing :id or carrying a non-String/non- Integer :id is rejected immediately with HTTP 400 Bad Request and JSON-RPC error code -32600 (Invalid Request).
Across both /api/v4/mcp and GitLab Orbit's knowledge-graph MCP interface, GitLab enforces strict, pre-dispatch JSON-RPC 2.0 wire invariants (MR !268112) so malformed AI client frames never trigger unacknowledged side effects or consume enterprise rate-limit quotas.
Validate JSON-RPC 2.0 envelope invariants (params.key?(:id), strict integer/string type guards, and notifications/ method namespace rules) at the outermost ingress gate before touching rate limiters, gRPC channels, or tool dispatchers.