unifi-cli
CLI for UniFi Network controller. Designed for both human operators and AI agents.
Installation
From source
From GitHub releases
Pre-built binaries are available for Linux (x64, arm64), macOS (x64, arm64), and Windows (x64) on the releases page.
Configuration
Configuration can be provided via CLI flags, environment variables, or a config file.
CLI flags
Environment variables
Config file
Create ~/.config/unifi-cli/config.toml:
= "https://unifi.example.com"
= "YOUR_KEY"
Usage
Clients
Devices
Networks
System
Agent-friendly design
unifi-cli is designed to work well with AI agents and automation scripts. Instead of requiring an MCP server, agents can call the CLI directly with lower overhead and better composability.
Automatic JSON output
When stdout is not a terminal (piped or redirected), output switches to JSON automatically. No flags needed.
# Human at terminal: gets a formatted table
# Agent piping output: gets JSON automatically
data=
You can also force JSON mode explicitly:
Clean stdout/stderr separation
Data goes to stdout. Human messages (summaries, confirmations) go to stderr. This means piping and redirection always capture clean, parseable data.
# stdout has only the JSON data, stderr has "12 clients"
Quiet mode
Suppress all non-data output with --quiet:
Structured mutation responses
Commands that change state (block, kick, restart, etc.) return structured JSON:
# {"action": "block", "mac": "AA:BB:CC:DD:EE:FF", "status": "ok"}
Runtime schema introspection
The schema command dumps all commands, arguments, output fields, and exit codes as JSON. Agents can discover capabilities at runtime without parsing --help text.
This outputs the full command tree including which commands are mutating, what arguments they accept, and what fields appear in the JSON output.
Distinct exit codes
Agents can branch on specific failure modes without parsing error messages:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Configuration error (missing host or API key) |
| 3 | Authentication error (401/403) |
| 4 | Not found (404) |
| 5 | API error (server error) |
Why CLI over MCP?
For AI agent integrations, a well-designed CLI has several advantages over an MCP server:
- Token efficiency -- a CLI call uses ~35x fewer tokens than the MCP tool-call protocol
- Composability -- pipe output to
jq,grep, or other tools - No server process -- no sidecar to run, no port to manage
- Universal -- works from any language, shell, or automation framework
Development
License
MIT