Skip to main content

systemprompt_cli/commands/plugins/mcp/
mod.rs

1//! MCP server management commands
2
3mod call;
4mod list;
5mod list_packages;
6mod logs;
7mod status;
8mod tools;
9pub mod types;
10mod validate;
11
12use anyhow::{Context, Result};
13use clap::Subcommand;
14
15use crate::cli_settings::get_global_config;
16use crate::shared::render_result;
17use crate::CliConfig;
18
19#[derive(Debug, Subcommand)]
20pub enum McpCommands {
21    /// List MCP server configs
22    List(list::ListArgs),
23
24    /// Show running MCP server status with binary info
25    Status(status::StatusArgs),
26
27    /// Validate MCP connection
28    Validate(validate::ValidateArgs),
29
30    /// View MCP server logs
31    Logs(logs::LogsArgs),
32
33    /// List package names for build
34    ListPackages(list_packages::ListPackagesArgs),
35
36    /// List tools from running MCP servers
37    Tools(tools::ToolsArgs),
38
39    /// Execute a tool on an MCP server
40    Call(call::CallArgs),
41}
42
43pub async fn execute(command: McpCommands) -> Result<()> {
44    let config = get_global_config();
45    execute_with_config(command, &config).await
46}
47
48pub async fn execute_with_config(command: McpCommands, config: &CliConfig) -> Result<()> {
49    match command {
50        McpCommands::List(args) => {
51            let result = list::execute(args, config).context("Failed to list MCP servers")?;
52            render_result(&result);
53            Ok(())
54        },
55        McpCommands::Status(args) => {
56            let result = status::execute(args, config)
57                .await
58                .context("Failed to get MCP server status")?;
59            render_result(&result);
60            Ok(())
61        },
62        McpCommands::Validate(args) => {
63            let result = validate::execute(args, config)
64                .await
65                .context("Failed to validate MCP server")?;
66            render_result(&result);
67            Ok(())
68        },
69        McpCommands::Logs(args) => {
70            let result = logs::execute(args, config)
71                .await
72                .context("Failed to get MCP server logs")?;
73            render_result(&result);
74            Ok(())
75        },
76        McpCommands::ListPackages(args) => {
77            let result =
78                list_packages::execute(args, config).context("Failed to list MCP packages")?;
79            render_result(&result);
80            Ok(())
81        },
82        McpCommands::Tools(args) => {
83            let result = tools::execute(args, config)
84                .await
85                .context("Failed to list MCP tools")?;
86            render_result(&result);
87            Ok(())
88        },
89        McpCommands::Call(args) => {
90            let result = call::execute(args, config)
91                .await
92                .context("Failed to execute MCP tool")?;
93            render_result(&result);
94            Ok(())
95        },
96    }
97}