Skip to main content

agentis_pay/
lib.rs

1//! agentis-pay CLI public entry points.
2
3pub mod commands;
4pub mod display;
5pub mod mcp;
6mod pix_key;
7pub mod session;
8pub mod updater;
9
10use std::path::PathBuf;
11
12use clap::{ArgGroup, Parser, Subcommand};
13
14pub use commands::{HistoryArgs, LoginArgs, PixSendArgs, SignupArgs, VerifyArgs};
15pub use display::{
16    CommandName, OutputFormat, StatusColor, cents_to_brl, current_agent_name, emit_data, emit_line,
17    emit_message, emit_status, set_agent_name,
18};
19
20#[derive(clap::ValueEnum, Clone, Debug, Default)]
21pub enum McpClient {
22    #[default]
23    Claude,
24}
25
26#[derive(clap::Args, Debug, Clone)]
27pub struct McpServeArgs {
28    /// Use stdio transport (default for local agents).
29    #[arg(long)]
30    pub stdio: bool,
31
32    /// Use Streamable HTTP transport (for remote/multi-user deployments).
33    #[arg(long)]
34    pub http: bool,
35
36    /// Host to bind the HTTP server to.
37    #[arg(long, default_value = "0.0.0.0", env = "AGENTIS_PAY_HOST")]
38    pub host: String,
39
40    /// Port to bind the HTTP server to.
41    #[arg(long, default_value_t = 8080, env = "AGENTIS_PAY_PORT")]
42    pub port: u16,
43
44    /// Optional device identifier override.
45    #[arg(long)]
46    pub device_id: Option<String>,
47}
48
49#[derive(clap::Args, Debug, Clone)]
50#[command(group(ArgGroup::new("mcp-jwt-source").args(["jwt_file", "jwt_stdin"]).multiple(false)))]
51pub struct McpSetupArgs {
52    /// MCP client target.
53    #[arg(long, value_enum, default_value_t = McpClient::Claude)]
54    pub client: McpClient,
55
56    /// Optional path to a JWT file to embed in the generated MCP snippet.
57    /// Usually unnecessary for local agents because `mcp serve` reuses saved CLI credentials.
58    #[arg(long, value_name = "PATH")]
59    pub jwt_file: Option<PathBuf>,
60
61    /// Read a JWT from stdin and embed it in the generated MCP snippet.
62    #[arg(long)]
63    pub jwt_stdin: bool,
64
65    /// Optional device identifier override to embed in the generated MCP snippet.
66    #[arg(long)]
67    pub device_id: Option<String>,
68
69    /// Optional agent name override to embed in the generated MCP snippet.
70    #[arg(long)]
71    pub agent_name: Option<String>,
72
73    /// Only print the JSON config without writing to the config file.
74    #[arg(long)]
75    pub print_only: bool,
76}
77
78#[derive(Subcommand, Debug)]
79pub enum McpCommand {
80    /// Run the MCP server for local agent integrations.
81    Serve(McpServeArgs),
82
83    /// Install MCP server into Claude Desktop config.
84    #[command(alias = "setup")]
85    Install(McpSetupArgs),
86}
87
88#[derive(Parser, Debug)]
89#[command(name = "agentis-pay")]
90#[command(author, version, about = "CLI client for Bipa's agentis-pay service", long_about = Some("Interact with pix accounts via Bipa gRPC with MCP support for agent workflows."))]
91#[command(
92    subcommand_required = true,
93    infer_subcommands = true,
94    arg_required_else_help = true
95)]
96pub struct Cli {
97    /// Output format for command responses.
98    #[arg(
99        short = 'f',
100        long,
101        global = true,
102        env = "AGENTIS_PAY_OUTPUT",
103        default_value_t = OutputFormat::Text,
104        value_enum
105    )]
106    pub output: OutputFormat,
107
108    /// Optional command line verbosity.
109    #[arg(short, long, global = true)]
110    pub verbose: bool,
111
112    /// Silence all success/info output.
113    #[arg(short = 'q', long, global = true)]
114    pub quiet: bool,
115
116    #[command(subcommand)]
117    pub command: Command,
118}
119
120#[derive(Subcommand, Debug)]
121pub enum PixCommand {
122    /// Send a PIX payment to a Pix key.
123    #[command(alias = "pagar")]
124    Pay(commands::PixSendArgs),
125
126    /// List Pix keys.
127    #[command(alias = "chaves")]
128    Keys,
129
130    /// Decode a Pix BR Code / Copia e Cola payload.
131    #[command(aliases = ["copia&cola", "copiacola"])]
132    Brcode(commands::BrcodeArgs),
133
134    /// View compact and detailed transaction history.
135    #[command(alias = "extrato")]
136    History(commands::HistoryArgs),
137
138    /// Show configured Pix limits.
139    Limits,
140
141    /// Show current BRL balance.
142    #[command(alias = "saldo")]
143    Balance,
144
145    /// Show Pix keys for deposits.
146    #[command(alias = "depositar")]
147    Deposit,
148
149    /// Show account details.
150    #[command(alias = "conta")]
151    Account,
152}
153
154#[derive(Subcommand, Debug)]
155pub enum Command {
156    /// Start the account signup flow. [unimplemented]
157    Signup(commands::SignupArgs),
158
159    /// Authenticate with Agentis Pay (OAuth by default, --pin for legacy).
160    Login(commands::LoginArgs),
161
162    /// Complete PIN-based login by submitting the PIN received via email or phone.
163    Verify(commands::VerifyArgs),
164
165    /// Clear stored credentials.
166    Logout,
167
168    /// Show current credential status.
169    Whoami,
170
171    /// Print the Agentis Pay skill reference for AI agents.
172    Skill,
173
174    /// Pix operations (pay, keys, account, balance, deposit, brcode, history, limits).
175    #[command(subcommand)]
176    Pix(PixCommand),
177
178    /// Update the CLI to the latest version (managed installs only).
179    Update,
180
181    /// MCP commands for local/remote agent integrations.
182    #[command(subcommand)]
183    Mcp(McpCommand),
184
185    /// Legacy alias for `mcp serve`.
186    #[command(name = "mcp-serve", hide = true)]
187    McpServeLegacy(McpServeArgs),
188
189    /// Legacy alias for `mcp install`.
190    #[command(name = "setup-mcp", hide = true)]
191    SetupMcpLegacy(McpSetupArgs),
192}