Trait ServerHandlerCore

Source
pub trait ServerHandlerCore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn handle_request<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: RequestFromClient,
        runtime: &'life1 dyn McpServer,
    ) -> Pin<Box<dyn Future<Output = Result<ResultFromServer, RpcError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn handle_notification<'life0, 'life1, 'async_trait>(
        &'life0 self,
        notification: NotificationFromClient,
        runtime: &'life1 dyn McpServer,
    ) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn handle_error<'life0, 'life1, 'async_trait>(
        &'life0 self,
        error: RpcError,
        runtime: &'life1 dyn McpServer,
    ) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn on_initialized<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _runtime: &'life1 dyn McpServer,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn on_server_started<'life0, 'life1, 'async_trait>(
        &'life0 self,
        runtime: &'life1 dyn McpServer,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Defines the ServerHandlerCore trait for handling Model Context Protocol (MCP) server operations. Unlike ServerHandler, this trait offers no default implementations, providing full control over MCP message handling while ensures type-safe processing of the messages through three distinct handlers for requests, notifications, and errors.

Required Methods§

Source

fn handle_request<'life0, 'life1, 'async_trait>( &'life0 self, request: RequestFromClient, runtime: &'life1 dyn McpServer, ) -> Pin<Box<dyn Future<Output = Result<ResultFromServer, RpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Asynchronously handles an incoming request from the client.

§Parameters
  • request – The request data received from the MCP client.
§Returns

A ResultFromServer, which represents the server’s response to the client’s request.

Source

fn handle_notification<'life0, 'life1, 'async_trait>( &'life0 self, notification: NotificationFromClient, runtime: &'life1 dyn McpServer, ) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Asynchronously handles an incoming notification from the client.

§Parameters
  • notification – The notification data received from the MCP client.
Source

fn handle_error<'life0, 'life1, 'async_trait>( &'life0 self, error: RpcError, runtime: &'life1 dyn McpServer, ) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Asynchronously handles an error received from the client.

§Parameters
  • error – The error data received from the MCP client.

Provided Methods§

Source

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

Invoked when the server finishes initialization and receives an initialized_notification from the client.

The runtime parameter provides access to the server’s runtime environment, allowing interaction with the server’s capabilities. The default implementation does nothing.

Source

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

Implementors§