//! `fxt mcp` -- MCP (Model Context Protocol) server mode.
//!
//! Starts a JSON-RPC 2.0 server on stdin/stdout, exposing all Foxhunt
//! operations as MCP tools for LLM agents (Claude, Cursor, etc.).

use anyhow::Result;
use clap::Parser;

use crate::grpc::FoxhuntClient;
use crate::mcp::server::McpServer;

/// Start MCP server (JSON-RPC 2.0 on stdin/stdout)
#[derive(Parser, Debug)]
pub struct McpCommand {
    /// API endpoint URL for backend gRPC calls
    #[arg(
        long = "api-url",
        env = "FXT_API_URL",
        default_value = "https://api.fxhnt.ai"
    )]
    api_url: String,
}

impl McpCommand {
    /// Start the MCP server that exposes Foxhunt operations as tools
    /// for LLM agents (e.g. Claude, Cursor).
    pub async fn execute(&self) -> Result<()> {
        let client = FoxhuntClient::connect(&self.api_url).await?;
        let server = McpServer::new(self.api_url.clone(), client);
        server.run().await
    }
}
