Expand description
MCP Streamable HTTP client for backends configured with
transport = "mcp" (the default for [[backends]]).
The gateway speaks to each backend the way a conforming MCP client does (Streamable HTTP transport, 2025-11-25):
- every POST carries
Accept: application/json, text/event-stream; - the first request of a backend session is
initialize, followed bynotifications/initialized; a returnedMCP-Session-Idis sent on every later request together withMCP-Protocol-Version; - a
404on a request that carried a session id means the backend ended the session: the client starts a new one and retries once (the backend did not process the request, so the retry cannot run a tool twice); - a request may be answered with one JSON object or with an SSE
stream. The stream is decoded incrementally and reading stops at the
JSON-RPC response whose
idmatches the request. Server-to-client requests that arrive first are answered (pingwith an empty result, anything else with “method not found”), because the gateway declares no client capabilities and a waiting backend would otherwise hang until the deadline. A stream that ends early after carrying an event id is resumed withGETandLast-Event-ID.
Backend sessions are kept per (agent session, backend) pair so state a
backend keeps per session never leaks between agents. The table is
bounded; an evicted entry only costs a fresh initialize.
Structs§
- Backend
Endpoint - Everything needed to talk to one backend endpoint.
- Backend
Session - A negotiated backend session.
- McpBackend
Client - Client for MCP backends, holding the bounded backend-session table.
- SseDecoder
- Incremental decoder for
text/event-streambodies, following the WHATWG event-stream interpretation rules that MCP relies on.
Enums§
- McpError
- Why a backend exchange failed. The distinction matters to the caller:
only
McpError::NotDeliveredproves the backend never processed the request, so only that failure may release a claimed tool execution.
Constants§
- LATEST_
PROTOCOL_ VERSION - The version offered in
initializeand preferred in negotiation. - PROTOCOL_
VERSION_ HEADER - Header carrying the negotiated protocol version on later requests.
- SESSION_
ID_ HEADER - Header carrying the backend-assigned (or gateway-assigned) session id.
- SUPPORTED_
PROTOCOL_ VERSIONS - Protocol versions this gateway implements, newest first.
Functions§
- is_
supported_ version - True for a protocol version string this gateway implements.