pub struct HttpClientConfig {
pub headers: HashMap<String, String>,
pub auto_sse: bool,
pub channel_capacity: usize,
pub request_timeout: Duration,
pub notification_timeout: Duration,
pub sse_reconnect: bool,
pub sse_reconnect_delay: Duration,
pub max_sse_reconnect_attempts: u32,
pub session_recovery: bool,
pub max_sse_event_size: usize,
}Expand description
Configuration for HttpClientTransport.
§Example
use tower_mcp::client::{HttpClientTransport, HttpClientConfig};
use std::time::Duration;
let config = HttpClientConfig {
request_timeout: Duration::from_secs(60),
..Default::default()
};
let transport = HttpClientTransport::with_config("http://localhost:3000", config);Fields§
§headers: HashMap<String, String>Custom headers to include on every request (e.g., auth tokens).
auto_sse: boolWhether to automatically open the standalone SSE notification stream
after initialization. Associated POST response streams used for
sampling, elicitation, and roots requests work independently.
Default: true.
channel_capacity: usizeCapacity of the internal message channel. Default: 256.
request_timeout: DurationTimeout for HTTP requests. Default: 30 seconds.
notification_timeout: DurationTimeout for notification POSTs (frames without an id), capped at
request_timeout.
Notifications are awaited inline so notifications/initialized is
ordered ahead of the first request, which blocks the client’s message
loop for the duration. This bounds that block independently of
request_timeout so a server that stalls a notification’s 202 cannot
freeze the client for the full request timeout.
Default: 5 seconds.
sse_reconnect: boolWhether to attempt SSE reconnection on disconnect.
Default: true.
sse_reconnect_delay: DurationDelay before SSE reconnection attempts. Default: 1 second.
max_sse_reconnect_attempts: u32Maximum SSE reconnection attempts before giving up. Default: 5.
session_recovery: boolWhether to support automatic session recovery on expiry.
When enabled, HTTP 404 responses (with a session ID attached) and
JSON-RPC -32005 errors trigger re-initialization.
Default: true.
max_sse_event_size: usizeMaximum size in bytes buffered for a single SSE event.
A server that streams an event without ever terminating it would
otherwise grow the parse buffer without bound. When a single
event’s buffered size exceeds this cap, the stream is terminated
with Error::SseEventTooLarge.
Default: 16 MiB (matching rmcp).
Implementations§
Source§impl HttpClientConfig
impl HttpClientConfig
Sourcepub fn bearer_token(self, token: impl Into<String>) -> Self
pub fn bearer_token(self, token: impl Into<String>) -> Self
Set a Bearer token for authentication.
Sourcepub fn api_key_header(
self,
name: impl Into<String>,
key: impl Into<String>,
) -> Self
pub fn api_key_header( self, name: impl Into<String>, key: impl Into<String>, ) -> Self
Set an API key using a custom header name.
Trait Implementations§
Source§impl Clone for HttpClientConfig
impl Clone for HttpClientConfig
Source§fn clone(&self) -> HttpClientConfig
fn clone(&self) -> HttpClientConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more