pub struct HttpTransport { /* private fields */ }Expand description
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.
Implementations§
Source§impl HttpTransport
impl HttpTransport
pub fn new( endpoint: McpEndpoint, headers: Vec<(String, String)>, ) -> HttpTransport
Sourcepub fn with_signer(
self,
signer: Option<Arc<dyn RequestSigner>>,
) -> HttpTransport
pub fn with_signer( self, signer: Option<Arc<dyn RequestSigner>>, ) -> HttpTransport
Install a per-request signer (AAuth). Builder-style; call before use.
Sourcepub fn set_identity(&mut self, identity: Option<ClientIdentity>)
pub fn set_identity(&mut self, identity: Option<ClientIdentity>)
Attach a mutual-TLS client identity (used only for https:// endpoints).
Sourcepub fn set_protocol_version(&self, version: String)
pub fn set_protocol_version(&self, version: String)
Record the negotiated protocol version, sent as MCP-Protocol-Version on
every subsequent request (called by the client after initialize/discovery).
Sourcepub fn clear_protocol_version(&self)
pub fn clear_protocol_version(&self)
Clear the negotiated version — the legacy initialize request must carry no
MCP-Protocol-Version header (nothing agreed yet), so this resets what a
prior modern probe set.
pub fn scheme(&self) -> &'static str
Sourcepub fn send<F>(
&self,
request_id: Option<i64>,
body: &[u8],
timeout: Duration,
extra_headers: &[(&str, &str)],
on_notification: F,
) -> Result<Option<Value>, HttpError>
pub fn send<F>( &self, request_id: Option<i64>, body: &[u8], timeout: Duration, extra_headers: &[(&str, &str)], on_notification: F, ) -> Result<Option<Value>, HttpError>
POST one JSON-RPC message. For a REQUEST (id present), return the JSON-RPC
response with the matching id — parsed from the application/json body or
pumped out of the text/event-stream (queuing any interleaved
notifications via on_notification). For a NOTIFICATION (id absent), the
server replies 202 Accepted with no body and Ok(None) is returned.
Captures/echoes Mcp-Session-Id.
Sourcepub fn session_id(&self) -> Option<String>
pub fn session_id(&self) -> Option<String>
The session id the server assigned, if this connection has one.
Sourcepub fn open_events(
&self,
read_timeout: Duration,
) -> Result<SseReader<BufReader<Box<dyn Stream>>>, HttpError>
pub fn open_events( &self, read_timeout: Duration, ) -> Result<SseReader<BufReader<Box<dyn Stream>>>, HttpError>
Open the long-lived server→client notification stream: a GET that the
server answers with text/event-stream, carrying JSON-RPC notifications
(e.g. resources/updated). Returns an owning SSE reader. read_timeout
bounds each read so the caller’s loop can poll a stop flag between events
(clean shutdown). Errors if the server has no push channel (non-2xx or a
non-SSE response) — the caller then runs without server-initiated pushes.
Sourcepub fn open_listen(
&self,
read_timeout: Duration,
body: &[u8],
routing: &[(&str, &str)],
) -> Result<SseReader<BufReader<Box<dyn Stream>>>, HttpError>
pub fn open_listen( &self, read_timeout: Duration, body: &[u8], routing: &[(&str, &str)], ) -> Result<SseReader<BufReader<Box<dyn Stream>>>, HttpError>
Open the MODERN long-lived notification stream via a subscriptions/listen
POST. The modern era has no GET stream, so this response IS the push
channel. body is the full pre-built JSON-RPC request (its _meta
already injected); routing
are the Mcp-Method/Mcp-Name headers. The server answers with an SSE stream
that stays open, carrying the opted-in notifications; returns its reader.