Skip to main content

McpHttpServer

Trait McpHttpServer 

Source
pub trait McpHttpServer: Send + Sync {
    // Required methods
    fn graceful_shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn sessions<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Vec<SessionId>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn runtime_by_session<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 SessionId,
    ) -> Pin<Box<dyn Future<Output = SdkResult<Arc<ServerRuntime>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Common interface for running MCP servers over HTTP transports.

Implemented by framework-specific runtimes (e.g. AxumRuntime in rust-mcp-axum, ActixRuntime in rust-mcp-actix) to provide a uniform API for:

  • Graceful shutdown
  • Session enumeration
  • Per-session runtime access

Users coding against dyn McpHttpServer can swap HTTP frameworks without changing their runtime interaction code.

Required Methods§

Source

fn graceful_shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gracefully shuts down the server, waiting for in-flight requests to complete.

Source

fn sessions<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Vec<SessionId>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns all active session IDs on this server.

Source

fn runtime_by_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = SdkResult<Arc<ServerRuntime>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns the runtime for a given session ID.

Returns an error if the session does not exist or has been closed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§