(
&self,
name: String,
url: String,
headers: Option<HashMap<String, String>>,
timeout_ms: Option<u64>,
)
| 746 | } |
| 747 | } |
| 748 | pub async fn add_http( |
| 749 | &self, |
| 750 | name: String, |
| 751 | url: String, |
| 752 | headers: Option<HashMap<String, String>>, |
| 753 | timeout_ms: Option<u64>, |
| 754 | ) -> Result<Arc<McpClient>, McpClientError> { |
| 755 | self.connection_configs.write().await.insert( |
| 756 | name.clone(), |
| 757 | RegistryConnectionConfig::Http { |
| 758 | url: url.clone(), |
| 759 | headers: headers.clone(), |
| 760 | timeout_ms, |
| 761 | }, |
| 762 | ); |
| 763 | self.log_event(&name, "Connecting via http").await; |
| 764 | |
| 765 | let mut client_impl = McpClient::new(name.clone(), self.tool_registry.clone()); |
| 766 | if let Some(t) = timeout_ms { |
| 767 | client_impl = client_impl.with_timeout(t); |
| 768 | } |
| 769 | if let Some(bus) = &self.bus { |
| 770 | client_impl = client_impl.with_bus(bus.clone()); |
| 771 | } |
| 772 | let client = Arc::new(client_impl); |
| 773 | |
| 774 | match client.connect_http(url, headers).await { |
| 775 | Ok(()) => { |
| 776 | self.set_status(&name, McpStatus::Connected).await; |
| 777 | self.clients.write().await.insert(name, client.clone()); |
| 778 | self.log_event(client.server_name(), "Connected").await; |
| 779 | Ok(client) |
| 780 | } |
| 781 | Err(e) => { |
| 782 | let status = client.status().await; |
| 783 | self.set_status(&name, status).await; |
| 784 | self.log_event(&name, format!("Connect failed: {}", e)) |
| 785 | .await; |
| 786 | Err(e) |
| 787 | } |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | pub async fn add_sse( |
| 792 | &self, |
no test coverage detected