Skip to main content

HttpTransport

Struct HttpTransport 

Source
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

Source

pub fn new( endpoint: McpEndpoint, headers: Vec<(String, String)>, ) -> HttpTransport

Source

pub fn with_signer( self, signer: Option<Arc<dyn RequestSigner>>, ) -> HttpTransport

Install a per-request signer (AAuth). Builder-style; call before use.

Source

pub fn set_identity(&mut self, identity: Option<ClientIdentity>)

Attach a mutual-TLS client identity (used only for https:// endpoints).

Source

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).

Source

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.

Source

pub fn scheme(&self) -> &'static str

Source

pub fn send<F>( &self, request_id: Option<i64>, body: &[u8], timeout: Duration, extra_headers: &[(&str, &str)], on_notification: F, ) -> Result<Option<Value>, HttpError>
where F: FnMut(Value),

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.

Source

pub fn session_id(&self) -> Option<String>

The session id the server assigned, if this connection has one.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more