Skip to main content

systemprompt_cli/commands/plugins/mcp/
mod.rs

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