mcp-tools 0.1.0

Rust MCP tools library
Documentation
//! System Tools MCP Server Binary
//!
//! Standalone executable for the System Tools MCP server
//! Provides system operations and shell command execution via MCP protocol

use clap::Parser;
use mcp_tools::{
    common::{McpServerBase, ServerConfig},
    servers::SystemToolsServer,
    Result,
};
use std::path::PathBuf;
use tokio::signal;
use tracing::{error, info, warn};

/// System Tools MCP Server
#[derive(Parser)]
#[command(name = "system-server")]
#[command(about = "System Tools MCP Server - Provides system operations via MCP protocol")]
#[command(version = "1.0.0")]
struct Args {
    /// Server bind address
    #[arg(short, long, default_value = "127.0.0.1")]
    host: String,

    /// Server port
    #[arg(short, long, default_value = "8083")]
    port: u16,

    /// Server name
    #[arg(long, default_value = "system-tools-server")]
    name: String,

    /// Working directory for command execution
    #[arg(short, long)]
    working_dir: Option<PathBuf>,

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

    /// Configuration file path
    #[arg(short, long)]
    config: Option<PathBuf>,

    /// Enable unsafe commands (NOT RECOMMENDED)
    #[arg(long)]
    allow_unsafe: bool,

    /// Command execution timeout in seconds
    #[arg(long, default_value = "30")]
    command_timeout: u64,
}

#[tokio::main]
async fn main() -> Result<()> {
    let args = Args::parse();

    // Initialize logging
    let log_level = if args.verbose { "debug" } else { "info" };
    tracing_subscriber::fmt().with_env_filter(log_level).init();

    info!("Starting System Tools MCP Server v1.0.0");
    info!("Server will bind to {}:{}", args.host, args.port);
    info!("Command timeout: {}s", args.command_timeout);

    // Security warning
    if args.allow_unsafe {
        warn!("⚠️  UNSAFE MODE ENABLED - Dangerous commands are allowed!");
        warn!("⚠️  This is NOT RECOMMENDED for production use!");
    } else {
        info!("🔒 Safe mode enabled - Dangerous commands will be blocked");
    }

    // Create server configuration
    let config = ServerConfig {
        name: args.name,
        description: "System Tools MCP Server - Provides system operations and command execution"
            .to_string(),
        version: "1.0.0".to_string(),
        host: args.host,
        port: args.port,
        max_connections: 100,
        request_timeout_secs: 300,
        log_requests: args.verbose,
        server_config: std::collections::HashMap::new(),
    };

    // Create and initialize server
    let mut server = SystemToolsServer::new(config).await?;
    server.initialize().await?;

    info!("System Tools MCP Server initialized successfully");
    info!("Available tools: execute_command, get_system_info, get_environment, get_processes");
    info!("⚠️  System execution permissions required");

    // Start server (this would typically start the actual MCP server)
    info!("Server is ready to accept connections");
    info!("Press Ctrl+C to shutdown");

    // Wait for shutdown signal
    match signal::ctrl_c().await {
        Ok(()) => {
            info!("Received shutdown signal");
        }
        Err(err) => {
            error!("Unable to listen for shutdown signal: {}", err);
        }
    }

    // Shutdown server
    info!("Shutting down System Tools MCP Server...");
    server.shutdown().await?;
    info!("Server shutdown complete");

    Ok(())
}