r/openwrt • • 20h ago

uapi: v4, an MCP server for AI agents, and a package PR for OpenWrt

7 Upvotes

Three months ago I posted uapi 3.0 here.

uapi is a REST API for OpenWrt. It runs as a uhttpd-mod-ucode handler and maps HTTP to ubus and uci, with no extra daemon.

I recently released new major v4 which targets next OpenWRT major release. It is also compatible with current snapshot.

What changed in v4:

  • A read gives the value that netifd, fw4, dnsmasq, wifi-scripts or mwan3 applies, and each field reads one type. For example, the disabled option of an interface reads true for a stored true, as netifd reads it.
  • A write is refused while its section holds a value that the daemon refuses, as LuCI refuses a save. A stored value that the daemon accepts does not block a write.
  • The API moves to /api/v4. The endpoints of uapi itself move under /uapi/: tokens, batch, metrics and diagnostics. POST /batch is now POST /uapi/batch.
  • On OpenWrt main, the openvpn package runs a tunnel as a netifd protocol. So openvpn becomes a proto of network/interfaces.
  • dhcp/leases gives the DHCPv4 and the DHCPv6 leases, and reads the DHCPv6 leases from odhcpd over ubus.
  • sqm/queues models the options of the LuCI SQM form.
  • POST /uapi/services/{name}/recover starts a service again after procd gave up on it.

These are breaking changes. The migration guide lists each change and what a client must do: https://github.com/openwrt-iac/uapi/blob/main/docs/migration-v3-to-v4.md

The current version is 4.0.1.

Why 4.x needs OpenWrt main:

On OpenWrt main, netifd accepts true for the disabled option of an interface. The netifd of 25.12 does not. uapi 4.x reads that option the way the netifd of main reads it, so the package depends on netifd 2026.07.17 or later. Today that means snapshots. The next stable release, cut from main, will have it too.

On 25.12, the feed keeps 3.5.0. Install it with apk add 'uapi<4'. apk does not fall back to an older version on its own, so a plain apk add uapi fails there.

The provider follows the same major. Version 4.0.0 is on both registries, under the same name, openwrt-iac/uapi. Its endpoint now ends with /api/v4.

terraform {
  required_providers {
    uapi = {
      source  = "openwrt-iac/uapi"
      version = "~> 4.0"
    }
  }
}

The new member of the family: uapi-mcp

uapi-mcp is an MCP server. It lets an AI agent, such as Claude Code or OpenCode, read and change a router through uapi.

  • It has one tool per endpoint and method, 258 in all. A generator makes them from the OpenAPI specification of uapi, so the tools follow the API.
  • It does not expose /raw/. Raw payloads use the option names of uci and have no stability promise across OpenWrt releases.
  • A write returns what uci holds now, with the X-Reload-* and X-Kernel-* headers of uapi. If a write leaves a daemon down, the agent sees it, and the instructions of the server tell it what to do.
  • An error returns the error envelope of uapi field by field, so the agent can correct all fields in one round trip.
  • It is one Go binary for Linux, macOS, Windows and FreeBSD. It reads three environment variables: UAPI_ENDPOINT, UAPI_TOKEN and UAPI_INSECURE.

Give it a token with only the scopes that the agent needs. uapi-token create --name agent --scope '*:ro' makes a token that can read and cannot write. uapi-mcp 4.x needs uapi 4.x. For a router on 3.5.0, use uapi-mcp 3.5.

uapi in OpenWrt:

I opened a PR to add uapi to openwrt/packages and one to add luci-app-uapi to openwrt/luci. A packages maintainer tested an earlier version with good results, and the PR now carries 4.0.1. It is not merged yet, but I expect uapi to be in the official feed of the next stable release. Then apk add uapi will work with no third-party feed and no extra key.

4.x will be the first major of uapi in the official feed. From there, I will maintain the major of uapi that each supported OpenWrt release carries.

To install it on your router now:

Requirements: OpenWrt main for 4.x, or OpenWrt 25.12 for 3.5.0. The package is architecture independent.

uclient-fetch -qO /etc/apk/keys/uapi-feed.pub.pem \
    https://openwrt-iac.github.io/feed/uapi-feed.pub.pem
echo 'https://openwrt-iac.github.io/feed/packages/all/uapi/packages.adb' \
    > /etc/apk/repositories.d/uapi.list
apk update
apk upgrade uhttpd uhttpd-mod-ubus uhttpd-mod-ucode uhttpd-mod-lua
apk add uapi        # OpenWrt main
apk add 'uapi<4'    # OpenWrt 25.12

uhttpd and its plugins must come from the same build, and the package feed of OpenWrt is newer than the image. This is why the apk upgrade line is there. luci-app-uapi is in the same feed.

Source and documentation: https://github.com/openwrt-iac/uapi

Thanks for your attention.