Menu

In-Process Rack Dispatch in GitLab's MCP Server: Eliminating Local HTTP Loopback Without Corrupting env
📰

In-Process Rack Dispatch in GitLab's MCP Server: Eliminating Local HTTP Loopback Without Corrupting env

DEV Community: rails·Aryan Rajput·about 5 hours ago
#zyIXknvL
#devtorails#devto#dev#execute_route#rack
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.