//! Serve command handler for MCP server.

use crate::cli::args::{GlobalArgs, ServeArgs, Transport as ArgTransport};
use crate::error::{ExitStatus, Result};

/// Handle the serve command
#[cfg(feature = "mcp")]
pub async fn handle_serve(args: ServeArgs, _global: &GlobalArgs) -> Result<ExitStatus> {
    use crate::mcp::server::{start_mcp_server, Transport};

    let transport = match args.transport {
        ArgTransport::Stdio => Transport::Stdio,
        ArgTransport::Sse => Transport::Sse,
        ArgTransport::Http => Transport::Http,
    };

    start_mcp_server(transport, &args.host, args.port).await?;
    Ok(ExitStatus::Success)
}

#[cfg(not(feature = "mcp"))]
pub async fn handle_serve(_args: ServeArgs, _global: &GlobalArgs) -> Result<ExitStatus> {
    eprintln!("MCP server requires the 'mcp' feature.");
    eprintln!("Rebuild with: cargo build --features mcp");
    Ok(ExitStatus::ConfigError)
}
