Skip to main content

Module http

Module http 

Source
Expand description

The MCP Streamable HTTP client transport.

A conformant remote MCP server is reached by POSTing a JSON-RPC message to a single endpoint; the server replies with either a application/json body (one message) or a text/event-stream (SSE) carrying one or more messages. A server-assigned Mcp-Session-Id (returned on initialize) is echoed on every subsequent request. Server→client notifications ride an optional long-lived GET SSE stream.

The transport is stream-agnostic (it reuses the hand-rolled net::http client): https:// runs over TCP+TLS (optionally mutual TLS), http:// over plain TCP (a local sidecar), unix: over a unix socket, and vsock: over AF_VSOCK. None of these spawns a process: the transport has no local exec surface, so a hostile server config cannot turn into command execution here.

Structs§

AuthResponse
The AAuth-relevant fields of a server response. Handed to RequestSigner::on_response so the signer can satisfy a runtime AAuth-Requirement and decide whether a retry would now succeed.
HttpTransport
The Streamable HTTP transport for one MCP server. Cheap to hold; each request opens a fresh connection (Connection: close), so there is no persistent socket to reap. session is set from the server’s Mcp-Session-Id on the first response and echoed thereafter.

Enums§

HttpError
An MCP transport error (connect / HTTP / protocol).
McpEndpoint
A resolved MCP endpoint: where to connect + the HTTP path/Host to send.

Traits§

RequestSigner
A per-request AAuth signer. The transport calls [sign] just before each POST (the returned (name, value) pairs become request headers — the RFC 9421 Signature-Input/Signature/Signature-Key), and [on_response] after, to react to the server’s AAuth-Requirement (adopt an access token, run the Person-Server flow) and re-sign+retry. Deliberately a trait, not an implementation: the crypto lives in the caller, so this crate stays free of any crypto dependency.

Functions§

authority_of
The Host authority (host[:port]) of an MCP endpoint URL — the @authority AAuth signs over. localhost for non-TCP endpoints. Best-effort (a parse failure yields an empty string).

Type Aliases§

EventStream
An owning SSE reader over the notification GET stream (a boxed transport stream, so it survives on the notification thread).