Skip to content

SessionManager is fixed to LocalSessionManager for SteamableHttpService #756

@BrentGarnett

Description

@BrentGarnett

Describe the bug
SessionManager seems to be fixed to LocalSessionManager for SteamableHttpService, at least for the new function.

To Reproduce
Steps to reproduce the behavior:

    let ns = NeverSessionManager{};
    let service: StreamableHttpService<MyServerHandler> = StreamableHttpService::new(
        move || {
            Ok(MyServerHandler {})
        },
        ns.into(),//LocalSessionManager::default().into(),
        StreamableHttpServerConfig::default(),
    );

Expected behavior
It seems that new for StreamableHttpService defines an M only bound by SessionManager trait

impl<S, M> StreamableHttpService<S, M>
where
    S: crate::Service<RoleServer> + Send + 'static,
    M: SessionManager,
{
    pub fn new(
        service_factory: impl Fn() -> Result<S, std::io::Error> + Send + Sync + 'static,
        session_manager: Arc<M>,
        config: StreamableHttpServerConfig,
    ) -> Self {
        Self {
            config,
            session_manager,
            service_factory: Arc::new(service_factory),
        }
    }
...

However, the struct definition for StreamableHttpService fixes M to LocalSessionManager:

pub struct StreamableHttpService<S, M = super::session::local::LocalSessionManager> {
    pub config: StreamableHttpServerConfig,
    session_manager: Arc<M>,
    service_factory: Arc<dyn Fn() -> Result<S, std::io::Error> + Send + Sync>,
}

Effectively making new only able to accept session_manager: Arc.

I wonder if this is a bug or if this was an explicit choice to lock out StreamableHttpService until more implementations of the trait are
available. I question how the SessionManager trait is used if this is not a bug. This BTW was encountered implementing a RedisSessionManager in lieu of an SDK based one being discussed here

Logs
Error from the "To Reproduce" section:

error[E0277]: the trait bound `Arc<LocalSessionManager>: From<NeverSessionManager>` is not satisfied
   --> mcp.rs:30:12
    |
308 |         ns.into(),//LocalSessionManager::default().into(),
    |            ^^^^ unsatisfied trait bound
    |
    = help: the trait `std::convert::From<rmcp::transport::streamable_http_server::session::never::NeverSessionManager>` is not implemented for `std::sync::Arc<rmcp::transport::streamable_http_server::session::local::LocalSessionManager>`
    = help: the following other types implement trait `std::convert::From<T>`:
              `std::sync::Arc<B>` implements `std::convert::From<std::borrow::Cow<'_, B>>`
              `std::sync::Arc<T, A>` implements `std::convert::From<std::boxed::Box<T, A>>`
              `std::sync::Arc<T>` implements `std::convert::From<T>`
              `std::sync::Arc<[T], A>` implements `std::convert::From<std::vec::Vec<T, A>>`
              `std::sync::Arc<[T]>` implements `std::convert::From<&[T]>`
              `std::sync::Arc<[T]>` implements `std::convert::From<&mut [T]>`
              `std::sync::Arc<[T]>` implements `std::convert::From<[T; N]>`
              `std::sync::Arc<[u8]>` implements `std::convert::From<std::sync::Arc<std::bstr::ByteStr>>`
            and 22 others
    = note: required for `rmcp::transport::streamable_http_server::session::never::NeverSessionManager` to implement `Into<Arc<LocalSessionManager>>`
    = note: consider using `--verbose` to print the full type name to the console

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is not working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions