| 876 | } |
| 877 | |
| 878 | pub async fn restart(&self, name: &str) -> Result<Arc<McpClient>, McpClientError> { |
| 879 | self.log_event(name, "Restart requested").await; |
| 880 | |
| 881 | let config = self |
| 882 | .connection_configs |
| 883 | .read() |
| 884 | .await |
| 885 | .get(name) |
| 886 | .cloned() |
| 887 | .ok_or_else(|| { |
| 888 | McpClientError::ProtocolError(format!("No restart config found for {}", name)) |
| 889 | })?; |
| 890 | |
| 891 | if let Some(client) = self.clients.write().await.remove(name) { |
| 892 | client.close().await?; |
| 893 | } |
| 894 | |
| 895 | match config { |
| 896 | RegistryConnectionConfig::Stdio(config) => self.add_stdio(config).await, |
| 897 | RegistryConnectionConfig::Http { |
| 898 | url, |
| 899 | headers, |
| 900 | timeout_ms, |
| 901 | } => { |
| 902 | self.add_http(name.to_string(), url, headers, timeout_ms) |
| 903 | .await |
| 904 | } |
| 905 | RegistryConnectionConfig::Sse { |
| 906 | url, |
| 907 | headers, |
| 908 | timeout_ms, |
| 909 | } => { |
| 910 | self.add_sse(name.to_string(), url, headers, timeout_ms) |
| 911 | .await |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | impl Default for McpClientRegistry { |