entity_graph_mcp/
cli.rs

1//! CLI argument parsing.
2//!
3//! ```text
4//! entity-graph-mcp              # default: stdio
5//! entity-graph-mcp stdio        # explicit stdio
6//! entity-graph-mcp http         # HTTP on 0.0.0.0:8080
7//! entity-graph-mcp http --port 9090 --host 127.0.0.1
8//! ```
9
10use std::net::SocketAddr;
11
12use clap::{Parser, Subcommand};
13
14/// entity-graph MCP server — serve the entity graph over MCP.
15#[derive(Debug, Parser)]
16#[command(
17    name = "entity-graph-mcp",
18    version,
19    about = "Serve the Prometheus entity graph over the Model Context Protocol (MCP).",
20    long_about = None,
21)]
22pub struct Cli {
23    #[command(subcommand)]
24    pub command: Option<Command>,
25}
26
27/// Available transport sub-commands.
28#[derive(Debug, Subcommand)]
29pub enum Command {
30    /// Run on stdin/stdout (default for local MCP hosts like Claude Desktop).
31    Stdio,
32
33    /// Run a Streamable HTTP server.
34    Http(HttpArgs),
35}
36
37/// Arguments for the `http` subcommand.
38#[derive(Debug, clap::Args)]
39pub struct HttpArgs {
40    /// Host address to bind.
41    #[arg(long, default_value = "0.0.0.0", env = "ENTITY_GRAPH_MCP_HOST")]
42    pub host: String,
43
44    /// TCP port to listen on.
45    #[arg(long, default_value_t = 8080, env = "ENTITY_GRAPH_MCP_PORT")]
46    pub port: u16,
47}
48
49impl HttpArgs {
50    /// Parse host + port into a `SocketAddr`.
51    pub fn socket_addr(&self) -> Result<SocketAddr, std::net::AddrParseError> {
52        format!("{}:{}", self.host, self.port).parse()
53    }
54}