Expand description
The Streamable HTTP MCP server: HTTP/1.1 + SSE over TCP (plain, or TLS via
the [net::tls] acceptor), reusing the same Handler / [lifecycle_response]
/ SubRegistry as the socket servers. This is the
serving mirror of the crate’s HTTP client (crate::http) and the transport
the HTTPS control plane rides.
Model (Streamable HTTP, both eras):
- Unary — one
POSTcarrying a JSON-RPC request; the reply isapplication/json.initializeis stamped with anMcp-Session-Id(legacy). One request per connection (Connection: close), matching the client’s dialer. - Reactive — a
POST subscriptions/listen(modern, stateless): the connection becomes a long-livedtext/event-stream. Each requested uri is run through the handler’s normalresources/subscribegate (so the embedder’s per-origin subscribability rules apply unchanged) and, if accepted, this connection’s SSE write half is registered in the shared registry — so the embedder’s existingnotify_*pushes reach it as SSEdata:events. The stream is held open with periodic keep-alive comments; a failed write prunes the subscriptions and ends the connection.
Trust is never transport-derived. Every request is classified by an
HttpAuth the embedder supplies (mutual-TLS client identity primary, bearer
token alternative); an unauthenticated peer gets 401 and never reaches the
handler.
Structs§
- Allow
All - Allow every request as
PeerOrigin::Management— for loopback dev / tests only. NOT for a real listener (it makes the transport the trust boundary, exactly the posture the pivot removes). - PeerId
- A verified mTLS peer’s identity, surfaced so an embedder can match a caller to a named principal rather than merely observing “a cert was presented”. All-empty for a plain / no-client-cert connection. rustls has already verified the chain; these fields are only read from the leaf certificate, so they are safe to compare against — but only because verification already happened.
- RawRequest
- A raw inbound HTTP request handed straight to a
RawHandler: method, target (path + optional query), lowercased headers, and the raw body. Unlike theHandlerpath this does no JSON-RPC parsing and no transport-level auth — the embedder routes byRawRequest::pathand authenticates itself (e.g. a per-webhook HMAC over the raw body). The DNS-rebindOriginguard and TLS termination still apply. - RawResponse
- A raw HTTP response a
RawHandlerreturns. - Request
Parts - The parts of an inbound request an
HttpAuthclassifies trust from. - Serve
Options - Per-listener serving options beyond the handler/auth pair.
Enums§
- Http
Acceptor - How accepted TCP connections are wrapped: plaintext (loopback dev) or TLS
(the production control plane). The TLS variant carries the [
net::tls] acceptor, which drives the handshake (and, under mTLS, verifies the client certificate) at accept time.
Traits§
- Http
Auth - The embedder’s auth policy: classify an inbound request’s trust origin, or
reject it. Called once per connection before the handler sees anything. The
framework NEVER trusts by transport alone — return
Noneto answer401. - RawHandler
- A raw-HTTP embedder surface (the agentd webhook listener). One call per request; the embedder routes and authenticates itself.
Functions§
- bind_
tcp - Bind a TCP listener for HTTP serving. Kept separate from the accept loop so the caller can log/act on a successful bind (or propagate the error) before the accept thread starts.
- spawn_
accept_ http - Spawn the background accept thread: one blocking thread per connection, each
serving HTTP/1.1 (+ SSE) against
handler, with trust classified byauth. Peers that authenticate arrive in whateverPeerOriginauthmints. - spawn_
accept_ http_ opts spawn_accept_httpwith explicitServeOptions(extra browser origins).- spawn_
accept_ raw - Spawn a raw-HTTP accept loop — TLS-terminated like
spawn_accept_http, with the same DNS-rebindOriginguard — dispatching each request tohandler.