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?
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:
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.
- 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.
- 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.
- 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.
- 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.
| Capability | API | Auth |
|---|---|---|
| Devices, networks, Wi-Fi, firewall zones and policies, policy ordering, device restart, PoE power-cycle | Official Network API/proxy/network/integration/v1 | API key |
| Client search including offline clients, block, unblock, reconnect, rename | Internal 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 client | Internal 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.
| Tool | What it does | Type |
|---|---|---|
unifi_get_overview | Version, site, device health, client count, WANs | read |
unifi_list_devices / unifi_get_device | Gateways, switches and APs with live statistics | read |
unifi_list_clients | Connected, all or blocked clients; search by name, vendor, IP or partial MAC; live download/upload rates; sort by traffic | read |
unifi_get_client | Every field the controller has for one device | read |
unifi_list_flows / unifi_get_flow | Traffic flow logs: who connected to what, allowed or blocked, by which policy; filter by time, device, IP, port, domain, country or risk | read |
unifi_traffic_by_app | Data usage by app and by device over hours to a month; who uses an app; what one device uses | read |
unifi_wan_usage | Internet totals, average Mbps and busiest interval at 5-minute, hourly or daily granularity | read |
unifi_lookup_dpi | DPI application and category names by ID, or search by name | read |
unifi_flow_top | Top-N flows grouped by source IP, country, port, client, domain or policy, with a breakdown | read |
unifi_list_port_forwards / unifi_wan_health | Port-forward rules; internet status, latency, availability, speed test and gateway load | read |
unifi_flow_statistics | Top clients, destinations, apps and blocking policies per hour, day, week or month | read |
unifi_list_networks / unifi_list_wifi | VLANs, subnets and SSIDs | read |
unifi_list_firewall_zones | Zones and the networks in each | read |
unifi_list_firewall_policies / unifi_get_firewall_policy | Policies with human-readable source, destination, protocol and action | read |
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 rule | read |
unifi_get_firewall_policy_order | Evaluation order for a zone pair (first match wins) | read |
unifi_api_get | Read-only access to any other endpoint, paged, with field selection | read |
unifi_block_client / unifi_unblock_client | Block a device from the whole network, optionally until a time, or let it back on | write |
unifi_block_internet | Cut 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_action | See pending timed undos; lift a block early or keep it | write |
unifi_reconnect_client / unifi_rename_client | Force a reconnect; set a friendly name or note | write |
unifi_create_firewall_policy | New policy from simple fields (IPs, CIDRs, networks, MACs, domains, countries, ports, protocol, schedule) or raw JSON; dry run supported | write |
unifi_update_firewall_policy | Change only the fields you name; dry run shows before and after | write |
unifi_set_firewall_policy_enabled / unifi_delete_firewall_policy | Toggle or remove a policy (deletes return a restorable copy) | write |
unifi_move_firewall_policy | Reorder: top, bottom, or before/after another policy | write |
unifi_restart_device / unifi_power_cycle_port | Reboot a device or power-cycle a PoE port | write |
Things to try
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.
- Create an API key
UniFi Network → Settings → Control Plane → Integrations → Create API Key.
- Configure
Clone the repo, copy
.env.exampleto.env, and setUNIFI_HOSTandUNIFI_API_KEY. If blocking fails, add a local-only admin account asUNIFI_USERNAME/UNIFI_PASSWORD. - 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 accessclaude 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"Runs as a long-lived HTTP service at /mcp, protected by a bearer token and published on localhost only.
cp .env.example .env # fill in UNIFI_* settings
echo "MCP_AUTH_TOKEN=$(openssl rand -hex 32)" >> .env
docker compose up -d --build
docker compose run --rm unifi-mcp dist/check.jsclaude mcp add --transport http unifi http://127.0.0.1:3000/mcp \
--header "Authorization: Bearer $(grep '^MCP_AUTH_TOKEN=' .env | cut -d= -f2)"Add to ~/Library/Application Support/Claude/claude_desktop_config.json and restart Claude Desktop.
{
"mcpServers": {
"unifi": {
"command": "node",
"args": ["/path/to/Unifi-MCP/dist/index.js"],
"env": {
"UNIFI_HOST": "https://192.168.1.1",
"UNIFI_API_KEY": "your-key",
"UNIFI_VERIFY_TLS": "false"
}
}
}
}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
doneFix 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.