1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::BTreeMap;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6#[serde(untagged)]
7pub enum McpServerConfig {
8 Stdio {
9 #[serde(default)]
10 r#type: Option<String>,
11 command: String,
12 #[serde(default)]
13 args: Vec<String>,
14 #[serde(default)]
15 env: BTreeMap<String, String>,
16 },
17 Sse {
18 #[serde(rename = "type")]
19 r#type: String,
20 url: String,
21 #[serde(default)]
22 headers: BTreeMap<String, String>,
23 },
24 Http {
25 #[serde(rename = "type")]
26 r#type: String,
27 url: String,
28 #[serde(default)]
29 headers: BTreeMap<String, String>,
30 },
31 Ws {
32 #[serde(rename = "type")]
33 r#type: String,
34 url: String,
35 #[serde(default)]
36 headers: BTreeMap<String, String>,
37 },
38 Sdk {
39 #[serde(rename = "type")]
40 r#type: String,
41 name: String,
42 },
43}
44
45pub fn discover_mcp_servers(settings: &Value) -> BTreeMap<String, McpServerConfig> {
46 settings
47 .get("mcpServers")
48 .and_then(|value| serde_json::from_value(value.clone()).ok())
49 .unwrap_or_default()
50}