| 1 | use serde_json::{Value, json}; |
| 2 | |
| 3 | use crate::McpEndpoint; |
| 4 | |
| 5 | pub(super) const SERVER_NAME: &str = "teams"; |
| 6 | |
| 7 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 8 | pub(super) struct ServerEntry { |
| 9 | pub url: String, |
| 10 | pub authorization: String, |
| 11 | } |
| 12 | |
| 13 | impl ServerEntry { |
| 14 | pub fn expected(endpoint: &McpEndpoint) -> Self { |
| 15 | ServerEntry { |
| 16 | url: endpoint.url.clone(), |
| 17 | authorization: format!("Bearer {}", endpoint.token), |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | pub fn from_json(value: &Value) -> Option<Self> { |
| 22 | Some(ServerEntry { |
| 23 | url: value.get("url")?.as_str()?.to_string(), |
| 24 | authorization: value |
| 25 | .get("headers")? |
| 26 | .get("Authorization")? |
| 27 | .as_str()? |
| 28 | .to_string(), |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | pub fn to_json(&self, with_type: bool, with_tools: bool) -> Value { |
| 33 | let mut value = json!({ |
| 34 | "url": self.url, |
| 35 | "headers": { "Authorization": self.authorization }, |
| 36 | }); |
| 37 | let object = value.as_object_mut().expect("object literal"); |
| 38 | if with_type { |
| 39 | object.insert("type".into(), json!("http")); |
| 40 | } |
| 41 | if with_tools { |
| 42 | object.insert("tools".into(), json!(["*"])); |
| 43 | } |
| 44 | value |
| 45 | } |
| 46 | } |