McpNotification

Trait McpNotification 

Source
pub trait McpNotification:
    NotificationDefinition
    + Send
    + Sync {
    // Required method
    fn send<'life0, 'async_trait>(
        &'life0 self,
        payload: Value,
    ) -> Pin<Box<dyn Future<Output = McpResult<DeliveryResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn can_send(&self, method: &str) -> bool { ... }
    fn priority(&self) -> u32 { ... }
    fn validate_payload<'life0, 'life1, 'async_trait>(
        &'life0 self,
        payload: &'life1 Value,
    ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn transform_payload<'life0, 'async_trait>(
        &'life0 self,
        payload: Value,
    ) -> Pin<Box<dyn Future<Output = McpResult<Value>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn handle_error<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _error: &'life1 McpError,
        attempt: u32,
    ) -> Pin<Box<dyn Future<Output = McpResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn batch_send<'life0, 'async_trait>(
        &'life0 self,
        payloads: Vec<Value>,
    ) -> Pin<Box<dyn Future<Output = McpResult<Vec<DeliveryResult>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_acknowledged<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _delivery_result: &'life1 DeliveryResult,
    ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn check_status<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _notification_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = McpResult<DeliveryStatus>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

High-level trait for implementing MCP notifications

McpNotification extends NotificationDefinition with execution capabilities. All metadata is provided by the NotificationDefinition trait, ensuring consistency between concrete Notification structs and dynamic implementations.

Required Methods§

Source

fn send<'life0, 'async_trait>( &'life0 self, payload: Value, ) -> Pin<Box<dyn Future<Output = McpResult<DeliveryResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a notification (per MCP spec)

This method processes and delivers notifications to clients, handling serialization, transport, and error recovery.

Provided Methods§

Source

fn can_send(&self, method: &str) -> bool

Optional: Check if this notification handler can send the given notification

This allows for conditional notification handling based on method type, payload content, or transport availability.

Source

fn priority(&self) -> u32

Optional: Get notification handler priority

Higher priority handlers are tried first when multiple handlers can send the same notification type.

Source

fn validate_payload<'life0, 'life1, 'async_trait>( &'life0 self, payload: &'life1 Value, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Optional: Validate the notification payload

This method can perform validation of notification data before sending.

Source

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

Optional: Transform payload before sending

This allows for data enrichment, filtering, or formatting before the notification is transmitted.

Source

fn handle_error<'life0, 'life1, 'async_trait>( &'life0 self, _error: &'life1 McpError, attempt: u32, ) -> Pin<Box<dyn Future<Output = McpResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Optional: Handle notification delivery errors

This method is called when notification delivery fails, allowing for retry logic, fallback notifications, or error logging.

Source

fn batch_send<'life0, 'async_trait>( &'life0 self, payloads: Vec<Value>, ) -> Pin<Box<dyn Future<Output = McpResult<Vec<DeliveryResult>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Optional: Batch multiple notifications

This method can be used to optimize notification delivery by batching multiple notifications together when supported.

Source

fn on_acknowledged<'life0, 'life1, 'async_trait>( &'life0 self, _delivery_result: &'life1 DeliveryResult, ) -> Pin<Box<dyn Future<Output = McpResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Optional: Subscribe to notification acknowledgments

This method can be used to track which notifications have been successfully received and processed by clients.

Source

fn check_status<'life0, 'life1, 'async_trait>( &'life0 self, _notification_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = McpResult<DeliveryStatus>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Optional: Check delivery status

This method allows querying the current delivery status of notifications.

Implementors§