lean_ctx_server/server/
notifications.rs1use rmcp::model::{
3 Notification, NotificationNoParam, ResourceUpdatedNotificationParam, ServerNotification,
4 ToolListChangedNotificationMethod,
5};
6use rmcp::service::{Peer, RoleServer};
7
8pub async fn send_resource_updated(peer: &Peer<RoleServer>, uri: &str) {
9 let notif = Notification::new(ResourceUpdatedNotificationParam::new(uri));
10 let server_notif = ServerNotification::ResourceUpdatedNotification(notif);
11 if let Err(e) = peer.send_notification(server_notif).await {
12 tracing::debug!("Failed to send resource updated notification: {e}");
13 }
14}
15
16pub async fn send_tools_list_changed(peer: &Peer<RoleServer>) {
17 let notif = NotificationNoParam {
18 method: ToolListChangedNotificationMethod,
19 extensions: rmcp::model::Extensions::default(),
20 };
21 let server_notif = ServerNotification::ToolListChangedNotification(notif);
22 if let Err(e) = peer.send_notification(server_notif).await {
23 tracing::debug!("Failed to send tools list changed notification: {e}");
24 }
25}
26
27pub const RESOURCE_URI_SUMMARY: &str = "lean-ctx://context/summary";
28pub const RESOURCE_URI_PRESSURE: &str = "lean-ctx://context/pressure";
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn notification_types_construct_correctly() {
36 let notif = Notification::new(ResourceUpdatedNotificationParam::new(RESOURCE_URI_SUMMARY));
37 let sn = ServerNotification::ResourceUpdatedNotification(notif);
38 assert!(matches!(
39 sn,
40 ServerNotification::ResourceUpdatedNotification(_)
41 ));
42
43 let notif = NotificationNoParam {
44 method: ToolListChangedNotificationMethod,
45 extensions: rmcp::model::Extensions::default(),
46 };
47 let sn = ServerNotification::ToolListChangedNotification(notif);
48 assert!(matches!(
49 sn,
50 ServerNotification::ToolListChangedNotification(_)
51 ));
52 }
53}