Skip to main content

StreamableHttpServiceBuilder

Struct StreamableHttpServiceBuilder 

Source
pub struct StreamableHttpServiceBuilder<S, M = LocalSessionManager, State: State = Empty> { /* private fields */ }
Expand description

Use builder syntax to set the inputs and finish with build().

Implementations§

Source§

impl<S, M, State: State> StreamableHttpServiceBuilder<S, M, State>

Source

pub fn build(self) -> StreamableHttpService<S, M>
where State: IsComplete,

Finish building and return the requested object

Source

pub fn service_factory( self, value: Arc<dyn Fn() -> Result<S, Error> + Send + Sync>, ) -> StreamableHttpServiceBuilder<S, M, SetServiceFactory<State>>
where State::ServiceFactory: IsUnset,

Required.

The service factory function that creates new MCP service instances

Source

pub fn session_manager( self, value: Arc<M>, ) -> StreamableHttpServiceBuilder<S, M, SetSessionManager<State>>
where State::SessionManager: IsUnset,

Required.

The session manager for tracking client connections

Source

pub fn stateful_mode( self, value: bool, ) -> StreamableHttpServiceBuilder<S, M, SetStatefulMode<State>>
where State::StatefulMode: IsUnset,

Optional (Some / Option setters). Default: true.

Whether to enable stateful session management

Source

pub fn maybe_stateful_mode( self, value: Option<bool>, ) -> StreamableHttpServiceBuilder<S, M, SetStatefulMode<State>>
where State::StatefulMode: IsUnset,

Optional (Some / Option setters). Default: true.

Whether to enable stateful session management

Source

pub fn sse_keep_alive( self, value: Duration, ) -> StreamableHttpServiceBuilder<S, M, SetSseKeepAlive<State>>
where State::SseKeepAlive: IsUnset,

Optional (Some / Option setters). Optional keep-alive interval for SSE connections

Source

pub fn maybe_sse_keep_alive( self, value: Option<Duration>, ) -> StreamableHttpServiceBuilder<S, M, SetSseKeepAlive<State>>
where State::SseKeepAlive: IsUnset,

Optional (Some / Option setters). Optional keep-alive interval for SSE connections

Source

pub fn on_request( self, value: Arc<OnRequestHook>, ) -> StreamableHttpServiceBuilder<S, M, SetOnRequest<State>>
where State::OnRequest: IsUnset,

Optional (Some / Option setters). Optional hook called for each request to propagate extensions from HttpRequest to RequestContext.

This allows middleware-populated data (e.g., JWT claims) to be accessed in MCP handlers.

§Example
use std::sync::Arc;
use actix_web::HttpMessage;

StreamableHttpService::builder()
    .on_request(Arc::new(|http_req, ext| {
        if let Some(claims) = http_req.extensions().get::<MyClaims>() {
            ext.insert(claims.clone());
        }
    }))
    .build()
Source

pub fn maybe_on_request( self, value: Option<Arc<OnRequestHook>>, ) -> StreamableHttpServiceBuilder<S, M, SetOnRequest<State>>
where State::OnRequest: IsUnset,

Optional (Some / Option setters). Optional hook called for each request to propagate extensions from HttpRequest to RequestContext.

This allows middleware-populated data (e.g., JWT claims) to be accessed in MCP handlers.

§Example
use std::sync::Arc;
use actix_web::HttpMessage;

StreamableHttpService::builder()
    .on_request(Arc::new(|http_req, ext| {
        if let Some(claims) = http_req.extensions().get::<MyClaims>() {
            ext.insert(claims.clone());
        }
    }))
    .build()
Source§

impl<S, M, State: State> StreamableHttpServiceBuilder<S, M, State>
where State::OnRequest: IsUnset,

Source

pub fn on_request_fn( self, hook: impl Fn(&HttpRequest, &mut Extensions) + Send + Sync + 'static, ) -> StreamableHttpServiceBuilder<S, M, SetOnRequest<State>>

Sets the on_request hook using a closure.

This is a convenience method that automatically wraps the closure in an Arc, making it easier to use without manual Arc wrapping.

§Example
use actix_web::HttpMessage;

StreamableHttpService::builder()
    .on_request_fn(|http_req, ext| {
        if let Some(claims) = http_req.extensions().get::<MyClaims>() {
            ext.insert(claims.clone());
        }
    })
    .build()

Auto Trait Implementations§

§

impl<S, M = LocalSessionManager, State = Empty> !RefUnwindSafe for StreamableHttpServiceBuilder<S, M, State>

§

impl<S, M = LocalSessionManager, State = Empty> !UnwindSafe for StreamableHttpServiceBuilder<S, M, State>

§

impl<S, M, State> Freeze for StreamableHttpServiceBuilder<S, M, State>

§

impl<S, M, State> Send for StreamableHttpServiceBuilder<S, M, State>
where M: Sync + Send,

§

impl<S, M, State> Sync for StreamableHttpServiceBuilder<S, M, State>
where M: Sync + Send,

§

impl<S, M, State> Unpin for StreamableHttpServiceBuilder<S, M, State>

§

impl<S, M, State> UnsafeUnpin for StreamableHttpServiceBuilder<S, M, State>

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