Skip to main content
Glama

openwrt-ubus-mcp

openwrt-ubus-mcp MCP server

openwrt-ubus-mcp lets an AI assistant manage an OpenWrt router without SSH, root, or any software installed on the router. It talks only to the router's own ubus JSON-RPC API, the one LuCI uses, as a dedicated login, so the router itself enforces what the AI may touch, through a stock rpcd ACL. Every change is previewed, applied under OpenWrt's rollback timer, and confirmed only after a fresh login proves the router still answers, so a bad firewall rule reverts itself instead of locking you out. Wi-Fi keys and passwords are redacted before anything leaves the server.

Status: v0.1.1, December 2026, on PyPI, GHCR and the MCP Registry. MIT licensed. The engineering notebook (docs/NOTEBOOK.md) records how it was built and live-tested, including the rpcd behaviour the live tests uncovered. The story behind it, in plain words: Letting Claude manage my OpenWrt router, without giving it the keys.

What it is, and what it isn't

It is a small Python MCP server that runs on any machine that can reach the router (your laptop, a home server, a container). It offers read tools for the router's state and a few narrow write tools: DHCP static leases, port forwards and firewall traffic rules.

It isn't a remote shell, a firmware or package manager, or a general UCI editor. It can't touch interfaces, the WAN or wireless settings, and it can't reboot the router. That is on purpose (see Limits). It is not affiliated with the OpenWrt project.

Related MCP server: OpenWrt MCP Controller

The safety model

  1. ubus only. The server speaks rpcd's JSON-RPC over HTTP(S) at /ubus. There is no SSH session, no shell, and no file or exec call anywhere in the code.

  2. The router enforces the limits. The server logs in as its own rpcd user. The ACL (rpcd/acl.d/openwrt-ubus-mcp.json) allows a short list of read calls, plus UCI writes to the dhcp and firewall configs only. A bug in this server, or a confused AI, can't widen that: rpcd refuses anything else. Without the write group the login is read-only.

  3. Preview, then confirm. Every write tool first returns the exact UCI changes it would make and leaves nothing staged. Only a second call with confirm: true applies them. Clients that show tool calls put that preview in front of you.

  4. Changes undo themselves. A confirmed change is applied with uci apply and the rollback timer armed (30 s). The server waits for services to settle (5 s), checks that a fresh login still works, and only then sends uci confirm. If the router stops answering, nothing confirms the change and the router restores the old config on its own. The server watches until it has, and reports rolled_back.

  5. Only its own entries. Sections the server creates are named mcp_* in UCI, and its firewall entries show in LuCI as mcp:<name>. The remove tools refuse anything else unless you pass force: true.

  6. Secrets stay on the router. Wi-Fi keys, PSKs, passwords and private keys are shown as *** in tool output and in the server's own logs, matched both by option name and by value. Tests enforce it, and the live check compares every output against the router's real secrets.

Before

Applied, not confirmed (+10 s)

Rolled back by the router (+45 s)

LuCI Traffic Rules before the test

The disabled test rule mcp:rollback-test at the bottom of the list

The same list after the router's rollback

The rollback test in LuCI's Traffic Rules. The server added a disabled rule, mcp:rollback-test, so it changed nothing, and deliberately didn't confirm it. The router removed it by itself 30 s after apply. The "before" and "after" images are byte-identical files. More screenshots.

Tools

Read

router_info

model, firmware, kernel, uptime, load, memory

interfaces

lan/wan/...: up, protocol, device, addresses, gateway, DNS

dhcp_leases

active DHCPv4 and DHCPv6 leases

wifi_status

each radio: SSID, channel, TX power, signal, encryption

wifi_clients

associated stations with signal and rates, named from the DHCP leases

firewall_config

zones, forwardings, rules and port forwards

uci_show

one of network, dhcp, firewall, system, wireless

system_log

the last lines of the log, optionally filtered

pending_changes

anything staged in the server's session (normally nothing)

Write (preview, then confirm: true)

static_lease_add / static_lease_remove

DHCP static leases (MAC, IPv4 address in the LAN subnet, hostname)

port_forward_add / port_forward_remove

port forwards (firewall redirect, DNAT)

firewall_rule_add / firewall_rule_remove

traffic rules (ACCEPT, DROP or REJECT; IPv4, IPv6 or both)

Inputs are checked before anything is staged: MAC addresses, hostnames, port ranges and zones. A lease's IP must be inside the LAN subnet (not the network, broadcast or router address), and its MAC, IP and name must not already be in use.

1. Set up the router (once)

You need rpcd and uhttpd-mod-ubus, which come with LuCI on stock OpenWrt images. Copy the rpcd folder to the router and run the installer there:

scp -O -r rpcd root@192.168.1.1:/tmp/
ssh -t root@192.168.1.1 sh /tmp/rpcd/install.sh --write

It asks for a password (12 characters or more) and stores only its hash, made with uhttpd -m. It installs the ACL and creates one rpcd login named mcp. Leave out --write for a read-only login. Running it again updates the same login, removing any duplicates, instead of adding another.

It also lists the ACL file in /etc/sysupgrade.conf. A firmware upgrade keeps /etc/config/rpcd (the login) but not files added under /usr/share, so without that line the login would survive an upgrade with no permissions at all. Tested with real upgrades: with the line the ACL is kept; without it, it is lost.

Things that trip people up:

  • scp -O is needed because OpenWrt's dropbear has no SFTP server.

  • Copy to /tmp/ as shown, not to a named folder: when the target folder already exists, a second scp -r puts the files one level deeper and you'd run the old copy.

  • The installer restarts rpcd, which logs everyone out of LuCI. Just log in again.

To undo it, run ssh root@192.168.1.1 sh /tmp/rpcd/uninstall.sh. It removes the login, the ACL and its sysupgrade.conf line, and lists any mcp_* entries still in dhcp or firewall so you can remove them too. If you'd rather set it up by hand, rpcd/login.example shows the login section.

2. Run the server

Settings come from environment variables (see example.env):

Variable

Default

OPENWRT_URL

http://192.168.1.1/ubus

the router's ubus endpoint; https:// works too

OPENWRT_USER

mcp

OPENWRT_PASSWORD

required

OPENWRT_VERIFY_TLS

true

false, or a CA file, for a self-signed router certificate

OPENWRT_ROLLBACK_TIMEOUT

30

seconds before an unconfirmed change is rolled back

OPENWRT_SETTLE_SECONDS

5

wait after apply before the check (0 to 20)

MCP_TRANSPORT

stdio

or http (streamable HTTP)

MCP_HTTP_BIND / MCP_HTTP_PORT

127.0.0.1 / 8765

HTTP only

MCP_BEARER_TOKEN

required for HTTP

MCP_HTTP_ALLOWED_HOSTS

extra Host names accepted over HTTP, e.g. example-host

stdio, started by your MCP client

With uv there is nothing to install first:

claude mcp add openwrt -e OPENWRT_PASSWORD=your-password -- uvx openwrt-ubus-mcp

Or with pip:

pip install openwrt-ubus-mcp
claude mcp add openwrt -e OPENWRT_PASSWORD=your-password -- openwrt-ubus-mcp

Add -e OPENWRT_URL=https://192.168.1.1/ubus if your router isn't at the default address. Other clients use the same command and environment in their own config format.

HTTP, as a service (Docker)

Run it on one machine and point several clients at it, protected by a bearer token:

docker run -d --name openwrt-ubus-mcp --network host --restart unless-stopped \
  -e OPENWRT_PASSWORD=your-password -e MCP_BEARER_TOKEN=your-long-random-token \
  -e MCP_HTTP_BIND=192.168.1.10 -e MCP_HTTP_ALLOWED_HOSTS=example-host \
  ghcr.io/kk4hfj/openwrt-ubus-mcp

claude mcp add --transport http openwrt http://example-host:8765/mcp \
  --header "Authorization: Bearer your-long-random-token"

compose.yaml does the same from a .env file, with a read-only filesystem and no Linux capabilities. Bind to a private address (a VPN interface is ideal), never to 0.0.0.0 on an untrusted network. Make a token with openssl rand -hex 32.

How it compares

OpenWrt MCP servers broadly come in three kinds:

  • SSH-based servers log in from your machine and run commands. They can do anything the login can, and their limits live in the server's own code.

  • On-router servers install their own daemon on the router, with its own policy engine and audit log, and usually reach the client over an SSH tunnel. They can cover far more of the router (packages, upgrades, any ubus call) than this one does.

  • API-based servers use a REST API that has to be installed on the router first.

This one sits in a narrow spot: nothing to install on the router (one JSON file and one login), no SSH at all, and limits that rpcd enforces, the same mechanism that already guards LuCI. The price is scope: it only does what the ACL and its few typed tools allow. If you want an agent that can explore and change anything on the router, one of the others will suit you better.

Limits

  • No interfaces, WAN, wireless writes, VLANs or bridges. A wrong change there can cut off the machine the server runs on, and recovery would rest entirely on the rollback timer. Wireless status is read-only.

  • No reboot, packages, upgrades or shell. The ACL doesn't allow them.

  • IPv4 for leases and port forwards. DHCPv6 leases are shown but not managed.

  • One router per server. Run one instance per router.

  • Rollback restores the router's config, not what happened meanwhile. It can't undo what a client did during the 30 s window.

Tested versions

OpenWrt

Result

25.12.6

Tested live on a real router: install.sh, every read tool, adding and removing a lease, a port forward and a rule, and the forced rollback (4 runs).

24.10.8

Tested in a KVM virtual machine (the official armsr-armv8 image, no Wi-Fi): install.sh (twice, with one login left), every read tool, adding and removing a lease, and the forced rollback. rpcd behaves the same as on 25.12.

Reports for other versions are welcome as issues.

Roadmap

openwrt-ubus-mcp is meant to become the control layer of a small fleet console: many routers, staged rollouts that stop at the first failure, health monitoring, and token enrollment. That console is planned, not built. See the executive summary and the whitepaper.

Development

python -m venv .venv && .venv/bin/pip install -e '.[test]'
.venv/bin/pytest                                  # fake ubus and BusyBox ash, no router needed
OPENWRT_LIVE=1 python scripts/live_check.py       # read tools against a real router
OPENWRT_LIVE=1 python scripts/rollback_proof.py   # the rollback proof (adds a disabled rule)

The fake ubus models rpcd's sessions, ACL refusals, per-session staging, and apply with a rollback timer, including rpcd putting rolled-back changes back into the applying session. It runs on a test clock. Each safety rule was mutation-checked: break it and a test fails. The router scripts are tested under BusyBox ash with a stand-in uci.

License

MIT. See LICENSE.

Available Tools

15 tools
dhcp_leasesA
Read-onlyIdempotent

Active DHCPv4 and DHCPv6 leases: hostname, IP, MAC and time left (as LuCI shows them).

Inputs: no named parameters. Returns: object

firewall_configA
Read-onlyIdempotent

Firewall UCI config grouped as defaults, zones, forwardings, rules and redirects (port forwards).

Inputs: no named parameters. Returns: object

firewall_rule_addA
Destructive

Add a traffic rule. src/dest: zone names or "*" (dest omitted = traffic to the router itself). target: ACCEPT, REJECT or DROP. proto: tcp, udp, "tcp udp", icmp or all. family: ipv4, ipv6 or any. Without confirm=true this only returns a preview of the UCI changes and changes nothing. With confirm=true it applies them with the router's rollback timer, checks the router still answers, and confirms; if the check fails, the router restores the old config by itself.

Inputs: src (required), name (required), dest, proto, +7 more. Returns: object

firewall_rule_removeA
Destructive

Remove a firewall rule, by section id or name. Only ones this server created unless force=true. Without confirm=true this only returns a preview of the UCI changes and changes nothing. With confirm=true it applies them with the router's rollback timer, checks the router still answers, and confirms; if the check fails, the router restores the old config by itself.

Inputs: name, force, confirm, section. Returns: object

interfacesC
Read-onlyIdempotent

Logical network interfaces (lan, wan ...): up/down, protocol, device, addresses, gateway, DNS.

Inputs: no named parameters. Returns: object

pending_changesA
Read-onlyIdempotent

UCI changes this server has staged but not applied (normally none: every tool cleans up).

Inputs: no named parameters. Returns: object

port_forward_addA
Destructive

Forward a port (or range like 8000-8010) from the src zone (default wan) to a LAN host. proto: tcp, udp or "tcp udp". dest_port defaults to src_dport. Without confirm=true this only returns a preview of the UCI changes and changes nothing. With confirm=true it applies them with the router's rollback timer, checks the router still answers, and confirms; if the check fails, the router restores the old config by itself.

Inputs: name (required), dest_ip (required), src_dport (required), src, +5 more. Returns: object

port_forward_removeA
Destructive

Remove a port forward, by section id or name. Only ones this server created unless force=true. Without confirm=true this only returns a preview of the UCI changes and changes nothing. With confirm=true it applies them with the router's rollback timer, checks the router still answers, and confirms; if the check fails, the router restores the old config by itself.

Inputs: name, force, confirm, section. Returns: object

router_infoB
Read-onlyIdempotent

Router model, firmware release, kernel, uptime, load and memory (ubus system board/info).

Inputs: no named parameters. Returns: object

static_lease_addA
Destructive

Reserve an IPv4 address for a device (a DHCP static lease). mac: aa:bb:cc:dd:ee:ff; ip: a free address in the LAN; name: a hostname (letters, digits, hyphens). Without confirm=true this only returns a preview of the UCI changes and changes nothing. With confirm=true it applies them with the router's rollback timer, checks the router still answers, and confirms; if the check fails, the router restores the old config by itself.

Inputs: ip (required), mac (required), name (required), confirm. Returns: object

static_lease_removeA
Destructive

Remove a static lease, by section id (see uci_show dhcp) or by MAC. Only leases this server created are removed unless force=true. Without confirm=true this only returns a preview of the UCI changes and changes nothing. With confirm=true it applies them with the router's rollback timer, checks the router still answers, and confirms; if the check fails, the router restores the old config by itself.

Inputs: mac, force, confirm, section. Returns: object

system_logA
Read-onlyIdempotent

The last lines lines of the system log (1-1000, default 100). With contains, only the lines containing that text (case-insensitive), searched in the last 1000.

Inputs: lines, contains. Returns: object

uci_showA
Read-onlyIdempotent

One UCI config as a list of sections. config: network, dhcp, firewall, system or wireless. Secret options (key, password, psk ...) are shown as ***.

Inputs: config (required). Returns: object

wifi_clientsA
Read-onlyIdempotent

Associated Wi-Fi stations on every radio, with signal, rates, and hostname/IP from DHCP.

Inputs: no named parameters. Returns: object

wifi_statusC
Read-onlyIdempotent

Each Wi-Fi interface: SSID, mode, channel, frequency, TX power, signal/noise, encryption type.

Inputs: no named parameters. Returns: object

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 15 tools

    Disambiguation4/5

    Most tools have clearly distinct targets: DHCP leases, Wi-Fi status, Wi-Fi clients, interfaces, firewall config, and router info are separable. The main overlap is that uci_show exposes raw configs that partially duplicate firewall_config, interfaces, and DHCP lease views, but its generic raw-UCI purpose is still clear.

    Naming Consistency3/5

    All names use snake_case, but there are mixed conventions: read tools are noun phrases such as wifi_status and router_info, while mutating tools use entity_action order such as static_lease_add and port_forward_remove. The pattern is readable and semantically grouped, but it is not a single predictable verb_noun convention.

    Tool Count5/5

    Fifteen tools is well-scoped for a router-management MCP server, with a balanced set of read-only inspection tools and paired add/remove operations. Each tool appears to earn its place without excessive surface area.

    Completeness4/5

    The set covers the core lifecycle well: inspect router/network/Wi-Fi/firewall state, add and remove static leases, port forwards, and firewall rules, with preview/confirm safety. Minor gaps remain, such as updating existing rules or leases in place and broader Wi-Fi or DHCP server configuration changes.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers