
Mikrotik Rest Mcp
io.github.Soglv0.1.1更新於 Oct 2, 2026
MikroTik RouterOS 7 REST MCP: filtered reads, guarded writes, timed rollback
概覽
讓助理透過 REST API 對 MikroTik RouterOS 7 裝置進行結構化讀取與受控寫入,並具備定時回滾保護。
- 功能
- 提供約 60 個精選 get_* 工具,涵蓋防火牆、路由、DHCP、DNS、介面、WireGuard、容器、排程器、日誌與系統資源等常用集合,另有 200 多個端點可用名稱呼叫,並可透過 catalog_search 尋找。讀取支援用戶端 where 篩選、欄位投影、排序、限制與精簡輸出;routeros_get 可直接存取任意 /rest/ 路徑,routeros_batch 一次可平行執行最多 16 個讀取。寫入經由 routeros_write 並依方法套用政策;apply_safe 會先快照目標、在路由器上設定排程器,除非以 commit_safe 解除,否則自動回滾。診斷工具包括 ping、traceroute、fetch、介面流量取樣、計數器差值、容器 shell 與沙箱化的路由器檔案傳輸。
- 適用情境
- 適合網路或基礎架構情境:讓助理盤點 RouterOS 裝置、檢查防火牆與路由狀態、觀察計數器,並在確認步驟與回滾視窗的保護下套用設定變更。適用於對你管理的路由器進行有人監督的維運,而非隨意或無人值守的自動化。
- 執行需求
- 以 Python 套件形式透過 stdio 在本機執行(Python 3.10+),可用 pipx 或 uvx 安裝。需要 REST 可存取的 RouterOS 7.1+ 裝置,以及環境變數 MIKROTIK_BASE 與 MIKROTIK_USERNAME,另需 MIKROTIK_PASSWORD 或 MIKROTIK_PASSWORD_FILE。唯讀使用只需具備 read、api、rest-api 的 RouterOS 帳號;變更、診斷與檔案工具還需要 write、test 與 ftp。建議透過 www-ssl 使用 HTTPS。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Mikrotik Rest Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
English | Русский
MikroTik REST MCP
MCP server that gives coding agents structured access to a RouterOS 7 device over its REST API — reads, filtered queries, guarded writes, a scheduled rollback guard, container shell, and file transfer. One MCP server over stdio.
Built for real ops work: the agent can inventory the router, diff firewall/routing state, poke containers, watch counters, and apply changes — with a human confirmation gate in front of anything disruptive.
Features
- Broad read coverage
- ~60 curated
get_*tools for the common collections (firewall, routes, DHCP, DNS, interfaces, WireGuard, containers, scheduler, logs, system resources). - 200+ additional
get_*endpoints stay callable by name through the same filter pipeline — they are deliberately unlisted so the tool schema stays small.catalog_searchmakes them discoverable. routeros_gettakes any/rest/path directly, plusrouteros_batchfor up to 16 parallel reads in one call.
- ~60 curated
- Real query power
- Client-side
wherefilters with__contains,__in,__not,__gt,__gte,__lt,__lte,__startswith,__endswith. fieldsprojection,sort_by,limit,compact(one-line-per-item output that saves a lot of tokens).- RouterOS-native
.proplist/.querypass-through for server-side filtering.
- Client-side
- Guarded mutations
MIKROTIK_MODE=readonly: mutation/execution tools are not registered at all — the protocol surface itself is read-only, not just policy-gated.MIKROTIK_MODE=careful(default): operations classified as disruptive returnrequires_confirmation— the agent relays it to the user and re-runs withconfirm: trueafter approval. MCP elicitation shows a native dialog where supported. The confirmation flag is a UX gate, not a security boundary — the RouterOS account permissions are what actually limits the agent.- Method-aware policy:
PUTonly on known collections,PATCH/DELETEonly oncollection/<id>items,POSTonly on an explicit action allowlist (ping,traceroute,fetch,file/read,script/run,dns flush,backup/save,export, container shell — seecatalog.py). MIKROTIK_STRICT_CONFIRM=1gates every mutation.MIKROTIK_MODE=yoloremoves all gates and can switch to a separate full-privilege account (MIKROTIK_YOLO_USERNAME/MIKROTIK_YOLO_PASSWORD_FILE) — for supervised automation windows only.
- Scheduled rollback guard (not RouterOS Safe Mode — this works over plain REST)
apply_safesnapshots the target, arms an on-router scheduler, then applies the mutation. Once armed, the rollback no longer depends on the MCP process or client staying alive —commit_safedisarms it withinwindow_seconds.- Supported methods:
PATCH(restores the snapshotted values of changed fields — not transactional, no concurrent-edit detection) andDELETE(best-effort recreate; list position and generated fields are not preserved — the response says so).PUTis rejected because a created item's.idcan't be known until after it exists. - Ambiguous transport failures leave the rollback armed rather than silently disarming;
commit_safekeeps the pending record if disarm fails so it can be retried. safe_statusreports currently armed rollbacks.
- Container & diagnostics
container_shellruns commands inside RouterOS containers by name or.id— off by default (MIKROTIK_ENABLE_CONTAINER_SHELL), confirmation-gated in careful mode, and the genericrouteros_writepath can't bypass the flag.interface_trafficmeasures live rx/tx bps and pps over a sampling window;routeros_watchdiffs numeric fields across samples — counter deltas without two manual reads.run_ping,run_traceroute,run_fetch,run_wifi_monitor,describe_path(field introspection before you write filters).
- File ops with a sandbox
- Router-side file create/read/update/rename/delete plus chunked
download_file/upload_file. - Host filesystem access is off by default;
MIKROTIK_ENABLE_LOCAL_FILES+MIKROTIK_LOCAL_ROOTconfine it to one directory; transfers are capped at 8 MiB anddownload_filerequiresoverwrite: trueto replace an existing local file.
- Router-side file create/read/update/rename/delete plus chunked
- Secret hygiene
- Credentials come from
MIKROTIK_PASSWORD_FILE(recommended) orMIKROTIK_PASSWORD. - Every response passes through a scrubber that masks
password/secret/psk/token/private-key-shaped fields (MIKROTIK_REDACT=0disables). Redaction is field-name based — secrets embedded in free-form text (comments, script bodies, log lines, file contents) are not reliably detected. - Tool annotations (
readOnlyHint,destructiveHint,idempotentHint,openWorldHint) on every tool so clients can enforce their own policy.
- Credentials come from
Requirements
- Python 3.10+ (developed on 3.13).
- RouterOS 7.1+ with REST reachable (integration-tested on 7.24.5, hAP ax³ — REST, containers, scheduler rollback, file ops). HTTPS via
www-sslrecommended; plain HTTP viawwwrequires RouterOS 7.9+ and should be used only on isolated networks — REST uses Basic auth, readable on the wire. - A RouterOS user with
read+api+rest-apifor read-only use. Addwrite+testfor mutations/diagnostics,ftpfor file tools (download_file,/file/read). Script entries have their ownpolicyattribute — the account only needswriteto run them, and cannot run a script with broader policy than it possesses.
Installation
This exposes the mikrotik-rest-mcp-server console script. For development: git clone + pip install -e .
Configuration
Point your MCP client at the server:
See .env.example for the full variable list (modes, capability flags, timeouts, TLS verification).
Recommended RouterOS account
For yolo mode, create a second account in full and wire it via MIKROTIK_YOLO_*. Omit ftp if you don't need file tools.
Using it with agents
Typical flow an agent follows:
run_script_inline creates a temporary RouterOS script, runs it, and removes it (always confirmed in careful mode). container_shell and host file transfer need their opt-in flags.
Layout
Tests
Unit tests run without a router (REST calls are mocked).
Security
See SECURITY.md. Don't point this at routers you don't administer; treat yolo as a loaded gun and container_shell as remote code execution (because it is).
來源:README.md,提交 0973284
工具
0版本歷史
1- v0.1.1最新Oct 2, 2026


