Skip to main content
Glama

OpenWrt LuCI HTTP MCP

标准 OpenWrt LuCI Web 界面的只读 MCP 表达,通过 LuCI 原生 POST /ubus/ JSON-RPC 接口读取状态和运行其诊断页中的固定命令,不使用 SSH,也不在路由器上安装代理。

当前版本:0.4.0。以 OpenWrt 25.12.3 / LuCI openwrt-25.12 为 ground truth;可选方法不存在时返回明确的 supported: false,不会把权限或认证错误误报为不支持。

安全范围

  • 使用现有 LuCI root 登录,不创建新账户。

  • 密码只从环境变量读取,不写入源码或日志。

  • 不注册任意 ubus 调用、任意 shell、重启、固件升级或 UCI 写入工具。

  • ip、nft、dmesg、软件目录和网络诊断只执行代码中写死的程序与参数结构;不经过 shell。

  • 网络诊断只允许经过校验的目标,Ping 次数、Traceroute 超时和跳数均不可由调用者改变。

  • 返回给模型前隐藏密码、PSK、community、令牌、会话标识、私钥、HTTP Authorization 和 URL 内嵌认证材料。

  • 单次 LuCI 响应限制为 2 MiB,单个 MCP 结果限制为 256 KiB;超限返回有效 JSON 错误而非截断内容。

这只是 Demo。root 密码通过普通 HTTP 发送时没有传输加密,只应在可信 LAN 中临时测试。长期使用应开启 LuCI HTTPS,并改为受限 rpcd 账户。

Related MCP server: openwrt-mcp

环境要求

  • Node.js 20 或更高版本

  • OpenWrt/LuCI 可通过局域网访问

  • uhttpd-mod-ubus 与 rpcd 正常工作

安装

cd C:\absolute\path\to\openwrt-luci-mcp-demo
npm install

不要复制 .env.example 后把真实密码提交到 Git。推荐直接在 MCP 客户端的进程环境中设置变量:

OPENWRT_URL=http://router.example.invalid
OPENWRT_USERNAME=root
OPENWRT_PASSWORD=<LuCI root 密码>
OPENWRT_ALLOW_INSECURE_HTTP=1

OPENWRT_ALLOW_INSECURE_HTTP=1 是显式风险确认。若 LuCI 已启用 HTTPS,请使用 https://... 并删除该变量。

运行

npm start

stdio 是 MCP 协议通道;程序日志只写入 stderr。通常由 MCP 客户端启动本程序,而不是手动交互。

参考 mcp-config.example.json 配置客户端,并把其中的 Node 与 src/index.mjs 路径改为绝对路径。

工具

  • router_capabilities

  • router_luci_pages

  • router_system_info

  • router_interfaces

  • router_interface_details

  • router_routing_config

  • router_network_device

  • router_port_status

  • router_vlan_config

  • router_dhcp_leases

  • router_dhcp_config

  • router_dns_config

  • router_known_hosts

  • router_wifi_overview

  • router_wifi_details

  • router_wifi_clients

  • router_services

  • router_processes

  • router_realtime_stats

  • router_routes

  • router_neighbors

  • router_firewall_status

  • router_firewall_config

  • router_nftables_rules

  • router_wifi_scan

  • router_logs

  • router_connections

  • router_storage

  • router_packages

  • router_package_catalog

  • router_time_status

  • router_system_settings

  • router_network_diagnostics

  • router_network_consistency

  • router_run_diagnostic

  • router_security_audit

  • router_client_summary

每个工具同时返回兼容的文本 JSON 和 MCP structuredContent。路由、DHCP/DNS、Firewall、VLAN、大型规则和软件目录使用 offset、limit 分页。

v0.4.0 增加 LuCI 网络配置控制面的只读表达:静态路由与策略规则、dnsmasq/odhcpd、DNS 记录、Firewall 关系、DSA/swconfig VLAN、基础 System 设置,以及配置与运行态一致性检查。工具只读取已提交配置;不会读取其他 LuCI 会话中尚未应用的 UCI 暂存变更。

router_network_diagnostics 只分析现有状态。router_run_diagnostic 对应 LuCI Network → Diagnostics 页面,会产生 Ping、Traceroute 或 DNS 流量,但不修改配置。router_package_catalog 只调用 LuCI package manager 的 list-installed 和 list-available,不更新软件源。

LuCI 页面覆盖

LuCI 页面

MCP 工具

状态

Status → Overview

router_system_info, router_interfaces, router_port_status, router_dhcp_leases, router_wifi_details

supported

Status → Realtime Graphs

router_realtime_stats

supported

Status → Routes

router_routes, router_neighbors

supported

Status → System Log

router_logs

supported

Status → Processes

router_processes

supported

Status → Firewall

router_firewall_status, router_nftables_rules

supported

Network → Interfaces

router_interfaces, router_interface_details

supported

Network → Switch/VLAN

router_vlan_config, router_port_status

supported/conditional

Network → Wireless

router_wifi_overview, router_wifi_details, router_wifi_clients, router_wifi_scan

supported

Network → Routing

router_routing_config, router_routes

supported

Network → DHCP

router_dhcp_config, router_dhcp_leases

supported

Network → DNS

router_dns_config

supported

Network → Diagnostics

router_network_diagnostics, router_run_diagnostic

supported

Network → Firewall Configuration

router_firewall_config, router_firewall_status

supported

System → System

router_system_settings, router_time_status

supported

System → Software

router_packages, router_package_catalog

supported

System → Mount Points

router_storage

supported

同一矩阵可由 router_luci_pages 读取。Switch/VLAN 仅在 DSA bridge-vlan 或旧 swconfig 配置存在时支持。WireGuard、SQM、UPnP 等可选 LuCI 应用不在 v0.4.0 范围内。

没有提供以下能力:

uci.set / uci.delete / uci.apply
任意 file.exec / file.write / file.remove
system.reboot
luci.setPassword
hostapd.*.del_client

测试

27 项测试使用本机模拟 /ubus/ 服务,不连接或修改真实路由器:

npm test

一次性真实连接检查

在 PowerShell 中使用安全密码提示,不把密码写入文件:

$secure = Read-Host 'LuCI root password' -AsSecureString
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try {
  $env:OPENWRT_PASSWORD = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr)
  $env:OPENWRT_URL = 'http://router.example.invalid'
  $env:OPENWRT_USERNAME = 'root'
  $env:OPENWRT_ALLOW_INSECURE_HTTP = '1'
  npm run check:live
}
finally {
  [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr)
  Remove-Item Env:OPENWRT_PASSWORD -ErrorAction SilentlyContinue
}

该检查只调用 system.board、system.info 和 luci.getVersion。

目标路由器核验范围

通过已登录 LuCI 页面确认以下模块在目标路由器上存在且可正常读取,没有出现 RPC access denied:

  • 活动 IPv4/IPv6 路由、策略规则和邻居表

  • nftables fw4 运行时状态

  • 系统日志

  • Wi-Fi 信道分析

  • 软件包管理器

  • 网络诊断

  • 静态路由、DHCP/DNS 与 Firewall 配置

  • DSA/bridge-vlan 与基础 System 设置

实现方法与 OpenWrt 25.12 使用的 LuCI/rpcd 接口保持一致;若将来更换固件或裁剪 LuCI 软件包,可调用 router_capabilities 和 router_luci_pages 核对实际支持情况。

Available Tools

30 tools
router_capabilitiesA
Read-onlyIdempotent

List method signatures for the read-only ubus objects allowed by this MCP server.

Inputs: no named parameters.

router_client_summaryA
Read-onlyIdempotent

Merge DHCP leases, LuCI host hints, and Wi-Fi associations into one client inventory.

Inputs: no named parameters.

router_connectionsA
Read-onlyIdempotent

Get a bounded snapshot of active conntrack entries.

Inputs: limit.

router_dhcp_leasesA
Read-onlyIdempotent

Get current DHCPv4 and DHCPv6 leases.

Inputs: no named parameters.

router_firewall_statusA
Read-onlyIdempotent

Get a read-only summary of firewall defaults, zones, forwardings, redirects, and rules from UCI.

Inputs: no named parameters.

router_interface_detailsA
Read-onlyIdempotent

Get the read-only LuCI interface status view for one logical interface.

Inputs: interface (required).

router_interfacesA
Read-onlyIdempotent

Get the current status of all logical network interfaces.

Inputs: no named parameters.

router_known_hostsA
Read-onlyIdempotent

Get LuCI host hints that correlate hostnames, IP addresses, and MAC addresses.

Inputs: no named parameters.

router_logsA
Read-onlyIdempotent

Read a bounded tail of system or kernel logs. Kernel access uses only the fixed command /bin/dmesg -r.

Inputs: source (required), lines.

router_luci_pagesA
Read-onlyIdempotent

List the standard LuCI pages represented by this MCP server and their implementation status.

Inputs: no named parameters.

router_neighborsA
Read-onlyIdempotent

Get the current IPv4 ARP and IPv6 NDP neighbor tables using two fixed read-only ip commands.

Inputs: no named parameters.

router_network_deviceB
Read-onlyIdempotent

Get status and counters for one network device such as eth0 or br-lan.

Inputs: name (required).

router_network_diagnosticsA
Read-onlyIdempotent

Perform passive diagnostics of WAN state, addressing, DNS, default routes, uptime, and Wi-Fi without sending probes.

Inputs: no named parameters.

router_nftables_rulesA
Read-onlyIdempotent

Get a filtered, paginated read-only view of the active nftables rules, sets, maps, and counters.

Inputs: chain, limit, table, family, +1 more.

router_package_catalogA
Read-onlyIdempotent

Browse the installed and available package catalog shown by LuCI without updating, installing, or removing packages.

Inputs: limit, query, scope, offset.

router_packagesA
Read-onlyIdempotent

Search the installed/world package list and return a bounded result.

Inputs: limit, query.

router_port_statusA
Read-onlyIdempotent

Get the LuCI overview port table with bridge/VLAN, link, counters, zones, and optional PoE state.

Inputs: no named parameters.

router_processesA
Read-onlyIdempotent

Get a bounded snapshot of running processes.

Inputs: limit.

router_realtime_statsB
Read-onlyIdempotent

Get LuCI bandwidth, wireless, conntrack, or load samples.

Inputs: mode (required), device.

router_routesA
Read-onlyIdempotent

Get active IPv4/IPv6 routes and policy rules using fixed read-only ip commands.

Inputs: no named parameters.

router_run_diagnosticA
Read-onlyIdempotent

Run the fixed, non-configuring Ping, Traceroute, or DNS command used by the LuCI diagnostics page.

Inputs: target (required), operation (required), family.

router_security_auditA
Read-onlyIdempotent

Run a read-only audit for unsafe WAN input, management port forwards, HTTP-only LuCI, and SSH password authentication.

Inputs: no named parameters.

router_servicesA
Read-onlyIdempotent

Get procd service status. This tool cannot start, stop, or restart services.

Inputs: no named parameters.

router_storageA
Read-onlyIdempotent

Get mounted filesystems with total, available, and free byte counts.

Inputs: no named parameters.

router_system_infoA
Read-onlyIdempotent

Get board, firmware, kernel, load, memory, uptime, and LuCI version information.

Inputs: no named parameters.

router_time_statusA
Read-onlyIdempotent

Get router local time, uptime, timezone-related system configuration, and time service status.

Inputs: no named parameters.

router_wifi_clientsA
Read-onlyIdempotent

List clients associated with one wireless interface, for example phy1-ap0.

Inputs: device (required).

router_wifi_detailsA
Read-onlyIdempotent

Get the LuCI wireless status view including radio details, frequencies, and associated clients.

Inputs: device.

router_wifi_overviewA
Read-onlyIdempotent

Get configured wireless radios and networks without returning UCI secrets.

Inputs: no named parameters.

router_wifi_scanA
Read-onlyIdempotent

Scan nearby Wi-Fi networks on one interface or every interface reported by iwinfo without changing wireless configuration.

Inputs: device.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 30 tools

    Disambiguation4/5

    Most tools target distinct network/system domains (routes, neighbors, firewall, WiFi, DHCP, packages), and descriptions are precise. The only mild confusions are `router_wifi_details` vs `router_wifi_clients` and `router_network_diagnostics` vs `router_run_diagnostic`, but the descriptions make the differences clear.

    Naming Consistency5/5

    All tools share a consistent `router_` prefix and use snake_case noun phrases organized by domain. The convention is uniform; `router_run_diagnostic` introduces a verb but still follows the same overall pattern.

    Tool Count2/5

    With 30 tools, the set exceeds the practical limit for easy agent selection and includes many low-level status endpoints that could be consolidated into grouped retrieval tools. Although the domain is broad, 30 tools is too many for a cohesive MCP surface.

    Completeness5/5

    The tool surface covers all major read-only OpenWrt/LuCI domains: interfaces, routes, WiFi, firewall, logs, system stats, packages, clients, diagnostics, and security. No obvious dead ends or missing core read-only operations exist for a status/diagnostics MCP server.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers