cd /news/ai-agents/pre-dispatch-wire-validation-in-json… · home › topics › ai-agents › article
[ARTICLE · art-170567] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Pre-Dispatch Wire Validation in JSON-RPC 2.0: Closing the Phantom 202 Accepted Mutation Hole

A GitLab engineer merged MR !268112, adding a reject_invalid_jsonrpc_request_id! helper to lib/api/helpers/mcp/json_rpc.rb that runs at the top of the post block in both the core MCP endpoint (lib/api/mcp/base.rb) and the Orbit MCP endpoint (ee/lib/api/orbit/mcp.rb). The fix closes a hole where a tools/call request missing its JSON-RPC id was treated as a notification and returned 202 Accepted after executing side effects and consuming rate-limit budget; such requests now fail fast with HTTP 400 and JSON-RPC error -32600, while legitimate notifications/* methods still return 202. The change enforces strict wire invariants on both /api/v4/mcp and the Orbit knowledge-graph MCP interface before rate limiting, gRPC initialization, or tool dispatch.

by read2 min views1 publishedNov 16, 2026

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.

── more in #ai-agents 4 stories · sorted by recency
── more on @gitlab 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/pre-dispatch-wire-va…] indexed:0 read:2min 2026-11-16 · —