pub trait ServerHandlerCore:
Send
+ Sync
+ 'static {
// Required methods
fn handle_request<'life0, 'async_trait>(
&'life0 self,
request: RequestFromClient,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<ResultFromServer, RpcError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn handle_notification<'life0, 'async_trait>(
&'life0 self,
notification: NotificationFromClient,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn handle_error<'life0, 'life1, 'async_trait>(
&'life0 self,
error: &'life1 RpcError,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn on_initialized<'life0, 'async_trait>(
&'life0 self,
_runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: '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§
Sourcefn handle_request<'life0, 'async_trait>(
&'life0 self,
request: RequestFromClient,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<ResultFromServer, RpcError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle_request<'life0, 'async_trait>(
&'life0 self,
request: RequestFromClient,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<ResultFromServer, RpcError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn handle_notification<'life0, 'async_trait>(
&'life0 self,
notification: NotificationFromClient,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle_notification<'life0, 'async_trait>(
&'life0 self,
notification: NotificationFromClient,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<(), RpcError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Asynchronously handles an incoming notification from the client.
§Parameters
notification– The notification data received from the MCP client.
Sourcefn handle_error<'life0, 'life1, 'async_trait>(
&'life0 self,
error: &'life1 RpcError,
runtime: Arc<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: &'life1 RpcError,
runtime: Arc<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§
Sourcefn on_initialized<'life0, 'async_trait>(
&'life0 self,
_runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_initialized<'life0, 'async_trait>(
&'life0 self,
_runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: '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.