#[non_exhaustive]pub struct StreamableHttpServerConfig {
pub sse_keep_alive: Option<Duration>,
pub sse_retry: Option<Duration>,
pub stateful_mode: bool,
pub json_response: bool,
pub cancellation_token: CancellationToken,
pub allowed_hosts: Vec<String>,
pub session_store: Option<Arc<dyn SessionStore>>,
}Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.sse_keep_alive: Option<Duration>The ping message duration for SSE connections.
sse_retry: Option<Duration>The retry interval for SSE priming events.
stateful_mode: boolIf true, the server will create a session for each request and keep it alive. When enabled, SSE priming events are sent to enable client reconnection.
json_response: boolWhen true and stateful_mode is false, the server returns
Content-Type: application/json directly instead of text/event-stream.
This eliminates SSE framing overhead for simple request-response tools,
allowed by the MCP Streamable HTTP spec (2025-06-18).
cancellation_token: CancellationTokenCancellation token for the Streamable HTTP server.
When this token is cancelled, all active sessions are terminated and the server stops accepting new requests.
allowed_hosts: Vec<String>Allowed hostnames or host:port authorities for inbound Host validation.
By default, Streamable HTTP servers only accept loopback hosts to prevent DNS rebinding attacks against locally running servers. Public deployments should override this list with their own hostnames. examples: allowed_hosts = [“localhost”, “127.0.0.1”, “0.0.0.0”] or with ports: allowed_hosts = [“example.com”, “example.com:8080”]
session_store: Option<Arc<dyn SessionStore>>Optional external session store for cross-instance recovery.
When set, SessionState (the client’s initialize parameters) is
persisted after a successful handshake and deleted when the session
closes. On any subsequent request that arrives at an instance with no
in-memory session, the store is consulted: if an entry is found the
session is transparently restored so the client does not need to
re-initialize.
§Example
use std::sync::Arc;
use rmcp::transport::streamable_http_server::{
StreamableHttpServerConfig, session::SessionStore,
};
let config = StreamableHttpServerConfig {
session_store: Some(Arc::new(MyRedisStore::new())),
..Default::default()
};Implementations§
Source§impl StreamableHttpServerConfig
impl StreamableHttpServerConfig
pub fn with_allowed_hosts( self, allowed_hosts: impl IntoIterator<Item = impl Into<String>>, ) -> StreamableHttpServerConfig
Sourcepub fn disable_allowed_hosts(self) -> StreamableHttpServerConfig
pub fn disable_allowed_hosts(self) -> StreamableHttpServerConfig
Disable allowed hosts. This will allow requests with any Host header, which is NOT recommended for public deployments.
pub fn with_sse_keep_alive( self, duration: Option<Duration>, ) -> StreamableHttpServerConfig
pub fn with_sse_retry( self, duration: Option<Duration>, ) -> StreamableHttpServerConfig
pub fn with_stateful_mode(self, stateful: bool) -> StreamableHttpServerConfig
pub fn with_json_response( self, json_response: bool, ) -> StreamableHttpServerConfig
pub fn with_cancellation_token( self, token: CancellationToken, ) -> StreamableHttpServerConfig
Trait Implementations§
Source§impl Clone for StreamableHttpServerConfig
impl Clone for StreamableHttpServerConfig
Source§fn clone(&self) -> StreamableHttpServerConfig
fn clone(&self) -> StreamableHttpServerConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StreamableHttpServerConfig
impl Debug for StreamableHttpServerConfig
Source§impl Default for StreamableHttpServerConfig
impl Default for StreamableHttpServerConfig
Source§fn default() -> StreamableHttpServerConfig
fn default() -> StreamableHttpServerConfig
Auto Trait Implementations§
impl Freeze for StreamableHttpServerConfig
impl !RefUnwindSafe for StreamableHttpServerConfig
impl Send for StreamableHttpServerConfig
impl Sync for StreamableHttpServerConfig
impl Unpin for StreamableHttpServerConfig
impl UnsafeUnpin for StreamableHttpServerConfig
impl !UnwindSafe for StreamableHttpServerConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more