mcp-tools 0.1.0

Rust MCP tools library
Documentation
//! MCP Tools CLI Client Binary
//!
//! Command-line interface for interacting with MCP servers
//! Provides interactive and batch modes for testing and automation

use clap::Parser;
use mcp_tools::{clients::CliClient, common::ClientConfig, Result};

/// CLI arguments for the MCP client
#[derive(Parser)]
#[command(name = "mcp-cli")]
#[command(about = "MCP Tools CLI Client")]
#[command(version = "1.0")]
pub struct CliArgs {
    /// Server URL to connect to
    #[arg(short, long, default_value = "http://localhost:8080")]
    pub server: String,

    /// Connection timeout in seconds
    #[arg(short, long, default_value = "30")]
    pub timeout: u64,

    /// Enable verbose logging
    #[arg(short, long)]
    pub verbose: bool,

    /// Output format (json, yaml, table)
    #[arg(short, long, default_value = "table")]
    pub format: String,

    /// Command to execute
    #[command(subcommand)]
    pub command: Option<CliCommand>,
}

/// CLI commands
#[derive(clap::Subcommand, Clone)]
pub enum CliCommand {
    /// Connect to MCP server and show capabilities
    Connect,

    /// List available tools
    ListTools,

    /// Execute a tool
    Execute {
        /// Tool name to execute
        tool: String,

        /// Tool arguments as JSON string
        #[arg(short, long)]
        args: Option<String>,

        /// Tool arguments as key=value pairs
        #[arg(short = 'p', long = "param")]
        params: Vec<String>,
    },

    /// Interactive mode
    Interactive,

    /// Show server status
    Status,

    /// Disconnect from server
    Disconnect,
}

#[tokio::main]
async fn main() -> Result<()> {
    // Parse command line arguments
    let args = CliArgs::parse();

    // Create client configuration
    let config = ClientConfig {
        name: "MCP-Tools-CLI".to_string(),
        version: "1.0.0".to_string(),
        server_url: args.server.clone(),
        connect_timeout_secs: 30,
        request_timeout_secs: args.timeout,
        log_requests: args.verbose,
        client_config: std::collections::HashMap::new(),
    };

    // Convert to internal CliArgs structure
    let cli_args = mcp_tools::clients::cli::CliArgs {
        server: args.server,
        timeout: args.timeout,
        verbose: args.verbose,
        format: args.format,
        command: args.command.map(|cmd| match cmd {
            CliCommand::Connect => mcp_tools::clients::cli::CliCommand::Connect,
            CliCommand::ListTools => mcp_tools::clients::cli::CliCommand::ListTools,
            CliCommand::Execute { tool, args, params } => {
                mcp_tools::clients::cli::CliCommand::Execute { tool, args, params }
            }
            CliCommand::Interactive => mcp_tools::clients::cli::CliCommand::Interactive,
            CliCommand::Status => mcp_tools::clients::cli::CliCommand::Status,
            CliCommand::Disconnect => mcp_tools::clients::cli::CliCommand::Disconnect,
        }),
    };

    // Create and run CLI client
    let mut client = CliClient::new(config, cli_args);
    client.run().await
}