Principle:21st dev Magic mcp MCP Transport Proxy
| Knowledge Sources | |
|---|---|
| Domains | Protocol, Networking |
| Last Updated | 2026-10-19 16:40 GMT |
Overview
A transport pattern that bridges a stdio JSON-RPC client to an HTTP MCP server, forwarding each message verbatim while latching the session id and preserving strict request ordering.
Description
An MCP transport proxy bridges two transports — stdio on the client side, HTTP on the server side — so a client that only speaks stdio can reach an HTTP-only MCP server. It addresses the limitation that MCP clients and servers may support different transports. A correct proxy is transport-only: it never interprets tool calls, forwarding each JSON-RPC message opaquely. It latches the `mcp-session-id` from the `initialize` response and echoes it on subsequent requests so capability negotiation (and inline UI) survives the hop. It processes requests sequentially — one in-flight at a time — which guarantees the initialize → session-id handshake lands before anything else. It restores the request `id` on responses where the server returns `id:null`, so strict clients can correlate responses with requests.
Usage
Use this principle when a client speaks stdio MCP but the server is HTTP-only, and you need to keep existing stdio configs working against the new HTTP endpoint. The proxy is launched as a stdio server by the client's MCP config; it forwards each inbound line as one authenticated POST.
Theoretical Basis
The core operation is a sequential, transparent forward with two latches:
# Abstract algorithm description (NOT real implementation)
session_id = None
for line in stdin_lines: # sequential pump
msg = parse_jsonrpc(line) # opaque; never interpret
headers = { "x-api-key": key }
if session_id: headers["mcp-session-id"] = session_id
response = http_post(endpoint, headers, body=line)
if response.status == 401: auth_refused = True # latch, never reset
new_session = response.headers.get("mcp-session-id")
if new_session: session_id = new_session # latch
if response.id is None and msg.id is not None:
response.id = msg.id # restore id for strict clients
write_stdout(response)
The sequential pump is not a bottleneck for typical MCP usage and is what makes the handshake ordering reliable.
Practical Guide
- Forward JSON-RPC verbatim — never inspect or rewrite tool calls.
- Latch `mcp-session-id` from `initialize` and echo it on all later requests.
- Process one request at a time (sequential pump) so the handshake lands first.
- Restore the request `id` when the server returns `id:null`.
- Make the endpoint overridable (e.g. via an env var) for testing.
- Send the auth header (`x-api-key`) on every request — see Principle:21st_dev_Magic_mcp_API_Key_Management.
Related Pages
Implemented By
Notes
- The auth-refused latch makes this proxy also the realization of Principle:21st_dev_Magic_mcp_Auth_Failure_Recovery — one implementation, two principles.
- The proxy is transport-only; the 21st MCP tool surface lives server-side (see the External Tool Docs: search, get_component, generate, ...).