1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6#[serde(tag = "type")]
7pub enum McpServerConfig {
8 #[serde(rename = "stdio")]
10 Stdio(McpStdioServerConfig),
11
12 #[serde(rename = "sse")]
14 Sse(McpSseServerConfig),
15
16 #[serde(rename = "http")]
18 Http(McpHttpServerConfig),
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct McpStdioServerConfig {
24 pub command: String,
25 #[serde(default)]
26 pub args: Vec<String>,
27 #[serde(default)]
28 pub env: HashMap<String, String>,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct McpSseServerConfig {
34 pub url: String,
35 #[serde(default)]
36 pub headers: HashMap<String, String>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct McpHttpServerConfig {
42 pub url: String,
43 #[serde(default)]
44 pub headers: HashMap<String, String>,
45}
46
47impl McpServerConfig {
48 pub fn stdio(command: impl Into<String>) -> Self {
50 McpServerConfig::Stdio(McpStdioServerConfig {
51 command: command.into(),
52 args: Vec::new(),
53 env: HashMap::new(),
54 })
55 }
56
57 pub fn sse(url: impl Into<String>) -> Self {
59 McpServerConfig::Sse(McpSseServerConfig {
60 url: url.into(),
61 headers: HashMap::new(),
62 })
63 }
64
65 pub fn http(url: impl Into<String>) -> Self {
67 McpServerConfig::Http(McpHttpServerConfig {
68 url: url.into(),
69 headers: HashMap::new(),
70 })
71 }
72}
73
74impl McpStdioServerConfig {
75 pub fn new(command: impl Into<String>) -> Self {
76 Self {
77 command: command.into(),
78 args: Vec::new(),
79 env: HashMap::new(),
80 }
81 }
82
83 pub fn with_args(mut self, args: Vec<String>) -> Self {
84 self.args = args;
85 self
86 }
87
88 pub fn with_env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
89 self.env.insert(key.into(), value.into());
90 self
91 }
92}
93
94impl McpSseServerConfig {
95 pub fn new(url: impl Into<String>) -> Self {
96 Self {
97 url: url.into(),
98 headers: HashMap::new(),
99 }
100 }
101
102 pub fn with_header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
103 self.headers.insert(key.into(), value.into());
104 self
105 }
106}
107
108impl McpHttpServerConfig {
109 pub fn new(url: impl Into<String>) -> Self {
110 Self {
111 url: url.into(),
112 headers: HashMap::new(),
113 }
114 }
115
116 pub fn with_header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
117 self.headers.insert(key.into(), value.into());
118 self
119 }
120}