pub trait ServerHandlerCore:
Send
+ Sync
+ 'static {
// Required methods
fn handle_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: RequestFromClient,
context: &'life1 RequestContext,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<ServerResult, RpcError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: '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 required_capabilities_for_method(
&self,
_method: &str,
) -> Vec<RequiredClientCapability> { ... }
}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, 'life1, 'async_trait>(
&'life0 self,
request: RequestFromClient,
context: &'life1 RequestContext,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<ServerResult, RpcError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle_request<'life0, 'life1, 'async_trait>(
&'life0 self,
request: RequestFromClient,
context: &'life1 RequestContext,
runtime: Arc<dyn McpServer>,
) -> Pin<Box<dyn Future<Output = Result<ServerResult, RpcError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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 required_capabilities_for_method(
&self,
_method: &str,
) -> Vec<RequiredClientCapability>
fn required_capabilities_for_method( &self, _method: &str, ) -> Vec<RequiredClientCapability>
Returns the set of client capabilities this handler requires for
the given method. Before dispatching a request the runtime calls
this method and rejects the request with
MISSING_REQUIRED_CLIENT_CAPABILITY (-32021) when the client
did not declare every required capability.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".