Skip to main content

ferro_cli/commands/
mcp.rs

1//! MCP server command - start the Model Context Protocol server for AI-assisted development
2
3use console::style;
4use std::path::PathBuf;
5
6pub fn run(cwd: Option<String>) {
7    eprintln!(
8        "{} Starting Ferro MCP server...",
9        style("[MCP]").cyan().bold()
10    );
11
12    let project_root = cwd
13        .map(PathBuf::from)
14        .unwrap_or_else(|| std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")));
15
16    eprintln!(
17        "{} Project root: {}",
18        style("[MCP]").cyan().bold(),
19        project_root.display()
20    );
21
22    if let Err(e) = std::env::set_current_dir(&project_root) {
23        eprintln!(
24            "{} Failed to chdir to project root: {}",
25            style("[ERROR]").red().bold(),
26            e
27        );
28        std::process::exit(1);
29    }
30
31    let runtime = match tokio::runtime::Runtime::new() {
32        Ok(rt) => rt,
33        Err(e) => {
34            eprintln!(
35                "{} Failed to create tokio runtime: {}",
36                style("[ERROR]").red().bold(),
37                e
38            );
39            std::process::exit(1);
40        }
41    };
42
43    if let Err(e) = runtime.block_on(ferro_mcp::run()) {
44        eprintln!("{} ferro-mcp failed: {}", style("[ERROR]").red().bold(), e);
45        std::process::exit(1);
46    }
47}