The Hook
When an enterprise MCP server exposes dozens of existing REST API endpoints as AI tools, proxying each tools/call over a loopback HTTP request back into the same monolith doubles Puma thread contention, serializes JSON twice, and adds network tail latency—yet invoking the router in-process mutates shared Rack state under your feet.
The Deep Dive
In the GitLab monolith, route-backed MCP tools ( Mcp::Tools::Base::ApiTool ) avoid loopback HTTP overhead by dispatching directly to the underlying Grape API endpoint in-process via route.app.call(env) inside the outer POST /api/:version/mcp request. While investigating Issue #638385 and authoring MR !268703 ( fix(mcp): prevent duplicate API request logging ) , I uncovered what happens when an in-process sub-dispatch shares a mutable Rack env hash with its parent request.…