mcpField
U
unifi-cli

unifi-cli

github.com/dl-alexandreCloud & DevOps145 installsUpdated 4w ago
Repository

About unifi-cli

unifi-cli is a skill for using the `unifi` CLI with local UniFi Network controllers, including Dream Machine, Cloud Key, and self-hosted installations. It provides commands to inspect sites, network devices, and connected clients.

Key features

  1. 01Configure controller connection
  2. 02List controller sites
  3. 03Inspect UniFi devices and status
  4. 04List connected clients
  5. 05Export results as JSON

Use cases

  1. 01Find a site before running site-specific commands
  2. 02Check device status and adoption
  3. 03Locate a client by IP or MAC address
  4. 04Export device inventory for analysis

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/dl-alexandre/skills --skill unifi-cli

After installing, type/unifi-cliin Claude Code to confirm it loaded.

Details

From the project README

Skill: unifi-cli

Local UniFi Controller CLI

This skill provides guidance for the unifi CLI tool, a command-line interface for local UniFi Network controllers.

Overview

unifi connects directly to your local UniFi Controller (Dream Machine, Cloud Key, or self-hosted) to manage sites, devices, and clients. For cloud-based management across multiple sites, use the separate usm CLI.

Installation

Homebrew
brew tap dl-alexandre/tap
brew install unifi
Manual

Download from GitHub Releases.

Quick Start

  1. Configure:
unifi init
# Or set environment variables:
export UNIFI_BASE_URL="https://192.168.1.1"
export UNIFI_USERNAME="admin"
export UNIFI_PASSWORD="your-password"
  1. List sites:
unifi sites list
  1. List devices:
unifi devices list
  1. List clients:
unifi clients list

Available Commands

unifi init

Interactive configuration setup. Creates ~/.config/unifi/config.yaml.

Use when:

  • First-time setup
  • Changing controller URL or username
unifi sites list

List all sites on the controller.

Use when:

  • Discovering available sites
  • Finding site IDs for other commands
unifi devices list

List all UniFi devices (APs, switches, gateways).

Use when:

  • Viewing network hardware
  • Checking device status and adoption state
  • Finding device MAC addresses

Flags:

  • --site=<id> - Specific site (default: first available)
unifi clients list

List connected clients.

Use when:

  • Viewing connected devices
  • Checking wireless signal strength
  • Finding client MAC addresses

Flags:

  • --site=<id> - Specific site (default: first available)
unifi version [--check]

Show version information.

Configuration

Config file: ~/.config/unifi/config.yaml

Note: Passwords are NOT stored in config. Use environment variables or flags.

api:
  base_url: https://192.168.1.1
  timeout: 30

auth:
  username: admin

output:
  format: table
  color: auto

Environment Variables

VariableDescription
UNIFI_BASE_URLController URL (e.g., https://192.168.1.1)
UNIFI_USERNAMEUsername for authentication
UNIFI_PASSWORDPassword for authentication
UNIFI_FORMATOutput format: table, json
UNIFI_COLORColor mode: auto, always, never
UNIFI_NO_HEADERSDisable table headers
UNIFI_CONFIGPath to config file

Authentication

Local UniFi Controllers use session-based authentication:

  1. Client sends username/password to /api/auth/login
  2. Server sets session cookie
  3. Client uses cookie for subsequent requests
  4. Automatic re-login when session expires

Security notes:

  • Use local admin accounts (not cloud/SSO accounts)
  • Passwords never stored in config
  • Session cookies handled automatically

Exit Codes

CodeMeaning
0Success
1General error
2Authentication failure
4Validation error
5Rate limited
6Network error

Common Workflows

Check all devices across all sites
for site in $(unifi sites list --output json | jq -r '.[].name'); do
  echo "=== Site: $site ==="
  unifi devices list --site "$site"
done
Export device list to JSON
unifi devices list --output json > devices.json
Find client by IP
unifi clients list --output json | jq '.[] | select(.ip == "192.168.1.100")'
Check adoption status
unifi devices list --output json | jq '.[] | select(.adopted == false)'

API Reference

Local UniFi Controller API endpoints:

  • GET /api/self/sites - List sites
  • GET /api/s/{site}/stat/device - List devices
  • GET /api/s/{site}/stat/sta - List clients
  • GET /api/s/{site}/stat/health - Site health

Related Tools

  • usm - For cloud-based UniFi Site Manager API (multi-site overview)

Troubleshooting

Connection refused:

  • Verify controller URL is correct
  • Check if controller is running
  • Ensure you're using HTTPS (not HTTP)

Authentication failed:

  • Use local admin account (not UniFi cloud account)
  • Verify username/password
  • Check if 2FA is enabled (not supported)

Certificate errors:

  • Self-signed certificates are common for local controllers
  • Use curl -k equivalent or add certificate to trust store

Comments

Markdown supported