1use tea_mcp::{McpManager, McpServerHealth, McpServerId};
2use tea_protocol::ProtocolTimestamp;
3use tea_tools::ToolName;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct McpCatalogEntry {
11 server_id: McpServerId,
12 tool_name: ToolName,
13}
14
15impl McpCatalogEntry {
16 pub(crate) fn new(server_id: McpServerId, tool_name: ToolName) -> Self {
17 Self {
18 server_id,
19 tool_name,
20 }
21 }
22
23 #[must_use]
25 pub const fn server_id(&self) -> &McpServerId {
26 &self.server_id
27 }
28
29 #[must_use]
31 pub const fn tool_name(&self) -> &ToolName {
32 &self.tool_name
33 }
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, Default)]
38pub struct McpServiceSnapshot {
39 servers: Vec<McpServerHealth>,
40 catalog: Vec<McpCatalogEntry>,
41}
42
43impl McpServiceSnapshot {
44 pub(crate) fn new(servers: Vec<McpServerHealth>, catalog: Vec<McpCatalogEntry>) -> Self {
45 Self { servers, catalog }
46 }
47
48 #[must_use]
50 pub fn servers(&self) -> &[McpServerHealth] {
51 &self.servers
52 }
53
54 #[must_use]
56 pub fn catalog(&self) -> &[McpCatalogEntry] {
57 &self.catalog
58 }
59}
60
61pub(crate) fn snapshot(
62 manager: Option<&McpManager>,
63 observed_at: ProtocolTimestamp,
64) -> Result<McpServiceSnapshot, tea_mcp::McpError> {
65 let Some(manager) = manager else {
66 return Ok(McpServiceSnapshot::default());
67 };
68 let servers = manager.health(observed_at)?;
69 let catalog = manager
70 .catalog()
71 .bindings()
72 .map(|binding| {
73 McpCatalogEntry::new(binding.server_id().clone(), binding.spec().name().clone())
74 })
75 .collect();
76 Ok(McpServiceSnapshot::new(servers, catalog))
77}