Model Context Protocol server

Run your UniFi network by asking.

UniFi MCP connects Claude and other AI agents to your UniFi console. Ask what's on your network, find a device you don't recognise, block it, or write a firewall rule, all in plain language. You approve every change.

There's something called ESP_3A1F2C on the network. What is it, and can you keep it off the internet without kicking it off Wi-Fi?

unifi_list_clients search="ESP_3A1F2C" status="all"

It's an Espressif chip (typical of smart plugs and sensors) on the IoT network at 10.0.30.41, first seen yesterday. I'll create a policy that blocks just that device from reaching the internet. Here's the dry run:

unifi_create_firewall_policy action=BLOCK sourceZone="Internal" source.macs=["a4:cf:12:3a:1f:2c"] destinationZone="External" position="top" dryRun=true

Shall I apply it?

Why it matters

Home and small-office networks keep growing: dozens of phones, TVs, cameras and smart plugs, split across VLANs and guarded by firewall rules that few people want to edit by hand. UniFi's controller is powerful, but answering a simple question can mean five screens and a MAC address lookup.

Questions, not menus

"Which devices are offline?" "What's on the guest network?" "Is anything talking to the cameras VLAN from outside?" Get the answer directly instead of clicking through dashboards.

Faster response

When an unknown device shows up, you can find it, identify the vendor and block it in one conversation. That beats hunting for a MAC address on your phone at midnight.

Firewall rules you can read

Zone-based firewall policies are deeply nested JSON. The agent writes them from a plain description, shows a readable dry run first, and keeps an audit log of every change.

Local and private

The server talks directly to your console on your LAN. It needs no cloud account or third-party service, and your network data goes only to the AI client you choose.

An open standard

MCP is supported by Claude Code, Claude Desktop and a growing list of agents. Build once and any MCP client can use your network as a tool.

You stay in control

Write tools are flagged as destructive, so your client asks before each one runs. Turn on read-only mode and the agent can look but never touch.

How it works

The Model Context Protocol is a standard way for AI applications to call external tools. UniFi MCP is a small Node.js server that exposes your network as a set of well-described tools, and translates each tool call into requests to your UniFi console.

  1. You ask a question or request a change.

    "Block the TV from the internet after 10pm." The AI client sees the tool list and their descriptions, and decides which tools to call.

  2. The agent gathers context first.

    It looks up the client by name to get its MAC, and lists zones and networks so names like "IoT" resolve to the right IDs.

  3. It proposes the change as a dry run.

    The server builds the exact API request from simple fields (zones, MACs, ports, schedule) and returns a readable summary without sending anything.

  4. You approve, and the server applies it.

    The request goes to your console, the result comes back in plain terms, and the change is appended to the audit log.

Two UniFi APIs, one interface

UniFi Network 10.x has an official API that covers most things but cannot block clients or read flow logs, so the server also uses the internal APIs and hides the difference.

CapabilityAPIAuth
Devices, networks, Wi-Fi, firewall zones and policies, policy ordering, device restart, PoE power-cycleOfficial Network API
/proxy/network/integration/v1
API key
Client search including offline clients, block, unblock, reconnect, renameInternal API
/proxy/network/api/s/<site>
API key, with automatic fallback to a local admin login
Traffic flow logs, flow statistics, usage by app and clientInternal v2 API
/proxy/network/v2/api/site/<site>
API key, with automatic fallback to a local admin login

Tools

Each tool has a typed input schema and a description written for the agent. Firewall tools accept zone and network names as well as IDs.

ToolWhat it doesType
unifi_get_overviewVersion, site, device health, client count, WANsread
unifi_list_devices / unifi_get_deviceGateways, switches and APs with live statisticsread
unifi_list_clientsConnected, all or blocked clients; search by name, vendor, IP or partial MAC; live download/upload rates; sort by trafficread
unifi_get_clientEvery field the controller has for one deviceread
unifi_list_flows / unifi_get_flowTraffic flow logs: who connected to what, allowed or blocked, by which policy; filter by time, device, IP, port, domain, country or riskread
unifi_traffic_by_appData usage by app and by device over hours to a month; who uses an app; what one device usesread
unifi_wan_usageInternet totals, average Mbps and busiest interval at 5-minute, hourly or daily granularityread
unifi_lookup_dpiDPI application and category names by ID, or search by nameread
unifi_flow_topTop-N flows grouped by source IP, country, port, client, domain or policy, with a breakdownread
unifi_list_port_forwards / unifi_wan_healthPort-forward rules; internet status, latency, availability, speed test and gateway loadread
unifi_flow_statisticsTop clients, destinations, apps and blocking policies per hour, day, week or monthread
unifi_list_networks / unifi_list_wifiVLANs, subnets and SSIDsread
unifi_list_firewall_zonesZones and the networks in eachread
unifi_list_firewall_policies / unifi_get_firewall_policyPolicies with human-readable source, destination, protocol and actionread
unifi_check_reachability"Can X reach Y?" for devices, networks, IPs, domains or the internet: evaluates policies in order with schedules and isolation, and names the deciding ruleread
unifi_get_firewall_policy_orderEvaluation order for a zone pair (first match wins)read
unifi_api_getRead-only access to any other endpoint, paged, with field selectionread
unifi_block_client / unifi_unblock_clientBlock a device from the whole network, optionally until a time, or let it back onwrite
unifi_block_internetCut internet for devices while they stay on the LAN, optionally until a time (e.g. 06:00)write
unifi_list_scheduled_actions / unifi_cancel_scheduled_actionSee pending timed undos; lift a block early or keep itwrite
unifi_reconnect_client / unifi_rename_clientForce a reconnect; set a friendly name or notewrite
unifi_create_firewall_policyNew policy from simple fields (IPs, CIDRs, networks, MACs, domains, countries, ports, protocol, schedule) or raw JSON; dry run supportedwrite
unifi_update_firewall_policyChange only the fields you name; dry run shows before and afterwrite
unifi_set_firewall_policy_enabled / unifi_delete_firewall_policyToggle or remove a policy (deletes return a restorable copy)write
unifi_move_firewall_policyReorder: top, bottom, or before/after another policywrite
unifi_restart_device / unifi_power_cycle_portReboot a device or power-cycle a PoE portwrite

Things to try

What's on my network right now that I don't recognise?
Which devices are using the most bandwidth right now?
What has the living-room TV been connecting to in the last hour?
What got blocked overnight, and by which policies?
Which device is using BitTorrent, and how much did it download this month?
What's our average internet bandwidth this week, and when was the busiest hour?
Which APs or switches need a firmware update?
Block the device called ESP_3A1F2C and note it as unknown.
Make sure the IoT network can't reach my main LAN, except Home Assistant on port 8123.
Block inbound traffic from CN and RU to my port-forwarded services.
Turn off the kids' iPads' internet until 6 AM.
Can the guest network reach my NAS? Can my kid's phone reach the internet right now?
Show me every firewall policy that allows traffic into Internal.
Power-cycle the camera on switch port 7.

Safety by design

Letting an AI change your firewall should make you a little nervous. These guard rails keep changes deliberate, visible and reversible.

Approval on every write

Write tools carry MCP destructiveHint annotations, so clients like Claude Code prompt before running them. The server's built-in instructions tell the agent to describe changes and confirm with you first.

Dry runs

Firewall create and update accept dryRun: true, which returns the exact request and a before/after summary without touching the console.

Audit log

Every change is appended as a JSON line to ~/.unifi-mcp/audit.log (or /data/audit.log in Docker). Deleted policies are logged in full and can be recreated.

Timed blocks undo themselves

Temporary blocks are saved with their expiry and survive restarts. If the server is down at expiry, the undo runs as soon as it is back. unifi_list_scheduled_actions shows what is pending.

Read-only mode

Set UNIFI_READ_ONLY=true and write tools aren't registered at all, so the agent can't see them, let alone call them.

System policies protected

Built-in system-defined firewall policies are refused for update and delete. The agent is pointed to an overriding user policy instead.

Locked-down HTTP mode

Over HTTP, a bearer token of 24+ characters is mandatory, browser origins are rejected by default, and the Docker port binds to localhost unless you choose otherwise.

Get started

You need a UniFi console running Network 10.x and Node.js 22.19+ or Docker. Setup takes about five minutes.

  1. Create an API key

    UniFi Network → Settings → Control Plane → Integrations → Create API Key.

  2. Configure

    Clone the repo, copy .env.example to .env, and set UNIFI_HOST and UNIFI_API_KEY. If blocking fails, add a local-only admin account as UNIFI_USERNAME / UNIFI_PASSWORD.

  3. Run and connect

    Pick Node or Docker below, run the connection check, and add the server to your AI client.

Build, check the connection, then let Claude Code launch the server on demand over stdio.

git clone https://github.com/SmugZombie/Unifi-MCP.git && cd Unifi-MCP
npm install && npm run build
cp .env.example .env            # fill in UNIFI_HOST and UNIFI_API_KEY
set -a; . ./.env; set +a
npm run check                   # verifies TLS, key, site, zones and blocking access
claude mcp add unifi \
  -e UNIFI_HOST=https://192.168.1.1 \
  -e UNIFI_API_KEY=your-key \
  -e UNIFI_VERIFY_TLS=false \
  -- node "$PWD/dist/index.js"

Self-signed certificate: UniFi consoles ship with one. Either point UNIFI_CA_CERT at the console's exported certificate, or set UNIFI_VERIFY_TLS=false on a network you trust.

FAQ and troubleshooting

The issues people actually hit.

Which UniFi versions are supported?

It's built against the UniFi Network 10.6.106 API on UniFi OS 5.x, and should work on any Network 10.x release with the zone-based firewall. The OpenAPI spec it targets is included in the repo under docs/.

Do I need a username and password, or is the API key enough?

Usually just the key. Many consoles accept the API key on the internal API used for blocking. Run npm run check: if the "Internal API" step fails, add a local-only admin account. Don't use your Ubiquiti cloud login; MFA will break it.

The Docker container can't reach my console, but my computer can.

This is almost always a Docker network whose subnet overlaps your LAN. Once Docker runs out of 172.x ranges it starts handing out 192.168.x.0/20 networks, and one of them may cover your console's address. Check with:

for n in $(docker network ls -q); do
  docker network inspect -f '{{.Name}} {{range .IPAM.Config}}{{.Subnet}} {{end}}' $n
done

Fix it by setting default-address-pools in Docker's daemon settings to a range clear of your LAN, then recreating the overlapping network, or run the server with Node instead.

Why didn't my new block rule take effect?

Policies are evaluated per source→destination zone pair, and the first match wins. An existing ALLOW higher in the list will shadow a new BLOCK. Create it with position: "top" or move it with unifi_move_firewall_policy.

What's the difference between blocking a client and a firewall policy?

Blocking removes the device from the network entirely, Wi-Fi and wired. A firewall policy matching its MAC lets you restrict only some traffic, for example internet access at night, while it stays connected.

Does my network data leave my house?

The server only talks to your console. Tool results go to whichever AI client you connect, so if that client uses a cloud model, the results it reads are sent to that model provider as part of the conversation.