use clap::Parser;
use mcp_tools::{
common::{McpServerBase, ServerConfig},
servers::WebToolsServer,
Result,
};
use std::path::PathBuf;
use tokio::signal;
use tracing::{error, info};
#[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 {
#[arg(short, long, default_value = "127.0.0.1")]
host: String,
#[arg(short, long, default_value = "8082")]
port: u16,
#[arg(long, default_value = "web-tools-server")]
name: String,
#[arg(short, long)]
working_dir: Option<PathBuf>,
#[arg(short, long)]
verbose: bool,
#[arg(short, long)]
config: Option<PathBuf>,
#[arg(long, default_value = "30")]
timeout: u64,
#[arg(long, default_value = "MCP-Web-Tools/1.0")]
user_agent: String,
}
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
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
);
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(),
};
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");
info!("Server is ready to accept connections");
info!("Press Ctrl+C to shutdown");
match signal::ctrl_c().await {
Ok(()) => {
info!("Received shutdown signal");
}
Err(err) => {
error!("Unable to listen for shutdown signal: {}", err);
}
}
info!("Shutting down Web Tools MCP Server...");
server.shutdown().await?;
info!("Server shutdown complete");
Ok(())
}