use anyhow::Result;
use clap::Args;
use octocode::mcp::proxy::McpProxyServer;
#[derive(Args, Clone)]
pub struct McpProxyArgs {
#[arg(long, value_name = "HOST:PORT")]
pub bind: String,
#[arg(long, default_value = ".")]
pub path: String,
#[arg(long)]
pub debug: bool,
}
pub async fn run(args: McpProxyArgs) -> Result<()> {
let root_path = if args.path == "." {
std::env::current_dir()
.map_err(|e| anyhow::anyhow!("Failed to get current directory: {}", e))?
} else {
std::path::Path::new(&args.path)
.canonicalize()
.map_err(|e| anyhow::anyhow!("Invalid path '{}': {}", args.path, e))?
};
if !root_path.is_dir() {
return Err(anyhow::anyhow!(
"Path '{}' is not a directory",
root_path.display()
));
}
let bind_addr = args
.bind
.parse::<std::net::SocketAddr>()
.map_err(|e| anyhow::anyhow!("Invalid bind address '{}': {}", args.bind, e))?;
println!("🚀 Starting MCP Proxy Server...");
println!("📁 Root path: {}", root_path.display());
println!("🌐 Bind address: {}", bind_addr);
println!("🐛 Debug mode: {}", args.debug);
let mut proxy_server = McpProxyServer::new(bind_addr, root_path, args.debug).await?;
proxy_server.run().await
}