Skip to main content

HttpClientTransport

Struct HttpClientTransport 

Source
pub struct HttpClientTransport { /* private fields */ }
Expand description

HTTP transport for MCP clients

This transport communicates with an MCP server via HTTP requests and optionally uses Server-Sent Events for real-time notifications.

Implementations§

Source§

impl HttpClientTransport

Source

pub async fn new<S: AsRef<str>>( base_url: S, sse_url: Option<S>, ) -> McpResult<Self>

Create a new HTTP client transport

§Arguments
  • base_url - Base URL for the MCP server
  • sse_url - Optional URL for Server-Sent Events (for notifications)
§Returns

Result containing the transport or an error

Source

pub async fn with_config<S: AsRef<str>>( base_url: S, sse_url: Option<S>, config: TransportConfig, ) -> McpResult<Self>

Create a new HTTP client transport with custom configuration

§Arguments
  • base_url - Base URL for the MCP server
  • sse_url - Optional URL for Server-Sent Events
  • config - Transport configuration
§Returns

Result containing the transport or an error

Source

pub async fn with_mtls<S: AsRef<str>>( base_url: S, sse_url: Option<S>, config: TransportConfig, mtls: MtlsClientConfig, ) -> McpResult<Self>

Create an HTTP client that presents a certificate and validates the server against the supplied private CA.

Source

pub async fn next_request_id(&self) -> u64

Source

pub async fn active_request_count(&self) -> usize

Get count of active requests (for debugging/metrics)

Source§

impl HttpClientTransport

Production-grade convenience methods for HttpClientTransport

Source

pub async fn ping(&mut self) -> McpResult<Duration>

Send a health check request and measure response time

Source

pub async fn get_server_info(&mut self) -> McpResult<ServerInfo>

Retrieve server capabilities and version information

Source

pub async fn get_connection_stats(&self) -> ConnectionStats

Get connection statistics for monitoring

Source

pub fn is_healthy(&self) -> bool

Quick health check based on recent activity

Source

pub async fn call_method<T: Serialize, R: for<'de> Deserialize<'de>>( &mut self, method: &str, params: T, ) -> McpResult<R>

Type-safe method calling with automatic serialization

Source

pub async fn call_method_simple(&mut self, method: &str) -> McpResult<Value>

Simple method call without parameters

Source

pub async fn batch_requests( &mut self, requests: Vec<JsonRpcRequest>, ) -> McpResult<Vec<JsonRpcResponse>>

Send multiple requests efficiently

Source

pub async fn reconnect(&mut self) -> McpResult<()>

Reconnect with same configuration

Source

pub async fn test_connection(&self) -> McpResult<bool>

Test if connection is working without modifying state

Source

pub fn update_headers(&mut self, new_headers: HashMap<String, String>)

Update headers without recreating transport

Source

pub fn set_timeout(&mut self, timeout_ms: u64)

Update timeout configuration

Source

pub fn get_config(&self) -> &TransportConfig

Access current configuration

Source

pub fn get_base_url(&self) -> &str

Get current base URL

Source

pub fn get_sse_url(&self) -> Option<&str>

Get current SSE URL

Source

pub fn get_endpoints(&self) -> HttpEndpoints

Get all endpoint URLs

Source

pub async fn call_with_retry<T: Serialize + Clone, R: for<'de> Deserialize<'de>>( &mut self, method: &str, params: T, retry_config: RetryConfig, ) -> McpResult<R>

Method call with automatic retry logic

Source

pub fn set_retry_policy(&mut self, _policy: RetryPolicy)

Set retry policy for automatic retries (would require state extension)

Source

pub fn enable_request_logging(&mut self, _enabled: bool)

Enable/disable request/response logging (placeholder)

Source

pub fn get_last_error(&self) -> Option<&McpError>

Get the last error that occurred (placeholder)

Source

pub async fn export_metrics(&self) -> McpResult<TransportMetrics>

Export detailed metrics for monitoring (placeholder)

Source§

impl HttpClientTransport

Source

pub fn builder() -> HttpClientTransportBuilder

Create a new builder for HttpClientTransport

Trait Implementations§

Source§

impl Debug for HttpClientTransport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Transport for HttpClientTransport

Source§

fn send_request<'life0, 'async_trait>( &'life0 mut self, request: JsonRpcRequest, ) -> Pin<Box<dyn Future<Output = McpResult<JsonRpcResponse>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a JSON-RPC request and wait for a response Read more
Source§

fn send_notification<'life0, 'async_trait>( &'life0 mut self, notification: JsonRpcNotification, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a JSON-RPC notification (no response expected) Read more
Source§

fn receive_notification<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = McpResult<Option<JsonRpcNotification>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receive a notification from the server (non-blocking) Read more
Source§

fn open_subscription<'life0, 'async_trait>( &'life0 mut self, request: JsonRpcRequest, ) -> Pin<Box<dyn Future<Output = McpResult<ClientSubscription>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Open a modern long-lived subscription stream.
Source§

fn cancel_subscription<'life0, 'life1, 'async_trait>( &'life0 mut self, request_id: &'life1 Value, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cancel an open subscription. HTTP implementations close the response stream; STDIO implementations send notifications/cancelled.
Source§

fn close<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Close the transport connection Read more
Source§

fn is_connected(&self) -> bool

Check if the transport is connected Read more
Source§

fn connection_info(&self) -> String

Get connection information for debugging Read more
Source§

fn handle_incoming_request<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = McpResult<Option<JsonRpcRequest>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle incoming server request (for bidirectional communication) Read more
Source§

fn send_response<'life0, 'async_trait>( &'life0 mut self, _response: JsonRpcResponse, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send response to server request (for bidirectional communication) Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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