use std::{collections::HashMap, sync::Arc}; use crate::core::downloads::models::DownloadManagerState; use rmcp::{ model::{CallToolRequestParam, CallToolResult, InitializeRequestParam, Tool}, service::RunningService, RoleClient, ServiceError, }; use tokio::sync::{Mutex, oneshot}; use tokio::task::JoinHandle; /// Server handle type for managing the proxy server lifecycle pub type ServerHandle = JoinHandle>>; pub enum RunningServiceEnum { NoInit(RunningService), WithInit(RunningService), } pub type SharedMcpServers = Arc>>; #[derive(Default)] pub struct AppState { pub app_token: Option, pub mcp_servers: SharedMcpServers, pub download_manager: Arc>, pub mcp_restart_counts: Arc>>, pub mcp_active_servers: Arc>>, pub mcp_successfully_connected: Arc>>, pub server_handle: Arc>>, pub tool_call_cancellations: Arc>>>, } impl RunningServiceEnum { pub async fn list_all_tools(&self) -> Result, ServiceError> { match self { Self::NoInit(s) => s.list_all_tools().await, Self::WithInit(s) => s.list_all_tools().await, } } pub async fn call_tool( &self, params: CallToolRequestParam, ) -> Result { match self { Self::NoInit(s) => s.call_tool(params).await, Self::WithInit(s) => s.call_tool(params).await, } } }