pub struct NotificationSender { /* private fields */ }Expand description
A sender for pushing notifications to the client.
This is a cloneable handle that can be passed to handlers and background tasks. Notifications are sent through a channel and delivered to the client via the transport.
§Example
use mcp_kit::server::NotificationSender;
async fn background_task(notifier: NotificationSender) {
// Notify client that a resource changed
notifier.resource_updated("file:///data.json").await;
// Send a log message
notifier.log_info("data", "File updated successfully").await;
}Implementations§
Source§impl NotificationSender
impl NotificationSender
Sourcepub fn new(tx: Sender<JsonRpcNotification>) -> Self
pub fn new(tx: Sender<JsonRpcNotification>) -> Self
Create a new notification sender with the given channel.
Sourcepub fn channel(buffer: usize) -> (Self, NotificationReceiver)
pub fn channel(buffer: usize) -> (Self, NotificationReceiver)
Create a sender/receiver pair with the specified buffer size.
Sourcepub async fn send(
&self,
notification: JsonRpcNotification,
) -> Result<(), SendError>
pub async fn send( &self, notification: JsonRpcNotification, ) -> Result<(), SendError>
Send a raw notification.
Sourcepub async fn notify<T: Serialize>(
&self,
method: &str,
params: T,
) -> Result<(), SendError>
pub async fn notify<T: Serialize>( &self, method: &str, params: T, ) -> Result<(), SendError>
Send a notification with the given method and params.
Sourcepub async fn resource_updated(
&self,
uri: impl Into<String>,
) -> Result<(), SendError>
pub async fn resource_updated( &self, uri: impl Into<String>, ) -> Result<(), SendError>
Notify the client that a resource’s content has changed.
The client may re-read the resource if it has subscribed to it.
Sourcepub async fn resources_list_changed(&self) -> Result<(), SendError>
pub async fn resources_list_changed(&self) -> Result<(), SendError>
Notify the client that the list of available resources has changed.
The client should re-fetch the resource list with resources/list.
Sourcepub async fn tools_list_changed(&self) -> Result<(), SendError>
pub async fn tools_list_changed(&self) -> Result<(), SendError>
Notify the client that the list of available tools has changed.
The client should re-fetch the tool list with tools/list.
Sourcepub async fn prompts_list_changed(&self) -> Result<(), SendError>
pub async fn prompts_list_changed(&self) -> Result<(), SendError>
Notify the client that the list of available prompts has changed.
The client should re-fetch the prompt list with prompts/list.
Sourcepub async fn log(
&self,
level: LoggingLevel,
logger: Option<String>,
data: impl Serialize,
) -> Result<(), SendError>
pub async fn log( &self, level: LoggingLevel, logger: Option<String>, data: impl Serialize, ) -> Result<(), SendError>
Send a log message notification to the client.
Sourcepub async fn log_debug(
&self,
logger: impl Into<String>,
message: impl Into<String>,
) -> Result<(), SendError>
pub async fn log_debug( &self, logger: impl Into<String>, message: impl Into<String>, ) -> Result<(), SendError>
Send a debug log message.
Sourcepub async fn log_info(
&self,
logger: impl Into<String>,
message: impl Into<String>,
) -> Result<(), SendError>
pub async fn log_info( &self, logger: impl Into<String>, message: impl Into<String>, ) -> Result<(), SendError>
Send an info log message.
Sourcepub async fn log_warning(
&self,
logger: impl Into<String>,
message: impl Into<String>,
) -> Result<(), SendError>
pub async fn log_warning( &self, logger: impl Into<String>, message: impl Into<String>, ) -> Result<(), SendError>
Send a warning log message.
Sourcepub async fn log_error(
&self,
logger: impl Into<String>,
message: impl Into<String>,
) -> Result<(), SendError>
pub async fn log_error( &self, logger: impl Into<String>, message: impl Into<String>, ) -> Result<(), SendError>
Send an error log message.
Sourcepub async fn progress(
&self,
progress_token: impl Into<ProgressToken>,
progress: f64,
total: Option<f64>,
message: Option<String>,
) -> Result<(), SendError>
pub async fn progress( &self, progress_token: impl Into<ProgressToken>, progress: f64, total: Option<f64>, message: Option<String>, ) -> Result<(), SendError>
Send a progress update for a long-running operation.
The progress_token should match the token provided in the original request.
Progress values are typically 0.0 to 1.0, or absolute values when total is provided.
Trait Implementations§
Source§impl Clone for NotificationSender
impl Clone for NotificationSender
Source§fn clone(&self) -> NotificationSender
fn clone(&self) -> NotificationSender
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more