Skip to main content
Glama

UniFi MCP

A local stdio MCP server for a UniFi gateway's Network application. It covers every operation in the documented local Network API (11.0.104): curated tools for common reads, one tool for any documented read, and a preview, approve, apply workflow for every documented write. It also covers a named set of reads and writes on the Network application's internal API. See docs/coverage.md for each operation's status and evidence.

The point of this server is its boundary: the agent never holds the API key, never sees credentials, and cannot change your network without a one-time code that only you can read.

Not affiliated with or endorsed by Ubiquiti. The internal API is unofficial and can change with any UniFi update.

Requirements

  • macOS, with FileVault on. The key broker is a LaunchDaemon; see docs/persistent-broker.md.

  • Agents that cannot sudo. Approvals rely on it: sudo -n true from an agent's shell should ask for a password.

  • /usr/bin/python3 from Apple's Command Line Tools or Xcode (xcode-select --install).

  • Node.js 22+ and pnpm.

  • A UniFi gateway with one site, running UniFi Network 11 (tested on 11.0.104), reachable on your local network, and a local API key created in its Network application (Settings, Control Plane, Integrations).

Related MCP server: unifi-mcp

Boundary

  • The MCP never holds the API key. The broker runs as a LaunchDaemon under the hidden _unifibroker user, from root-owned code, with the key in a file only that user can read. It answers over a Unix socket only the owner's unifibroker group can reach. The MCP refuses a socket that the broker's user does not own, or whose directory other users can enter.

  • The gateway is pinned. The broker talks to the address you set, and only if the gateway presents the TLS public key you confirmed at setup.

  • Documented fields only, never credentials. broker/unifi_api.py derives each read's allowlist from the Network API spec in spec/, minus the credential fields in EXCLUDED_FIELDS (Wi-Fi passphrases, preshared keys, hotspot voucher codes). Undocumented fields are dropped. A test fails if the spec gains a credential-like field nobody has classified. The six curated reads keep their own hand-written allowlists (LIST_OPERATIONS), as does every internal read.

  • Every write needs your approval code. broker/unifi_changes.py validates a write against the spec, reads the target, and gives the owner the exact target, diff, impact, and rollback with a one-time code through sudo "$UNIFI_BROKER" pending. The code never crosses the agents' socket. No operation has standing authorization.

  • Credentials cannot be written. Previews refuse changes to passphrases and preshared keys. Updates resend the current values, which the broker reads and never returns.

See SECURITY.md for what this does and does not protect against.

Setup

git clone https://github.com/edmprojects/unifi-mcp.git
cd unifi-mcp
pnpm install
pnpm build

Broker

UNIFI_BROKER="/Library/Application Support/UniFiBroker/bin/unifi-broker"
  1. Review the checkout (git status, git log, broker/), then install from it once: sudo /usr/bin/python3 -I broker/unifi_service.py install. It lists each file it will install and asks you to type yes.

  2. Pin your gateway, on your own network: sudo "$UNIFI_BROKER" set-gateway 192.168.1.1 (use your gateway's address). It shows the gateway's TLS key pin and asks you to type yes.

  3. Create a new UniFi API key for the broker and store it: sudo "$UNIFI_BROKER" set-key.

  4. Restart your MCP client so it picks up your new unifibroker group membership.

  5. To approve a write, run sudo "$UNIFI_BROKER" pending and give the agent the code it shows.

  6. To update, pull or commit in the checkout, then run sudo "$UNIFI_BROKER" update --repo <checkout>. The installed copy shows its own diff of every changed file before asking.

sudo "$UNIFI_BROKER" uninstall removes the daemon, files, gateway pin, user, and group, and asks before deleting the key. The broker logs to /Library/Logs/UniFiBroker/broker.log.

MCP client

{
  "mcpServers": {
    "unifi": {
      "command": "node",
      "args": ["/path/to/unifi-mcp/dist/server.js"]
    }
  }
}

Writes

  1. unifi_preview_change takes a documented write operation, its params (path IDs and query parameters; the site is supplied), and changes. For an update, changes holds only the fields to change; the broker merges them into the current record and sends the full body PUT requires, so every field you did not name is resent as read. For a create or action, changes is the request body.

  2. The preview returns the target, current state, exact body (credentials redacted), diff, impact (routine, disruptive, or destructive, with a network's references where relevant), and rollback. The owner sees the same plan and a one-time approval code with sudo "$UNIFI_BROKER" pending.

  3. If you approve, give the agent the code. unifi_apply_change sends only the change ID and the code; the body is the one the broker stored at preview.

  4. The broker refuses the write if there is no pending preview, the change ID or code differs, after three mismatched attempts, after 10 minutes, if the code was already used, or if the target changed since the preview. Every approval is single use, including one refused as stale.

  5. After writing, the broker reads the target back. Updates report every changed field and any unexpected or missing change; deletes confirm the target is gone; creates report the new ID; actions report that the gateway accepted them.

The read-back is the confirmation. Some changes take effect on the network a little later: after a live DNS record create and delete, the gateway's DNS server answered the new record a few seconds after the API did, and kept answering the deleted one for about 30 seconds.

To roll back, preview the returned rollback and approve it the same way.

Batches

unifi_preview_batch plans up to 25 routine changes, such as client renames or DNS record edits, for one approval code. Each change is planned exactly as it would be alone, and sudo "$UNIFI_BROKER" pending lists every one with its diff. A batch refuses disruptive and destructive changes and more than one change per target; those need their own approval. unifi_apply_change with the batch's code applies the changes in order, re-checks each for staleness, reads each back, and stops at the first that does not apply: status: "partial" lists what applied, what failed, and what was not attempted. Deletes recreate with a new ID, and voucher and device deletes are not reversible.

Tools

Tool

Returns

unifi_list_clients

Connected clients with type, IP and MAC address, connection time, and uplink device. Filters: type, search (name, IP, or MAC substring), limit (1–500, default 200).

unifi_list_devices

Adopted devices with model, state, addresses, firmware version, and update availability.

unifi_list_networks

Networks with VLAN ID, enabled state, management type, and firewall zone.

unifi_list_wifi_broadcasts

SSIDs with enabled state, security type, and assigned network name. No passphrases.

unifi_list_firewall_policies

Policies in gateway order with action, source and destination zone names, network selectors resolved to network names (with matchOpposite for "all except"), IP version, and logging. userDefinedOnly (default false). An empty description is reported as null; unifi_read with getFirewallPolicy returns the stored text, which can be "".

unifi_read

Any documented read by operation name (for example getDnsPolicyPage, getAclRule, getWans), with path IDs, offset, limit, and filter in params. Documented fields only, no credentials.

unifi_internal_read

A named read on the Network application's internal, unofficial API: active clients with live stats, known clients, health (including the latest speed test), devices with radios, ports, and firmware, neighboring APs, port forwards, static routes, port profiles, and the system log (params: hours up to 168, limit up to 100). Hand-written field allowlists; no credentials.

unifi_inspect_device

One device's details and latest statistics together.

unifi_preview_change

Plans any documented write: target, current state, exact body, diff, impact, rollback. Changes nothing; the owner gets an approval code from sudo … pending.

Internal writes go through unifi_preview_change and unifi_apply_change too, with the same approval and read-back: renameClient, setClientNote, setClientFixedIp, renameDevice, setDeviceLed, and setDeviceRadio edit a record by params.id; locateDevice, blockClient, unblockClient, reconnectClient, forgetClient, and upgradeDevice act on a client or device by params.mac. Block, reconnect, radio, and firmware changes are disruptive and forget is destructive, so none of them can be batched. See docs/gaps.md. | unifi_preview_batch | Plans up to 25 routine changes for one approval code; refuses disruptive or destructive changes and repeated targets. | | unifi_apply_change | Applies a previewed change with your code, then reads the target back and reports what changed. |

Field names and operations come from Ubiquiti's UniFi Network API spec, 11.0.104 (spec/), as a gateway serves it from its API docs page; see NOTICE. Its Filtering section documents the filter syntax that unifi_read passes through, such as name.eq('Guests') and and(enabled.eq(true), name.like('IoT*')). Other Network versions are untested.

Checks

pnpm format:check
pnpm lint
pnpm typecheck
pnpm test        # vitest (including the coverage matrix), then the broker's Python tests
pnpm coverage    # regenerate docs/coverage.md after changing coverage/status.json
pnpm build
pnpm smoke       # live reads through a running broker; prints counts only

See CONTRIBUTING.md for the rules every change keeps.

License

MIT, except the UniFi Network API spec in spec/; see NOTICE.

Available Tools

11 tools
unifi_apply_changeApply Approved UniFi ChangeA
Destructive

Applies the previewed change or batch with the owner's one-time approval code, then reads each target back and reports what changed. A batch applies in order and stops at the first change that does not apply; status partial lists results and what was not attempted. Refuses unapproved, mismatched, expired, reused, and stale approvals. Use the returned rollback to undo.

Inputs: changeId (required), approvalCode (required). Returns: kind, status, target, verified, +1 more

unifi_inspect_deviceInspect UniFi DeviceA
Read-only

Gets one adopted device's details (ports, radios, uplink, firmware) and its latest statistics (uptime, CPU, memory, traffic) in one call.

Inputs: deviceId (required). Returns: device, latestStatistics

unifi_internal_readRead UniFi Internal APIA
Read-only

Runs one named read on the Network application's internal, unofficial API, for what the documented API lacks. activeClients: Connected clients with IP, network, AP or switch port, signal, uptime, and traffic. knownClients: Every client the gateway remembers, with name, note, fixed IP, and first and last seen. health: Status of WAN, LAN, WLAN, and VPN: counts, WAN IP, ISP, latency, and throughput. devices: Devices with firmware and available upgrades, radio settings and stats, and port tables. rogueAps: Neighboring access points seen in the last 24 hours. portForwards: Port forwarding rules: what is reachable from the internet. routes: Static routes. portProfiles: Switch port profiles: which networks a port carries, PoE, isolation, and speed. systemLog: Recent system log events, admin (AUDIT) and client and device (CLIENT_DEVICES) alike: what happened to which client, device, network, or admin, and when. params: hours (1-168, default 24), limit (1-100, default 50). Returns only allowlisted fields; credentials are never included.

Inputs: operation (required), params. Returns: read, count, items

unifi_list_clientsList UniFi ClientsB
Read-only

Lists clients connected to the gateway with type, IP and MAC address, connection time, and uplink device. Filters by type or a name, IP, or MAC substring.

Inputs: type, limit, search. Returns: clients, totalCount, matchedCount

unifi_list_devicesList UniFi DevicesB
Read-only

Lists adopted UniFi devices with model, state, IP and MAC address, firmware version, and whether an update is available.

Inputs: no named parameters. Returns: count, devices

unifi_list_firewall_policiesList UniFi Firewall PoliciesA
Read-only

Lists firewall policies in gateway order with action, source and destination zones and network selectors (resolved to names), IP version, and logging. Optionally only user-defined policies.

Inputs: userDefinedOnly. Returns: count, policies

unifi_list_networksList UniFi Networks and VLANsA
Read-only

Lists networks with their VLAN IDs, enabled state, management type, and firewall zone.

Inputs: no named parameters. Returns: count, networks

unifi_list_wifi_broadcastsList UniFi Wi-Fi BroadcastsA
Read-only

Lists Wi-Fi SSIDs with enabled state, security type, and assigned network. Never returns passphrases.

Inputs: no named parameters. Returns: count, broadcasts

unifi_preview_batchPreview a Batch of UniFi ChangesA
Read-only

Plans up to 25 routine changes, such as client renames, notes, or DNS record edits, for one approval code. Each change takes the same operation, params, and changes as unifi_preview_change and is planned exactly as it would be alone. Refuses disruptive or destructive changes and more than one change per target; preview those singly. Returns every plan and its rollback; the owner gets one code through sudo … pending.

Inputs: changes (required). Returns: batch, count, items, approval, +3 more

unifi_preview_changePreview UniFi Configuration ChangeA
Read-only

Plans one documented Network API write without applying it. For updates, pass only the fields to change in changes; the broker merges them into the current record. Returns the target, current state, exact body, diff, impact, and rollback. The broker gives the owner a one-time approval code through sudo … pending; ask the owner for it. Credential fields cannot be set. Internal (unofficial) writes use the same flow: renameClient (params.id; changes { name }); setClientNote (params.id; changes { note } (empty clears it)); setClientFixedIp (params.id; changes { use_fixedip, fixed_ip, network_id } (fixed_ip and network_id when reserving)); renameDevice (params.id; changes { name }); setDeviceLed (params.id; changes { led_override: "default" | "on" | "off" }); setDeviceRadio (params.id; changes { radio (e.g. "ng" 2.4 GHz, "na" 5 GHz), and any of channel ("auto" or a number), ht (width: 20, 40, 80, 160, 320), tx_power_mode (auto, high, medium, low, custom), tx_power (dBm) }); locateDevice (params.mac; changes { enabled }); blockClient (params.mac; changes none); unblockClient (params.mac; changes none); reconnectClient (params.mac; changes none); forgetClient (params.mac; changes none); upgradeDevice (params.mac; changes none). Their IDs come from unifi_internal_read knownClients or devices.

Inputs: operation (required), params, changes. Returns: body, diff, kind, impact, +8 more

unifi_readRead Any UniFi Network API ResourceA
Read-only

Runs one documented Network API read (operation names follow the API, such as getDnsPolicyPage, getAclRule, getAdoptedDeviceLatestStatistics, getWans) and returns its documented fields. Pass path IDs and offset, limit (most lists allow at most 200), or filter in params; the site is supplied automatically. Wi-Fi passphrases and voucher codes are never returned.

Inputs: operation (required), params. Returns: result, operationId

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 11 tools

    Disambiguation4/5

    The set has a clear split between specific list tools, generic read escapes (unifi_read / unifi_internal_read), an inspection tool, and a preview/apply write flow, so most selections are unambiguous. There is mild overlap: unifi_list_devices vs unifi_inspect_device vs unifi_internal_read(devices), and unifi_list_clients vs unifi_internal_read(activeClients/knownClients) all touch similar data, and the two generic read tools differ mainly on documented-vs-internal API. Descriptions do explain the distinction, keeping it at a solid 4.

    Naming Consistency4/5

    All 11 names share a unifi_ prefix and snake_case, and most follow verb_noun (list_clients, preview_change, inspect_device, apply_change). The exceptions are unifi_read and unifi_internal_read, which are bare verbs without an object, a minor deviation from the pattern. Predictable overall with only that small inconsistency.

    Tool Count5/5

    11 tools is well within the sweet spot, and each earns its place: five resource-specific listers, two generic read escapes, one inspection shortcut, and a three-tool preview/preview_batch/apply write pipeline. Nothing feels redundant or bolted on.

    Completeness4/5

    Read coverage is broad (clients, devices, networks, SSIDs, firewall policies, plus generic documented and internal reads) and writes are covered generically through the preview/apply broker, including batch and rollback. Gaps are minor: approval management is punted to `sudo … pending` outside the toolset (no list/cancel pending approvals), and some resources like DNS records, routes, and port forwards are only reachable indirectly via the generic read tools.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents and applications to interact with UniFi network infrastructure through the UniFi Network Controller API, supporting device, client, network, firewall, QoS, backup, multi-site, and topology management.
      Apache 2.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables an LLM client to diagnose a UniFi network through 39 tools covering devices, clients, WAN and VPN state, events, metrics, traffic reports, threat summaries, and security posture audits. Guarded write tools allow blocking clients, restarting devices, and managing networks, WiFi broadcasts, and hotspot vouchers, with previews and confirmation required for changes that could cut off protected networks or the gateway.
      56
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables an agent to make a small, fixed set of guard-railed changes to UniFi Network, such as toggling mDNS forwarding, adding SSIDs, setting fixed IPs, and managing selected firewall policies, while keeping write actions separate and logged.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP clients to manage UniFi Network, Protect, and Access through official local APIs with read-only-by-default permissions, per-client tokens, and independent human approval for high-impact changes.
      Apache 2.0