mikrotik-mcp
Manage a MikroTik RouterOS device through MCP: read system state and configuration, and add, update, remove, enable/disable, and reorder firewall/NAT/DNS/interface items.
Read-only inspection: system info, interfaces, IP addresses, firewall rules (IPv4/IPv6), NAT rules, DHCP leases, static DNS, routes, logs, address lists, and any RouterOS path via
ros_list.Firewall management: add, get, update, enable/disable, remove, and move firewall filter rules; list with chain/verbose/dynamic filters.
NAT management: add, list, enable/disable, and remove NAT rules (port forwards, masquerade).
DNS management: add, list, and remove static DNS entries (A, CNAME, regexp).
DHCP management: list leases and pin a dynamic lease as static.
Interface control: list interfaces and enable/disable them (with the caveat that disabling the management interface can cut remote access).
Connectivity check: verify the server can reach and authenticate to the router.
Generic read:
ros_listreads any RouterOS configuration path, but there is no generic write escape hatch.
Provides tools for managing MikroTik RouterOS devices over the binary API, including system info, interfaces, IP addressing, firewall filter and NAT rules, DHCP leases, static DNS, routes, logs, and arbitrary RouterOS paths.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mikrotik-mcp show me the firewall filter rules"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mikrotik-mcp
mcp-name: io.github.StefanKnol/mikrotik-mcp
An MCP server for MikroTik RouterOS, over the binary API rather than by driving the CLI over SSH.
That distinction is the whole point. The CLI prints positional numbers, which
are not a rule's identity. A server that lists rules by position and then writes
by position either fails outright — where .id=3 matches nothing, so every
write reports "not found" for rules that plainly exist — or, worse, succeeds
against a different rule once the order has shifted. On a firewall that means
deleting the wrong rule.
The binary API returns the real .id (*7, *1f) on every read. So:
every read returns
id, and every write takes one back;list results also carry
position, which is display-only and refused for writes, with an error that explains why;writes read back what they wrote, so a change can be verified rather than assumed;
remove_firewall_ruletakes an optionalconfirm_commentand returns the rule it deleted.
Use it
uvx mikrotik-mcpConfigure through the environment — ps would show a password passed as a flag:
Variable | Default | Meaning |
| — | Router address. Required. |
| — | Required. |
| — | |
|
|
|
|
| |
| — | SHA-256 of the router certificate, to pin it. |
|
|
In an MCP client's config:
{
"mcpServers": {
"mikrotik": {
"command": "uvx",
"args": ["mikrotik-mcp"],
"env": {
"MIKROTIK_HOST": "192.168.88.1",
"MIKROTIK_USERNAME": "mcp-agent",
"MIKROTIK_PASSWORD": "..."
}
}
}
}Related MCP server: MikroTik MCP
On the router
/ip service enable api-ssl
/user group add name=mcp policy=api,read,write,test
/user add name=mcp-agent group=mcp password=<strong-password>The api policy is not optional, and its absence produces a login error
identical to a wrong password — so if credentials look right and login still
fails, check the group first.
Set MIKROTIK_TLS_FINGERPRINT if you can. MikroTik's API-SSL certificate is
self-signed, so ordinary CA validation cannot succeed against a stock device;
pinning is what makes the connection authenticated rather than merely encrypted.
Tools
34 of them, covering system info, interfaces, IP addressing, firewall filter
(IPv4 and IPv6), firewall address lists, NAT, DHCP leases, DNS, routes and logs
— plus ros_list, which reads any RouterOS path and so covers everything
without a dedicated tool.
There is deliberately no generic write escape hatch.
Three things worth knowing before the first call:
Writes take an
id(*7), never aposition. Both appear in every list result.positionis where a rule currently sits in evaluation order; it shifts whenever anything is added, removed or moved, and it is counted across the whole table rather than within the chain you filtered to. Passing one to a write is rejected rather than guessed at.IPv4 and IPv6 are separate rule sets. The firewall tools take a
familyand default toipv4, so a device can read as locked down while its IPv6 table is empty and therefore accepting everything. Listing IPv4 reports the IPv6 rule count for exactly this reason.Address lists hold state no configuration export shows. Entries a rule adds at runtime carry a timeout and exist only in memory. Ask
list_address_list_entriesfor acount_onlyfirst: a populated block list can hold tens of thousands.
With mcphub
mcphub puts MCP servers behind one
sign-in and grants them out per account. One router is one backend, at its own
/mcp/<slug>, registered in a client as its own connector.
Adding it
From the registry — the better default. Add from registry, search for
mikrotik-mcp, and the hub builds the settings form from server.json and
launches uvx mikrotik-mcp when you enable the backend. It runs in its own
process and cannot read credentials the hub holds for anything else. Backends
added this way start disabled: open it, look at the tool list, then enable.
As a plugin — install this package into the hub's own environment and
mikrotik appears as a backend kind, with typed fields and a Test button that
reports the router's identity and RouterOS version. Nicer to configure, but an
in-process plugin can read every credential the hub holds. Use it when you
build your own hub image.
What to set
Either route asks for the same things. As environment variables:
Variable | Default | |
| — | Router address. Required. |
| — | Required. A dedicated user, not |
| — | Required. |
|
|
|
|
| Turning it off sends the router password over the network in the clear. |
| — | SHA-256 of the router certificate. Pinning it is what makes the TLS connection authenticated rather than merely encrypted. |
|
| Seconds. |
No data directory: everything this server reads and writes lives on the router, so there is no local state to keep. Leave Give this server a data directory unticked.
Levels
The hub reads readOnlyHint and destructiveHint from each tool and enforces
the grant's level from those alone — a tool above the level is left out of
tools/list and refused if called anyway.
Level | Gets | |
| 17 tools | Reads the whole configuration and changes nothing. |
| +7 tools | Adds rules and entries, and disables or re-enables them. |
| +10 tools | Deletes, edits in place, and reorders. |
viewer — connectivity_check, get_dns_settings, get_firewall_rule,
get_logs, get_nat_rule, list_address_list_entries, list_address_lists,
list_dhcp_leases, list_dns_adlist, list_dns_static, list_firewall_rules,
list_interfaces, list_ip_addresses, list_nat_rules, list_routes,
ros_list, system_info.
user adds add_address_list_entry, add_dns_static, add_firewall_rule,
add_nat_rule, make_lease_static, set_firewall_rule_enabled,
set_nat_rule_enabled. Each of these writes, and none of them takes anything
away: adding a rule is a write, not a destruction, and disabling one keeps the
rule, its comment and its position so that re-enabling restores exactly what
was there. Disabling is the reversible way to find out whether a rule is
responsible for something, so it sits here rather than behind admin — the
alternative would leave a user with no safe way to test at all.
admin adds the destructive ten:
Tool | What is lost |
| The rule. The returned copy is the only record. |
| The rule. |
| The entry. |
| The entry. A dynamic one returns when its rule next matches; a static one does not. |
| The previous values of whatever it sets or clears. |
| The same. |
| The same. |
| The previous order, which is the entire semantics of a firewall. |
| The same. |
| Nothing on disk — but disabling the interface the request came in through severs the only route back, and nothing here can undo that remotely. |
A test pins every one of these assignments by name, so a tool added later fails the suite until someone decides which level it belongs to.
Publishing to the MCP registry
server.json is the manifest for the official MCP registry,
validated against the published schema. It declares the uvx mikrotik-mcp
command and every MIKROTIK_* variable, marking which are required and which
are secret — so a client that browses the registry can generate a correct
settings form without knowing anything about this server.
Publishing has an order to it, because the registry verifies that whoever publishes an entry actually owns the package it points at.
1. The package must already be on PyPI. The registry fetches
pypi.org/pypi/mikrotik-mcp/<version>/json and refuses an entry whose package
does not exist. Tag a release and let CI publish it:
git tag v0.1.0 && git push --tagsThat needs a PyPI Trusted Publisher first, and because this project does not exist on PyPI yet it has to be a pending publisher — the per-project Publishing tab only appears once a project exists, which is the chicken-and-egg this page solves:
pypi.org → Account settings → Publishing → Add a new pending publisher
Field
Value
PyPI Project Name
mikrotik-mcpOwner
StefanKnolRepository name
mikrotik-mcpWorkflow name
ci.ymlEnvironment name
pypi
The environment name matters: the publish job declares environment: pypi, and
PyPI rejects the upload if they disagree.
2. The README must carry the ownership token. The registry looks for
mcp-name: io.github.StefanKnol/mikrotik-mcp in the PyPI description, which is
this file — it is at the top, on its own line. That is what proves the person
publishing the registry entry controls the PyPI package.
3. The registry entry publishes itself. The registry job in ci.yml
runs after the PyPI upload on the same tag, authenticating with
mcp-publisher login github-oidc. GitHub signs a short-lived OIDC token, the
registry verifies it and grants the io.github.StefanKnol/* namespace from the
repository owner. There is no secret to store and no device-flow login to sit
through on each release.
It waits for PyPI to actually serve the new version first. The registry fetches
pypi.org/pypi/mikrotik-mcp/<version>/json and refuses an entry whose package
it cannot see, and that endpoint lags the upload by some seconds — long enough
that publishing straight afterwards races it.
Re-running it is safe: a version already in the registry is the outcome the job exists to produce, so it reports that and passes rather than failing on the registry's duplicate refusal.
To publish by hand — recovering a failed run, or a version released before this job existed:
curl -sL https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_linux_amd64.tar.gz | tar xz mcp-publisher
./mcp-publisher login github && ./mcp-publisher publishlogin github opens the device flow and proves you are StefanKnol, which
authorises the same namespace the OIDC path gets without asking.
The version appears in four places — pyproject.toml, __version__,
server.json, and again inside that file's packages entry. Rather than
edit them by hand:
uv run python scripts/release.py 0.2.0 --tagIt sets all four, verifies them, commits and tags. The registry treats each
version as its own row and checks PyPI has the package at exactly that
version, so the nested packages[].version matters as much as the top-level
one — and it is the one that gets missed, because the manifest still validates
without it. A test enforces that they agree.
Development
uv sync --extra dev
uv run pytestLicense
MIT
Available Tools
24 toolsadd_dns_staticC
Add a static DNS entry.
Inputs: ttl, name, cname, regexp, +2 more. Returns: result
add_firewall_ruleA
Add a firewall filter rule.
Order decides everything in a RouterOS firewall: the first matching
rule wins. A new rule appended after a final drop is dead code, so
set place_before unless the end of the chain is genuinely what you
want.
Inputs: chain (required), action (required), log, comment, +15 more. Returns: result
add_nat_ruleA
Add a NAT rule, such as a port forward.
A port forward also needs the forward chain to permit the traffic;
check list_firewall_rules(chain='forward') for a rule accepting
connection-nat-state=dstnat before concluding it is broken.
Inputs: chain (required), action (required), comment, disabled, +9 more. Returns: result
connectivity_checkARead-onlyIdempotent
Confirm the hub can reach and authenticate to this device.
Inputs: no named parameters. Returns: result
get_firewall_ruleARead-onlyIdempotent
Every field of one firewall rule, including counters.
Inputs: rule_id (required). Returns: result
get_logsBRead-onlyIdempotent
Read the device log, most recent last.
Inputs: limit, topic, search. Returns: result
list_dhcp_leasesARead-onlyIdempotent
List DHCP leases — effectively the inventory of what is on the network.
Inputs: search, active_only. Returns: result
list_dns_staticARead-onlyIdempotent
List static DNS entries and regex overrides.
Inputs: no named parameters. Returns: result
list_firewall_rulesARead-onlyIdempotent
List firewall filter rules in evaluation order.
Each rule carries both an id and a position. Use id for any
later change: position is only where the rule currently sits, and it
shifts as soon as anything is added, removed or moved.
Inputs: chain, verbose, include_dynamic. Returns: result
list_interfacesARead-onlyIdempotent
List every interface with its type, MAC, MTU and running state.
Inputs: type_filter, running_only. Returns: result
list_ip_addressesARead-onlyIdempotent
List configured IPv4 addresses and the interfaces they sit on.
Inputs: no named parameters. Returns: result
list_nat_rulesARead-onlyIdempotent
List NAT rules, including port forwards, in evaluation order.
Inputs: chain, verbose. Returns: result
list_routesCRead-onlyIdempotent
List the IPv4 routing table.
Inputs: active_only. Returns: result
make_lease_staticAIdempotent
Pin a dynamic DHCP lease so the device keeps its address.
Inputs: lease_id (required), comment. Returns: result
move_firewall_ruleADestructive
Reorder a firewall rule relative to another rule.
Both ends are given by id rather than position, so the move means the
same thing even if the list shifted since you last read it.
Inputs: rule_id (required), before_rule_id. Returns: result
remove_dns_staticADestructiveIdempotent
Delete a static DNS entry.
Inputs: entry_id (required). Returns: result
remove_firewall_ruleADestructiveIdempotent
Delete a firewall rule permanently.
There is no undo. Disabling a rule (set_firewall_rule_enabled) is
almost always the better first move, and the returned copy of the
deleted rule is the only record you will have afterwards.
Inputs: rule_id (required), confirm_comment. Returns: result
remove_nat_ruleADestructiveIdempotent
Delete a NAT rule permanently. Returns the rule that was removed.
Inputs: rule_id (required). Returns: result
ros_listARead-onlyIdempotent
Read any RouterOS configuration path.
The escape hatch for everything without a dedicated tool. Read-only: it lists items at a path and cannot modify the device.
Inputs: path (required). Returns: result
set_firewall_rule_enabledADestructiveIdempotent
Enable or disable one firewall rule, leaving its position intact.
Disabling is the reversible way to test whether a rule is responsible for something — prefer it over removing the rule.
Inputs: enabled (required), rule_id (required). Returns: result
set_interface_enabledADestructiveIdempotent
Bring an interface up or down.
Disabling the interface you are reaching the router through will cut this connection, and nothing here can undo that remotely.
Inputs: enabled (required), interface_id (required). Returns: result
set_nat_rule_enabledBDestructiveIdempotent
Enable or disable one NAT rule.
Inputs: enabled (required), rule_id (required). Returns: result
system_infoARead-onlyIdempotent
Identity, RouterOS version, model, uptime, CPU and memory for the device.
Inputs: no named parameters. Returns: result
update_firewall_ruleADestructiveIdempotent
Change fields on an existing firewall rule.
Only the arguments you pass are modified; omitted ones are left alone. Returns the rule as it stands afterwards.
Inputs: rule_id (required), log, chain, action, +14 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 24 tools
Each tool targets a distinct resource/action pair, from list_interfaces to move_firewall_rule, so an agent can reliably select the right operation. ros_list is broad but is explicitly framed as a read-only escape hatch, not a competing path.
Most tools follow a clean list_/add_/remove_/set_*_enabled pattern, and the firewall group is especially consistent. A few stragglers like system_info, ros_list, and connectivity_check break the verb-first convention without causing real confusion.
24 tools is at the upper edge of reasonable, but the server spans many distinct MikroTik subsystems: interfaces, firewall, NAT, DHCP, DNS, routes, and logs. Each tool earns a place, and there is little obvious redundancy beyond the intentional ros_list fallback.
Firewall lifecycle is well covered with create, read, update, delete, move, and enable/disable. However, NAT and DNS entries lack update operations, routes are read-only, and ros_list cannot write, so some configuration changes require workarounds or are impossible.
Maintenance
Related MCP Connectors
Connect any MCP client to MetaTrader 4/5 to read prices, manage positions, and place trades.
Managed MCP gateway with OAuth, per-agent permissions, shared accounts and activity logs.
Single-connection meta-router indexing 500+ MCP servers & A2A tools with 85% token compression and
Manage MetaTrader 4 and 5 trade copying: accounts, copiers, followers and their copy rules.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with MikroTik RouterOS devices through API and SSH connections, supporting network monitoring, configuration management, and diagnostics across multiple routers with automatic connection fallback.3MIT
- AlicenseCqualityAmaintenanceProvides a bridge between AI assistants and MikroTik RouterOS devices, enabling natural language management of VLANs, firewall rules, DNS settings, and more.2392,499 PyPI348MIT
- AlicenseNot gradedqualityDmaintenanceEnables management of MikroTik routers running RouterOS 6 and 7 via SSH, Telnet, or API with automatic command adaptation. Provides over 46 MCP tools for device management, firewall, DHCP, VPN, configuration profiles, and more.3MIT
- AlicenseCqualityAmaintenanceEnables n8n AI agents to manage MikroTik routers via SSH/SSE, providing tools for firewall, DNS, DHCP, WireGuard, interfaces, queues, backup, users, logs, and routes.174MIT