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
impl HttpClientTransport
Sourcepub async fn with_config<S: AsRef<str>>(
base_url: S,
sse_url: Option<S>,
config: TransportConfig,
) -> McpResult<Self>
pub async fn with_config<S: AsRef<str>>( base_url: S, sse_url: Option<S>, config: TransportConfig, ) -> McpResult<Self>
Sourcepub async fn with_mtls<S: AsRef<str>>(
base_url: S,
sse_url: Option<S>,
config: TransportConfig,
mtls: MtlsClientConfig,
) -> McpResult<Self>
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.
pub async fn next_request_id(&self) -> u64
Sourcepub async fn active_request_count(&self) -> usize
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
impl HttpClientTransport
Production-grade convenience methods for HttpClientTransport
Sourcepub async fn ping(&mut self) -> McpResult<Duration>
pub async fn ping(&mut self) -> McpResult<Duration>
Send a health check request and measure response time
Sourcepub async fn get_server_info(&mut self) -> McpResult<ServerInfo>
pub async fn get_server_info(&mut self) -> McpResult<ServerInfo>
Retrieve server capabilities and version information
Sourcepub async fn get_connection_stats(&self) -> ConnectionStats
pub async fn get_connection_stats(&self) -> ConnectionStats
Get connection statistics for monitoring
Sourcepub fn is_healthy(&self) -> bool
pub fn is_healthy(&self) -> bool
Quick health check based on recent activity
Sourcepub async fn call_method<T: Serialize, R: for<'de> Deserialize<'de>>(
&mut self,
method: &str,
params: T,
) -> McpResult<R>
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
Sourcepub async fn call_method_simple(&mut self, method: &str) -> McpResult<Value>
pub async fn call_method_simple(&mut self, method: &str) -> McpResult<Value>
Simple method call without parameters
Sourcepub async fn batch_requests(
&mut self,
requests: Vec<JsonRpcRequest>,
) -> McpResult<Vec<JsonRpcResponse>>
pub async fn batch_requests( &mut self, requests: Vec<JsonRpcRequest>, ) -> McpResult<Vec<JsonRpcResponse>>
Send multiple requests efficiently
Sourcepub async fn test_connection(&self) -> McpResult<bool>
pub async fn test_connection(&self) -> McpResult<bool>
Test if connection is working without modifying state
Sourcepub fn update_headers(&mut self, new_headers: HashMap<String, String>)
pub fn update_headers(&mut self, new_headers: HashMap<String, String>)
Update headers without recreating transport
Sourcepub fn set_timeout(&mut self, timeout_ms: u64)
pub fn set_timeout(&mut self, timeout_ms: u64)
Update timeout configuration
Sourcepub fn get_config(&self) -> &TransportConfig
pub fn get_config(&self) -> &TransportConfig
Access current configuration
Sourcepub fn get_base_url(&self) -> &str
pub fn get_base_url(&self) -> &str
Get current base URL
Sourcepub fn get_sse_url(&self) -> Option<&str>
pub fn get_sse_url(&self) -> Option<&str>
Get current SSE URL
Sourcepub fn get_endpoints(&self) -> HttpEndpoints
pub fn get_endpoints(&self) -> HttpEndpoints
Get all endpoint URLs
Sourcepub async fn call_with_retry<T: Serialize + Clone, R: for<'de> Deserialize<'de>>(
&mut self,
method: &str,
params: T,
retry_config: RetryConfig,
) -> McpResult<R>
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
Sourcepub fn set_retry_policy(&mut self, _policy: RetryPolicy)
pub fn set_retry_policy(&mut self, _policy: RetryPolicy)
Set retry policy for automatic retries (would require state extension)
Sourcepub fn enable_request_logging(&mut self, _enabled: bool)
pub fn enable_request_logging(&mut self, _enabled: bool)
Enable/disable request/response logging (placeholder)
Sourcepub fn get_last_error(&self) -> Option<&McpError>
pub fn get_last_error(&self) -> Option<&McpError>
Get the last error that occurred (placeholder)
Sourcepub async fn export_metrics(&self) -> McpResult<TransportMetrics>
pub async fn export_metrics(&self) -> McpResult<TransportMetrics>
Export detailed metrics for monitoring (placeholder)
Source§impl HttpClientTransport
impl HttpClientTransport
Sourcepub fn builder() -> HttpClientTransportBuilder
pub fn builder() -> HttpClientTransportBuilder
Create a new builder for HttpClientTransport
Trait Implementations§
Source§impl Debug for HttpClientTransport
impl Debug for HttpClientTransport
Source§impl Transport for HttpClientTransport
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
fn close<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Source§fn connection_info(&self) -> String
fn connection_info(&self) -> String
Auto Trait Implementations§
impl !RefUnwindSafe for HttpClientTransport
impl !UnwindSafe for HttpClientTransport
impl Freeze for HttpClientTransport
impl Send for HttpClientTransport
impl Sync for HttpClientTransport
impl Unpin for HttpClientTransport
impl UnsafeUnpin for HttpClientTransport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].