use crate::{
mcp_client::client_runtime_core::ClientCoreInternalHandler, schema::*, McpClientHandler,
ToMcpClientHandlerCore,
};
use async_trait::async_trait;
use crate::mcp_traits::McpClient;
#[async_trait]
pub trait ClientHandlerCore: Send + Sync + 'static {
async fn handle_request(
&self,
request: ServerJsonrpcRequest,
runtime: &dyn McpClient,
) -> std::result::Result<ResultFromClient, RpcError>;
async fn handle_notification(
&self,
notification: NotificationFromServer,
runtime: &dyn McpClient,
) -> std::result::Result<(), RpcError>;
async fn handle_error(
&self,
error: &RpcError,
runtime: &dyn McpClient,
) -> std::result::Result<(), RpcError>;
async fn handle_process_error(
&self,
error_message: String,
runtime: &dyn McpClient,
) -> std::result::Result<(), RpcError> {
if !runtime.is_shut_down().await {
tracing::error!("Process error: {error_message}");
}
Ok(())
}
}
impl<T: ClientHandlerCore + 'static> ToMcpClientHandlerCore for T {
fn to_mcp_client_handler(self) -> Box<dyn McpClientHandler + 'static> {
Box::new(ClientCoreInternalHandler::new(Box::new(self)))
}
}