mcp-tools 0.1.0

Rust MCP tools library
Documentation
//! Web Tools MCP Server Binary
//!
//! Standalone executable for the Web Tools MCP server
//! Provides web scraping and HTTP request capabilities via MCP protocol

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

/// Web Tools MCP Server
#[derive(Parser)]
#[command(name = "web-server")]
#[command(
    about = "Web Tools MCP Server - Provides web scraping and HTTP capabilities 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 = "8082")]
    port: u16,

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

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

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

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

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

    /// User agent string
    #[arg(long, default_value = "MCP-Web-Tools/1.0")]
    user_agent: String,
}

#[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 Web Tools MCP Server v1.0.0");
    info!("Server will bind to {}:{}", args.host, args.port);
    info!(
        "Request timeout: {}s, User-Agent: {}",
        args.timeout, args.user_agent
    );

    // Create server configuration
    let config = ServerConfig {
        name: args.name,
        description: "Web Tools MCP Server - Provides web scraping and HTTP capabilities"
            .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 = WebToolsServer::new(config).await?;
    server.initialize().await?;

    info!("Web Tools MCP Server initialized successfully");
    info!("Available tools: http_request, analyze_webpage, analyze_url, fetch_content");
    info!("⚠️  Network permissions required for web operations");

    // 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 Web Tools MCP Server...");
    server.shutdown().await?;
    info!("Server shutdown complete");

    Ok(())
}