Skip to main content

openwrt-ubus-mcp

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.0, December 2026. MIT licensed. The engineering notebook (docs/NOTEBOOK.md) records how it was built and live-tested, including the rpcd behaviour the live tests uncovered.

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.

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.

Metadata

Release files for openwrt-ubus-mcp 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openwrt-ubus-mcp 0.1.1
File Size Uploaded Provenance Actions
openwrt_ubus_mcp-0.1.1.tar.gz 41.2 kB With provenance Details for openwrt_ubus_mcp-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openwrt-ubus-mcp 0.1.1
File Interpreter ABI Platform Actions
openwrt_ubus_mcp-0.1.1-py3-none-any.whl Python 3 none any Details for openwrt_ubus_mcp-0.1.1-py3-none-any.whl

Total release size: 67.6 kB

Release files / openwrt_ubus_mcp-0.1.1.tar.gz

Download URL openwrt_ubus_mcp-0.1.1.tar.gz
Size 41.2 kB
Tags Source
SHA-256 checksum
How to use checksums
96851fe39a2c997a027de15520b772117b617497093ce0d4bdf7daf7d1f04b3c
BLAKE2b-256 checksum
How to use checksums
72087481f5b8b222934b0f1612dc688a52af56d6403bc67f8ee097775af78a4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / openwrt_ubus_mcp-0.1.1-py3-none-any.whl

Download URL openwrt_ubus_mcp-0.1.1-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfc945413f4413d1b91e1cad731f1c042ca1be4a27a4ed17237e7b323f3f5f1f
BLAKE2b-256 checksum
How to use checksums
67bf00ad6dda0dee5285e1d859cf25e6992937abd8ec0d82e686f8fdf0b11c0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for openwrt-ubus-mcp 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for openwrt_ubus_mcp-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page