Skip to main content

do_memory_mcp/server/tools/
management.rs

1// Tool management handlers
2//!
3//! This module contains tool management functions: add_tool, remove_tool, get_stats, and tracking.
4
5use 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    /// Get execution statistics
14    pub async fn get_stats(&self) -> ExecutionStats {
15        self.stats.read().clone()
16    }
17
18    /// Get tool usage statistics
19    pub async fn get_tool_usage(&self) -> HashMap<String, usize> {
20        self.tool_usage.read().clone()
21    }
22
23    /// Track usage of a tool (for progressive disclosure)
24    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    /// Add a custom tool to the server
30    pub async fn add_tool(&self, tool: Tool) -> Result<()> {
31        self.tool_registry.add_tool(tool)
32    }
33
34    /// Remove a tool from the server
35    pub async fn remove_tool(&self, tool_name: &str) -> Result<()> {
36        self.tool_registry.remove_tool(tool_name)
37    }
38
39    /// Get monitoring endpoints
40    pub fn monitoring_endpoints(&self) -> Arc<MonitoringEndpoints> {
41        Arc::clone(&self.monitoring_endpoints)
42    }
43
44    /// Get monitoring system
45    pub fn monitoring_system(&self) -> Arc<MonitoringSystem> {
46        Arc::clone(&self.monitoring)
47    }
48
49    /// Update system metrics (memory, CPU)
50    pub async fn update_system_metrics(&self) {
51        if !self.monitoring.config().enabled {
52            return;
53        }
54
55        // Get basic system metrics (simplified for now)
56        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}