use super::*;
impl McpRouter {
pub fn log(&self, params: LoggingMessageParams) -> bool {
let Some(tx) = &self.inner.notification_tx else {
return false;
};
tx.try_send(ServerNotification::LogMessage(params)).is_ok()
}
pub fn log_info(&self, message: &str) -> bool {
self.log(LoggingMessageParams::new(
LogLevel::Info,
serde_json::json!({ "message": message }),
))
}
pub fn log_warning(&self, message: &str) -> bool {
self.log(LoggingMessageParams::new(
LogLevel::Warning,
serde_json::json!({ "message": message }),
))
}
pub fn log_error(&self, message: &str) -> bool {
self.log(LoggingMessageParams::new(
LogLevel::Error,
serde_json::json!({ "message": message }),
))
}
pub fn log_debug(&self, message: &str) -> bool {
self.log(LoggingMessageParams::new(
LogLevel::Debug,
serde_json::json!({ "message": message }),
))
}
pub fn is_subscribed(&self, uri: &str) -> bool {
if let Ok(subs) = self.subscriptions.read() {
return subs.contains(uri);
}
false
}
pub fn subscribed_uris(&self) -> Vec<String> {
if let Ok(subs) = self.subscriptions.read() {
return subs.iter().cloned().collect();
}
Vec::new()
}
pub(super) fn subscribe(&self, uri: &str) -> bool {
if let Ok(mut subs) = self.subscriptions.write() {
return subs.insert(uri.to_string());
}
false
}
pub(super) fn unsubscribe(&self, uri: &str) -> bool {
if let Ok(mut subs) = self.subscriptions.write() {
return subs.remove(uri);
}
false
}
pub fn notify_resource_updated(&self, uri: &str) -> bool {
let notification = ServerNotification::ResourceUpdated {
uri: uri.to_string(),
};
let mut sent = false;
if self.is_subscribed(uri)
&& let Some(tx) = &self.inner.notification_tx
{
sent |= tx.try_send(notification.clone()).is_ok();
}
#[cfg(all(feature = "http", feature = "stateless"))]
if let Ok(active) = self.inner.modern_notification_sink.read()
&& let Some(sink) = active.as_ref()
{
sent |= sink(¬ification);
}
sent
}
pub async fn notify_task_status_changed(&self, task_id: &str) {
self.notify_task_state(task_id).await;
}
pub fn notify_resources_list_changed(&self) -> bool {
let Some(tx) = &self.inner.notification_tx else {
return false;
};
tx.try_send(ServerNotification::ResourcesListChanged)
.is_ok()
}
pub fn notify_tools_list_changed(&self) -> bool {
let Some(tx) = &self.inner.notification_tx else {
return false;
};
tx.try_send(ServerNotification::ToolsListChanged).is_ok()
}
pub fn notify_prompts_list_changed(&self) -> bool {
let Some(tx) = &self.inner.notification_tx else {
return false;
};
tx.try_send(ServerNotification::PromptsListChanged).is_ok()
}
}