(
&self,
name: String,
url: String,
headers: Option<HashMap<String, String>>,
timeout_ms: Option<u64>,
)
| 789 | } |
| 790 | |
| 791 | pub async fn add_sse( |
| 792 | &self, |
| 793 | name: String, |
| 794 | url: String, |
| 795 | headers: Option<HashMap<String, String>>, |
| 796 | timeout_ms: Option<u64>, |
| 797 | ) -> Result<Arc<McpClient>, McpClientError> { |
| 798 | self.connection_configs.write().await.insert( |
| 799 | name.clone(), |
| 800 | RegistryConnectionConfig::Sse { |
| 801 | url: url.clone(), |
| 802 | headers: headers.clone(), |
| 803 | timeout_ms, |
| 804 | }, |
| 805 | ); |
| 806 | self.log_event(&name, "Connecting via sse").await; |
| 807 | |
| 808 | let mut client_impl = McpClient::new(name.clone(), self.tool_registry.clone()); |
| 809 | if let Some(t) = timeout_ms { |
| 810 | client_impl = client_impl.with_timeout(t); |
| 811 | } |
| 812 | if let Some(bus) = &self.bus { |
| 813 | client_impl = client_impl.with_bus(bus.clone()); |
| 814 | } |
| 815 | let client = Arc::new(client_impl); |
| 816 | |
| 817 | match client.connect_sse(url, headers).await { |
| 818 | Ok(()) => { |
| 819 | self.set_status(&name, McpStatus::Connected).await; |
| 820 | self.clients.write().await.insert(name, client.clone()); |
| 821 | self.log_event(client.server_name(), "Connected").await; |
| 822 | Ok(client) |
| 823 | } |
| 824 | Err(e) => { |
| 825 | let status = client.status().await; |
| 826 | self.set_status(&name, status).await; |
| 827 | self.log_event(&name, format!("Connect failed: {}", e)) |
| 828 | .await; |
| 829 | Err(e) |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | /// Backwards-compatible alias for `add_stdio`. |
| 835 | pub async fn add_client( |
no test coverage detected