Skip to main content
Glama

OpenWrt MCP Server

一个用于操作 OpenWrt 路由器设备的 MCP (Model Context Protocol) Server。通过 SSH 连接到路由器,提供丰富的工具集来管理和开发 OpenWrt 设备。

功能

连接管理

  • connect_router — 可通过 SSH 和serial连接到 OpenWrt 路由器

  • disconnect_router — 断开当前连接

  • connection_status — 查看连接状态

命令执行

  • run_command — 在路由器上执行任意 shell 命令

UCI 配置管理

  • uci_show — 查看 UCI 配置

  • uci_get — 获取指定配置值

  • uci_set — 设置配置值

  • uci_add — 添加匿名配置节

  • uci_delete — 删除配置节或选项

  • uci_add_list / uci_del_list — 列表操作

  • uci_commit — 提交更改(可选重启服务)

  • uci_changes — 查看未提交的更改

  • uci_revert — 撤销更改

网络管理

  • network_interfaces — 列出所有网络接口

  • network_status — 查看指定接口状态

  • wifi_status — 查看无线状态

  • wifi_scan — 扫描附近无线网络

  • connected_clients — 查看已连接客户端

  • network_restart — 重启网络服务

  • firewall_status — 查看防火墙规则

  • ping_test — 从路由器 ping 测试

  • dns_lookup — DNS 查询

  • route_table — 查看路由表

系统管理

  • system_info — 获取系统综合信息

  • system_log — 查看系统日志

  • kernel_log — 查看内核日志

  • process_list — 查看运行进程

  • service_list — 列出服务及状态

  • service_action — 管理服务(启动/停止/重启/启用/禁用)

  • system_reboot — 重启路由器

  • cron_list — 查看定时任务

文件操作

  • file_read — 读取文件内容

  • file_write — 写入文件

  • file_list — 列出目录内容

  • file_delete — 删除文件

  • file_search — 搜索文件或文件内容

  • file_chmod — 修改文件权限

包管理 (opkg)

  • opkg_update — 更新软件包列表

  • opkg_list — 列出可用/已安装软件包

  • opkg_install — 安装软件包

  • opkg_remove — 移除软件包

  • opkg_info — 查看软件包详情

  • opkg_upgradable — 列出可升级的软件包

Related MCP server: AsusWRT MCP Server

安装

npm install
npm run build

运行模式

模式一:本地 Stdio(默认)

通过标准输入输出通信,适合本机 MCP 客户端直接调用:

npm start
# 或
node dist/index.js

模式二:远程 HTTP/SSE

启动 HTTP 服务器,允许远程客户端通过 SSE 协议连接:

npm run start:http
# 或
node dist/index.js --http

环境变量:

  • MCP_PORT — 监听端口(默认 3000)

  • MCP_HOST — 监听地址(默认 0.0.0.0)

  • MCP_PASSWORD — OAuth 认证密码(默认 openwrt)

  • MCP_BASE_URL — 对外基础 URL(用于 OAuth 回调,默认自动推断)

# 示例:指定端口、地址和密码
MCP_PORT=8080 MCP_PASSWORD=mysecret node dist/index.js --http

端点说明:

  • POST /mcp — Streamable HTTP 端点(Claude Code 首选)

  • GET /sse — SSE 连接端点

  • POST /messages?sessionId=xxx — SSE 消息发送端点

  • GET /health — 健康检查

  • GET /oauth/authorize — OAuth 认证页面

  • POST /oauth/token — Token 端点

配置

在 MCP 客户端(如 Windsurf、Claude Desktop)中添加以下配置:

本地模式 — Windsurf (~/.codeium/windsurf/mcp_config.json)

{
  "mcpServers": {
    "openwrt": {
      "command": "node",
      "args": ["<项目绝对路径>/dist/index.js"]
    }
  }
}

本地模式 — Claude Desktop

{
  "mcpServers": {
    "openwrt": {
      "command": "node",
      "args": ["<项目绝对路径>/dist/index.js"]
    }
  }
}

远程模式 — 客户端 SSE 连接

先在服务器上启动 HTTP 模式:

node dist/index.js --http

然后在支持 SSE 传输的 MCP 客户端中配置:

Claude Code

claude mcp add openwrt --transport sse http://10.118.81.110:6666/sse

或编辑 ~/.claude/settings.json:

{
  "mcpServers": {
    "openwrt": {
      "type": "sse",
      "url": "http://10.118.81.110:6666/sse"
    }
  }
}

Windsurf / Claude Desktop(远程)

{
  "mcpServers": {
    "openwrt": {
      "url": "http://<服务器IP>:3000/sse"
    }
  }
}

使用示例

  1. 先连接到路由器:

    连接到我的路由器 192.168.1.1,用户名 root,密码 arcwrt

  2. 查看系统信息:

    获取路由器的系统信息

  3. 配置网络:

    把 LAN 口的 IP 改为 192.168.2.1

  4. 安装软件包:

    安装 luci-app-openclash

  5. 查看日志:

    查看最近的系统日志,过滤包含 error 的条目

开发

npm run watch    # 监听模式编译
npm run dev      # 使用 ts-node 直接运行

技术栈

  • TypeScript — 类型安全

  • @modelcontextprotocol/sdk — MCP 协议实现

  • ssh2 — SSH 连接

  • zod — 参数校验

许可证

MIT

Available Tools

57 tools
connected_clientsA

List currently connected network clients (DHCP leases and ARP table).

Inputs: no named parameters.

connection_statusA

Check the current connection status to the router. Shows SSH, serial, and active transport info.

Inputs: no named parameters.

connect_routerA

Connect to an OpenWrt router via SSH. Must be called before using any other tools.

Inputs: host (required), port, password, username, +1 more.

connect_serialA

Connect to an OpenWrt router via serial port (UART/COM). Useful for boot logs, recovery, and low-level debugging.

Inputs: port (required), prompt, baudRate.

cron_listA

List current crontab entries on the router.

Inputs: no named parameters.

disconnect_routerA

Disconnect from the currently connected OpenWrt router (SSH).

Inputs: no named parameters.

disconnect_serialA

Disconnect from the serial port.

Inputs: no named parameters.

dns_lookupC

Perform DNS lookup from the router.

Inputs: domain (required).

file_chmodC

Change file permissions on the router.

Inputs: mode (required), path (required).

file_deleteB

Delete a file or directory on the router.

Inputs: path (required), recursive.

file_historyA

View modification history for files on the router. Shows all changes made through MCP tools (write, patch, sed, chmod, delete) with timestamps and details.

Inputs: last, path.

file_listA

List files and directories at a given path on the router.

Inputs: path, details.

file_patchA

Apply a unified diff patch to a file on the OpenWrt router. The patch is parsed and applied on the MCP server side — no 'patch' command needed on the router. Supports standard unified diff format (output of 'diff -u').

Inputs: path (required), patch (required), dry_run.

file_readA

Read the contents of a file on the OpenWrt router. For large files, use offset and limit to read in chunks. Returns file metadata (total lines and size) alongside content.

Inputs: path (required), limit, lines, offset.

file_read_batchA

Read multiple files at once for better performance. Returns all file contents in one call.

Inputs: paths (required).

file_writeA

Write content to a file on the OpenWrt router. Creates the file if it doesn't exist.

Inputs: path (required), content (required), append.

firewall_statusA

Show the current firewall rules and zones.

Inputs: no named parameters.

kernel_logB

Read the kernel log (dmesg).

Inputs: lines.

list_serial_portsA

List available serial ports on the system.

Inputs: no named parameters.

network_interfacesA

List all network interfaces and their status on the OpenWrt router.

Inputs: no named parameters.

network_restartB

Restart the network service or a specific interface.

Inputs: interface.

network_statusA

Get the status of a specific UCI network interface using netifd.

Inputs: interface.

opkg_infoB

Show detailed information about a package.

Inputs: package_name (required).

opkg_installB

Install a package via opkg.

Inputs: package_name (required).

opkg_listB

List available or installed packages.

Inputs: filter, installed_only.

opkg_removeB

Remove an installed package via opkg.

Inputs: package_name (required).

opkg_updateA

Update the opkg package lists from configured repositories.

Inputs: no named parameters.

opkg_upgradableA

List packages that have upgrades available.

Inputs: no named parameters.

ping_testB

Ping a host from the router to test connectivity.

Inputs: host (required), count.

process_listA

List running processes on the router.

Inputs: no named parameters.

route_tableA

Show the routing table.

Inputs: no named parameters.

run_commandA

Execute a shell command on the OpenWrt router. Use for any command-line operation not covered by specialized tools.

Inputs: command (required), timeout.

sed_addA

Add one or more sed expressions to the batch queue for a file. Expressions are NOT executed immediately — they accumulate until sed_execute is called. This allows building up complex multi-edit operations efficiently.

Inputs: path (required), expressions (required).

sed_clearB

Clear pending sed expressions from the batch queue.

Inputs: path.

sed_executeA

Execute all pending sed expressions in the batch queue. Each file is edited in-place with a backup (.sed.bak). All expressions for a file are combined into a single sed command for atomicity.

Inputs: path.

sed_previewA

Preview all pending sed expressions in the batch queue. Optionally preview the result on a specific file (dry run with sed, no modification).

Inputs: path.

serial_logA

Read the serial port output buffer. Captures all serial output including boot messages, kernel logs, and command output.

Inputs: clear, lines.

serial_writeA

Write raw data directly to the serial port. Use for sending special key sequences, break signals, or interacting with bootloaders.

Inputs: data (required), newline.

service_actionB

Perform an action on an init.d service (start, stop, restart, enable, disable).

Inputs: action (required), service (required).

service_listA

List available init.d services and their status.

Inputs: no named parameters.

switch_transportA

Switch the active transport between SSH and serial. Both connections can be maintained simultaneously — this controls which one is used for command execution.

Inputs: transport (required).

system_infoB

Get comprehensive system information from the OpenWrt router.

Inputs: no named parameters.

system_logB

Read the system log (logread) with optional filtering.

Inputs: lines, filter.

system_rebootB

Reboot the OpenWrt router. WARNING: This will disconnect the SSH session.

Inputs: delay.

uci_addA

Add an anonymous UCI section of a given type to a config.

Inputs: type (required), config (required).

uci_add_listC

Add an item to a UCI list option.

Inputs: path (required), value (required).

uci_changesA

Show pending (uncommitted) UCI changes.

Inputs: config.

uci_commitA

Commit pending UCI changes to make them persistent. Optionally restart the affected service.

Inputs: config, restart_service.

uci_deleteC

Delete a UCI section or option.

Inputs: path (required).

uci_del_listA

Remove an item from a UCI list option.

Inputs: path (required), value (required).

uci_getB

Get a specific UCI option value.

Inputs: path (required).

uci_revertB

Revert pending UCI changes.

Inputs: path (required).

uci_setB

Set a UCI option value.

Inputs: path (required), value (required).

uci_showB

Show UCI configuration. Can show all configs, a specific config, or a specific section/option.

Inputs: config, option, section.

wifi_scanC

Scan for nearby wireless networks.

Inputs: device.

wifi_statusA

Get wireless radio and interface status.

Inputs: no named parameters.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 57 tools

    Disambiguation4/5

    Most tools have clearly distinct purposes, but there is overlap between uci_show and uci_get, and file_read_batch may be confused with file_read. Overall, descriptions help clarify the boundaries.

    Naming Consistency3/5

    Names follow snake_case with domain prefixes (uci_, file_, opkg_, system_, etc.), but verb placement varies: some are noun_verb (file_read, system_reboot) while others are verb_noun (connect_router, list_serial_ports). This mixed pattern is still readable.

    Tool Count1/5

    With 57 tools, the set is extremely large for an MCP server. While it covers many OpenWrt domains, the sheer number exceeds what is typically manageable and increases selection complexity.

    Completeness4/5

    The tool surface is comprehensive for OpenWrt administration: UCI config, network, WiFi, firewall status, file operations, package management, serial access, and system management. Minor gaps like direct firewall modification are covered by UCI tools and run_command fallback.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables AI agents to manage OpenWRT routers remotely via SSH, supporting system monitoring, network management, OpenThread Border Router configuration, and package management through natural language commands.
      19
      17
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      Enables AI assistants to monitor and securely manage AsusWRT and AsusWRT-Merlin routers via SSH with allowlisted commands, supporting read-only monitoring and controlled mutations.
      47
      3
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to read-only monitor iStoreOS/OpenWRT routers via SSH or HTTP/ubus API, providing 31 tools for system status, network info, logs, and plugin status (OpenClash, Passwall, AdGuardHome, etc.).
      31
      MIT