use std::collections::{HashMap, hash_map}; use serde::{Deserialize, Serialize}; use crate::{ServerName, ToolDefinition}; /// Cache for MCP tool definitions /// /// Simplified cache structure that stores only the essential data. /// Validation and TTL checking are handled by the infrastructure layer /// using cacache's built-in metadata capabilities. #[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, derive_setters::Setters)] #[serde(rename_all = "camelCase")] #[setters(strip_option, into)] pub struct McpServers { /// Successfully loaded MCP servers with their tools servers: HashMap>, /// Failed MCP servers with their error messages #[serde(default)] failures: HashMap, } impl McpServers { /// Create a new cache entry with servers and failures pub fn new( servers: HashMap>, failures: HashMap, ) -> Self { Self { servers, failures } } /// Get the successful servers pub fn get_servers(&self) -> &HashMap> { &self.servers } /// Get the failed servers pub fn get_failures(&self) -> &HashMap { &self.failures } } impl IntoIterator for McpServers { type Item = (ServerName, Vec); type IntoIter = hash_map::IntoIter>; fn into_iter(self) -> Self::IntoIter { self.servers.into_iter() } }