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-mcp
Configure through the environment — ps would show a password passed as a flag:
| Variable | Default | Meaning |
|---|---|---|
MIKROTIK_HOST |
— | Router address. Required. |
MIKROTIK_USERNAME |
— | Required. |
MIKROTIK_PASSWORD |
— | |
MIKROTIK_PORT |
8729 |
8729 for api-ssl, 8728 for plaintext. |
MIKROTIK_TLS |
true |
|
MIKROTIK_TLS_FINGERPRINT |
— | SHA-256 of the router certificate, to pin it. |
MIKROTIK_TIMEOUT |
10 |
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": "..."
}
}
}
}
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
Two ways, and the first is the better default:
Launched as a subprocess by mcphub,
configured as a command — uvx mikrotik-mcp — with credentials as encrypted
environment variables. It runs in its own process and cannot read credentials
held for other backends.
Loaded in-process via the mcphub.plugins entry point this package also
ships, which gives typed host/username/password fields in mcphub's settings UI.
Nicer to configure, but an in-process plugin can read everything the hub holds.
Install it into the hub's environment to use this route.
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 --tags
That 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. Then publish the entry.
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 publish
login github opens a device flow and proves you are StefanKnol, which is
what authorises the io.github.StefanKnol/* namespace. In CI, login github-oidc does the same from a workflow with id-token: write.
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 --tag
It 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 pytest
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mikrotik_mcp-0.2.0.tar.gz.
File metadata
- Download URL: mikrotik_mcp-0.2.0.tar.gz
- Upload date:
- Size: 108.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
242652a113fd04b14fb2e6a9c115e1672c7695f2616e8a1e6cda7a135db994c1
|
|
| MD5 |
3ffd721153821151ce1d65f78e35dd3d
|
|
| BLAKE2b-256 |
c1cc40a55961742dc2ed359a78fe5edbd1b8e96e55a0c591933ed42795686eb1
|
Provenance
The following attestation bundles were made for mikrotik_mcp-0.2.0.tar.gz:
Publisher:
ci.yml on StefanKnol/mikrotik-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mikrotik_mcp-0.2.0.tar.gz -
Subject digest:
242652a113fd04b14fb2e6a9c115e1672c7695f2616e8a1e6cda7a135db994c1 - Sigstore transparency entry: 2850976196
- Sigstore integration time:
-
Permalink:
StefanKnol/mikrotik-mcp@f56cbb80611642bee0c0d218b404a17c8b9233d5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/StefanKnol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f56cbb80611642bee0c0d218b404a17c8b9233d5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mikrotik_mcp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mikrotik_mcp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 33.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bad99430e5109b1cc28b46228eb3164f191d98ecebce27a5f76bcdd97c6499fc
|
|
| MD5 |
71d6dd2fb76b46891c7574027bfc8aa8
|
|
| BLAKE2b-256 |
0209241a68bd914bcd108e5317e86f424eacaa810bc9c992a522559ac951d3fb
|
Provenance
The following attestation bundles were made for mikrotik_mcp-0.2.0-py3-none-any.whl:
Publisher:
ci.yml on StefanKnol/mikrotik-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mikrotik_mcp-0.2.0-py3-none-any.whl -
Subject digest:
bad99430e5109b1cc28b46228eb3164f191d98ecebce27a5f76bcdd97c6499fc - Sigstore transparency entry: 2850977076
- Sigstore integration time:
-
Permalink:
StefanKnol/mikrotik-mcp@f56cbb80611642bee0c0d218b404a17c8b9233d5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/StefanKnol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f56cbb80611642bee0c0d218b404a17c8b9233d5 -
Trigger Event:
push
-
Statement type: