Skip to main content

systemprompt_cli/commands/plugins/mcp/
mod.rs

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