Skip to main content

Module http

Module http 

Source
Available on crate feature mcp only.
Expand description

Streamable-HTTP (and SSE) MCP transport.

Implements the MCP “Streamable HTTP” transport introduced in revision 2025-03-26 and carried forward in later revisions. A single HTTP endpoint serves every JSON-RPC message:

  • The client POSTs a JSON-RPC request (or notification) to the endpoint.
  • The server replies with either a single application/json body (one JSON-RPC message) or a text/event-stream body (Server-Sent Events, each data: line carrying one JSON-RPC message). Either way, this transport resolves the JsonRpcResponse whose id matches the request it sent.
  • The server may issue a Mcp-Session-Id header on the initialize response; the client echoes it on all subsequent requests.
  • After initialization the client sends the negotiated MCP-Protocol-Version header on every request, as the spec mandates.

Authentication is supplied as a bearer token / OAuth access token (sent as an Authorization: Bearer … header) or arbitrary custom headers.

The transport is generic over the HTTP layer via HttpPoster: production code uses ReqwestPoster (the default), while tests inject a scripted poster to exercise the JSON and SSE response paths deterministically with no live network.

Structs§

HttpReply
A single HTTP response from an MCP endpoint, normalised across the two streamable-HTTP body shapes.
HttpRequest
The HTTP request a transport wants to make, in transport-neutral form.
ReqwestPoster
Default HttpPoster backed by reqwest.
StreamableHttpTransport
Streamable-HTTP MCP transport.

Enums§

McpAuth
Authentication strategy for an HTTP MCP connection.

Traits§

HttpPoster
Abstraction over the act of POSTing one JSON-RPC message to the MCP endpoint.