do_memory_mcp/server/tools/
management.rs1use crate::monitoring::MonitoringEndpoints;
6use crate::monitoring::MonitoringSystem;
7use crate::types::{ExecutionStats, Tool};
8use anyhow::Result;
9use std::collections::HashMap;
10use std::sync::Arc;
11
12impl crate::server::MemoryMCPServer {
13 pub async fn get_stats(&self) -> ExecutionStats {
15 self.stats.read().clone()
16 }
17
18 pub async fn get_tool_usage(&self) -> HashMap<String, usize> {
20 self.tool_usage.read().clone()
21 }
22
23 pub(super) async fn track_tool_usage(&self, tool_name: &str) {
25 let mut usage = self.tool_usage.write();
26 *usage.entry(tool_name.to_string()).or_insert(0) += 1;
27 }
28
29 pub async fn add_tool(&self, tool: Tool) -> Result<()> {
31 self.tool_registry.add_tool(tool)
32 }
33
34 pub async fn remove_tool(&self, tool_name: &str) -> Result<()> {
36 self.tool_registry.remove_tool(tool_name)
37 }
38
39 pub fn monitoring_endpoints(&self) -> Arc<MonitoringEndpoints> {
41 Arc::clone(&self.monitoring_endpoints)
42 }
43
44 pub fn monitoring_system(&self) -> Arc<MonitoringSystem> {
46 Arc::clone(&self.monitoring)
47 }
48
49 pub async fn update_system_metrics(&self) {
51 if !self.monitoring.config().enabled {
52 return;
53 }
54
55 let memory_mb = 50.0;
57 let cpu_percent = 5.0;
58
59 self.monitoring
60 .update_system_metrics(memory_mb, cpu_percent);
61 }
62}