1use clap::{Args, Parser, Subcommand, ValueEnum};
4use serde::{Deserialize, Serialize};
5use std::path::PathBuf;
6
7#[derive(Parser, Debug)]
9#[command(
10 name = "turbomcp-cli",
11 version,
12 about = "Comprehensive CLI for MCP servers - complete protocol support with rich UX",
13 long_about = "TurboMCP CLI provides comprehensive access to MCP (Model Context Protocol) servers.\n\
14 Supports all MCP operations: tools, resources, prompts, completions, sampling, and more.\n\
15 Multiple transports: stdio, HTTP SSE, WebSocket, TCP, Unix sockets."
16)]
17pub struct Cli {
18 #[command(subcommand)]
20 pub command: Commands,
21
22 #[arg(long, short = 'f', global = true, value_enum, default_value = "human")]
24 pub format: OutputFormat,
25
26 #[arg(long, short = 'v', global = true)]
28 pub verbose: bool,
29
30 #[arg(long, short = 'c', global = true)]
32 pub connection: Option<String>,
33
34 #[arg(long, global = true)]
36 pub no_color: bool,
37}
38
39#[derive(Subcommand, Debug)]
41pub enum Commands {
42 #[command(subcommand)]
44 Tools(ToolCommands),
45
46 #[command(subcommand)]
48 Resources(ResourceCommands),
49
50 #[command(subcommand)]
52 Prompts(PromptCommands),
53
54 #[command(subcommand)]
56 Complete(CompletionCommands),
57
58 #[command(subcommand)]
60 Server(ServerCommands),
61
62 #[command(subcommand)]
64 Sample(SamplingCommands),
65
66 Connect(Connection),
68
69 Status(Connection),
71}
72
73#[derive(Subcommand, Debug)]
75pub enum ToolCommands {
76 List {
78 #[command(flatten)]
79 conn: Connection,
80 },
81
82 Call {
84 #[command(flatten)]
85 conn: Connection,
86
87 name: String,
89
90 #[arg(long, short = 'a', default_value = "{}")]
92 arguments: String,
93 },
94
95 Schema {
97 #[command(flatten)]
98 conn: Connection,
99
100 name: Option<String>,
102 },
103
104 Export {
106 #[command(flatten)]
107 conn: Connection,
108
109 #[arg(long, short = 'o')]
111 output: PathBuf,
112 },
113}
114
115#[derive(Subcommand, Debug)]
117pub enum ResourceCommands {
118 List {
120 #[command(flatten)]
121 conn: Connection,
122 },
123
124 Read {
126 #[command(flatten)]
127 conn: Connection,
128
129 uri: String,
131 },
132
133 Templates {
135 #[command(flatten)]
136 conn: Connection,
137 },
138
139 Subscribe {
141 #[command(flatten)]
142 conn: Connection,
143
144 uri: String,
146 },
147
148 Unsubscribe {
150 #[command(flatten)]
151 conn: Connection,
152
153 uri: String,
155 },
156}
157
158#[derive(Subcommand, Debug)]
160pub enum PromptCommands {
161 List {
163 #[command(flatten)]
164 conn: Connection,
165 },
166
167 Get {
169 #[command(flatten)]
170 conn: Connection,
171
172 name: String,
174
175 #[arg(long, short = 'a', default_value = "{}")]
177 arguments: String,
178 },
179
180 Schema {
182 #[command(flatten)]
183 conn: Connection,
184
185 name: String,
187 },
188}
189
190#[derive(Subcommand, Debug)]
192pub enum CompletionCommands {
193 Get {
195 #[command(flatten)]
196 conn: Connection,
197
198 #[arg(value_enum)]
200 ref_type: RefType,
201
202 ref_value: String,
204
205 #[arg(long)]
207 argument: Option<String>,
208 },
209}
210
211#[derive(Subcommand, Debug)]
213pub enum ServerCommands {
214 Info {
216 #[command(flatten)]
217 conn: Connection,
218 },
219
220 Ping {
222 #[command(flatten)]
223 conn: Connection,
224 },
225
226 LogLevel {
228 #[command(flatten)]
229 conn: Connection,
230
231 #[arg(value_enum)]
233 level: LogLevel,
234 },
235
236 Roots {
238 #[command(flatten)]
239 conn: Connection,
240 },
241}
242
243#[derive(Subcommand, Debug)]
245pub enum SamplingCommands {
246 Create {
248 #[command(flatten)]
249 conn: Connection,
250
251 messages: String,
253
254 #[arg(long)]
256 model_preferences: Option<String>,
257
258 #[arg(long)]
260 system_prompt: Option<String>,
261
262 #[arg(long)]
264 max_tokens: Option<u32>,
265 },
266}
267
268#[derive(Args, Debug, Clone, Serialize, Deserialize)]
270pub struct Connection {
271 #[arg(long, value_enum)]
273 pub transport: Option<TransportKind>,
274
275 #[arg(long, env = "MCP_URL", default_value = "http://localhost:8080/mcp")]
277 pub url: String,
278
279 #[arg(long, env = "MCP_COMMAND")]
281 pub command: Option<String>,
282
283 #[arg(long, env = "MCP_AUTH")]
285 pub auth: Option<String>,
286
287 #[arg(long, default_value = "30")]
289 pub timeout: u64,
290}
291
292#[derive(Debug, Clone, ValueEnum, PartialEq, Eq, Serialize, Deserialize)]
294#[serde(rename_all = "lowercase")]
295pub enum TransportKind {
296 Stdio,
298 Http,
300 Ws,
302 Tcp,
304 Unix,
306}
307
308#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
310pub enum OutputFormat {
311 Human,
313 Json,
315 Yaml,
317 Table,
319 Compact,
321}
322
323#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
325pub enum RefType {
326 Prompt,
328 Resource,
330}
331
332#[derive(Debug, Clone, ValueEnum, PartialEq, Eq)]
334pub enum LogLevel {
335 Debug,
336 Info,
337 Warning,
338 Error,
339}
340
341impl From<LogLevel> for turbomcp_protocol::types::LogLevel {
342 fn from(level: LogLevel) -> Self {
343 match level {
344 LogLevel::Debug => turbomcp_protocol::types::LogLevel::Debug,
345 LogLevel::Info => turbomcp_protocol::types::LogLevel::Info,
346 LogLevel::Warning => turbomcp_protocol::types::LogLevel::Warning,
347 LogLevel::Error => turbomcp_protocol::types::LogLevel::Error,
348 }
349 }
350}