@ai-solutions.ru/mikrotik-mcp-server
README.md
# @ai-solutions.ru/mikrotik-mcp-server
[](https://www.npmjs.com/package/@ai-solutions.ru/mikrotik-mcp-server)
[](https://opensource.org/licenses/MIT)
[](https://nodejs.org)
[](https://github.com/modelcontextprotocol/typescript-sdk)
High-performance **TypeScript** MCP (Model Context Protocol) server for MikroTik RouterOS management. Connect Claude, GPT-4, or any MCP-compatible AI to your MikroTik router and manage it through natural language.
```bash
npx @ai-solutions.ru/mikrotik-mcp-server
```
---
## š Why This Server?
| Feature | **This server** | jeff-nasseri/mikrotik-mcp | kevinpez (nested fork) |
|---|---|---|---|
| Language | **TypeScript / Node.js** | Python | Python |
| Dynamic API Discovery | ā
**Browse full RouterOS API tree** | ā | ā |
| Structured JSON output (`structuredContent`) | ā
**Every tool** | ā | ā |
| Zod output schemas | ā
**Typed & validated** | ā | ā |
| MCP safety annotations | ā
`readOnly/destructive/idempotent` | ā | ā |
| WireGuard VPN management | ā
list + add peers | ā | ā |
| IPsec peer management | ā
| ā | ā |
| Configuration backup & export | ā
binary + script export | ā | ā |
| Raw command execution (escape hatch) | ā
`execute_command` | ā | ā |
| Pagination on all list tools | ā
limit/offset | partial | partial |
| Smart output truncation | ā
auto-hint for large results | ā | ā |
| In-memory caching | ā
discovery cache | ā | ā |
| MCP SDK version | **1.16+** (latest) | old | old |
| Install via npx | ā
zero config | ā pip install | ā pip install |
---
## ⨠Unique Features
### 1. Dynamic API Discovery (unique in ecosystem)
Browse the **entire RouterOS API tree** without needing to know command paths in advance. The AI can explore unknown router configurations autonomously.
```
ā mikrotik_discover_endpoints(path: "/ip")
Returns: address, arp, dhcp-client, dhcp-server, dns, firewall, hotspot, ipsec, ...
ā mikrotik_get_endpoint_schema(path: "/ip/firewall/filter")
Returns: available commands (print, add, remove, set, enable, disable) and parameters
```
This means Claude can discover and interact with **any RouterOS subsystem** ā including packages you've installed, containers, advanced routing, hardware-specific features ā without the server needing hardcoded knowledge of them.
### 2. Structured Content + Zod Output Schemas
Every tool returns **both** human-readable Markdown **and** machine-readable JSON via `structuredContent`. The JSON is validated against Zod schemas, giving you typed, predictable data structures that work with MCP clients that support structured output.
```typescript
// Example: mikrotik_list_ip_addresses returns
{
content: [{ type: "text", text: "# IP Addresses\n..." }], // ā Markdown for AI
structuredContent: { // ā Typed JSON for clients
total: 5,
addresses: [{ id: "*1", address: "192.168.1.1/24", interface: "bridge", ... }]
}
}
```
### 3. MCP Safety Annotations
Tools are annotated with MCP 2025 safety hints so AI clients can present appropriate warnings:
- `readOnlyHint: true` ā safe to call without side effects (list/print operations)
- `destructiveHint: true` ā modifies router state (add/remove/reboot)
- `idempotentHint: true` ā safe to retry
- `openWorldHint: true` ā queries live state from router
The reboot tool additionally requires `confirm: true` parameter as an extra safety gate.
### 4. VPN Management (WireGuard + IPsec)
First MikroTik MCP server with **WireGuard peer management**:
- List all WireGuard peers with traffic stats
- Add new WireGuard peers with endpoint and allowed addresses
- List IPsec peers with profiles
- Graceful handling when WireGuard package isn't installed
### 5. Raw Command Execution
`mikrotik_execute_command` provides a full escape hatch to the RouterOS API ā execute **any** RouterOS command with any parameters. This enables AI to handle edge cases, new RouterOS features, or complex operations not covered by specialized tools.
### 6. Configuration Backup & Export
- `mikrotik_create_backup` ā binary RouterOS backup (survives factory reset)
- `mikrotik_export_config` ā human-readable script export with statistics (line count, command count, size)
---
## š Full Tool Reference
### š„ System (2 tools)
| Tool | Description | Annotations |
|---|---|---|
| `mikrotik_system_info` | CPU, RAM, storage, uptime, version, board info | readOnly |
| `mikrotik_system_reboot` | Reboot device (requires `confirm: true`) | destructive |
### š Interfaces (3 tools)
| Tool | Description |
|---|---|
| `mikrotik_list_interfaces` | List all interfaces with type filter + pagination |
| `mikrotik_get_interface` | Get detailed info for specific interface |
| `mikrotik_configure_interface` | Enable/disable, set MTU, comment |
### š IP Addresses (3 tools)
| Tool | Description |
|---|---|
| `mikrotik_list_ip_addresses` | List all IP addresses with interface filter + pagination |
| `mikrotik_add_ip_address` | Add IP address to interface |
| `mikrotik_remove_ip_address` | Remove IP address by ID |
### š„ Firewall (3 tools)
| Tool | Description |
|---|---|
| `mikrotik_list_firewall_rules` | List filter rules with chain filter + pagination |
| `mikrotik_add_firewall_rule` | Add filter rule with full parameter support |
| `mikrotik_remove_firewall_rule` | Remove rule by ID |
### š” DHCP (3 tools)
| Tool | Description |
|---|---|
| `mikrotik_list_dhcp_leases` | List leases with status filter + pagination |
| `mikrotik_add_static_lease` | Assign static IP to MAC address |
| `mikrotik_list_dhcp_servers` | List configured DHCP servers |
### š DNS (2 tools)
| Tool | Description |
|---|---|
| `mikrotik_list_dns_static` | List static DNS records with pagination |
| `mikrotik_add_dns_record` | Add A/AAAA/CNAME static DNS record |
### šŗ Routing (3 tools)
| Tool | Description |
|---|---|
| `mikrotik_list_routes` | List all routes with pagination |
| `mikrotik_add_route` | Add static route with distance and routing table |
| `mikrotik_list_nat_rules` | List NAT rules with chain filter + pagination |
### š VPN (3 tools)
| Tool | Description |
|---|---|
| `mikrotik_list_wireguard_peers` | List WireGuard peers with traffic stats |
| `mikrotik_add_wireguard_peer` | Add WireGuard peer with endpoint |
| `mikrotik_list_ipsec_peers` | List IPsec peers with profiles |
### š¾ Backup (2 tools)
| Tool | Description |
|---|---|
| `mikrotik_create_backup` | Create binary system backup |
| `mikrotik_export_config` | Export config as text script with statistics |
### ā” Execute (1 tool)
| Tool | Description |
|---|---|
| `mikrotik_execute_command` | Execute any RouterOS API command (destructive) |
### š Discovery (2 tools)
| Tool | Description |
|---|---|
| `mikrotik_discover_endpoints` | Browse RouterOS API tree at any path |
| `mikrotik_get_endpoint_schema` | Get available commands & params for endpoint |
**Total: 27 tools + 4 MCP resources**
---
## š¦ MCP Resources
| Resource URI | Description |
|---|---|
| `routeros://system/info` | Live system info snapshot |
| `routeros://interfaces` | All interface states |
| `routeros://firewall/rules` | Full firewall ruleset |
| `routeros://routing/routes` | All routing table entries |
---
## š§ Installation & Setup
### Claude Desktop
Add to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"mikrotik": {
"command": "npx",
"args": ["-y", "@ai-solutions.ru/mikrotik-mcp-server"],
"env": {
"MIKROTIK_HOST": "192.168.88.1",
"MIKROTIK_USER": "admin",
"MIKROTIK_PASSWORD": "yourpassword",
"MIKROTIK_PORT": "8728",
"MIKROTIK_SECURE": "false"
}
}
}
}
```
### Environment Variables
| Variable | Default | Description |
|---|---|---|
| `MIKROTIK_HOST` | `192.168.88.1` | Router IP or hostname |
| `MIKROTIK_USER` | `admin` | API username |
| `MIKROTIK_PASSWORD` | *(required)* | API password |
| `MIKROTIK_PORT` | `8728` | RouterOS API port (8729 for TLS) |
| `MIKROTIK_SECURE` | `false` | Use TLS (requires port 8729) |
| `MIKROTIK_TIMEOUT` | `10000` | Connection timeout in ms |
| `DISCOVERY_CACHE_TTL` | `300` | Discovery cache TTL in seconds |
### Enable RouterOS API
In RouterOS WebFig or terminal:
```
/ip service enable api
```
For TLS: `/ip service enable api-ssl`
---
## š¬ Example Conversations
**"What's the current state of my router?"**
> Calls `mikrotik_system_info` ā Returns device name, RouterOS version, CPU load, RAM usage, uptime
**"Show me all firewall rules that drop traffic"**
> Calls `mikrotik_list_firewall_rules(chain="forward")` ā Filters by action=drop
**"Add a static DNS record for myserver.local pointing to 10.0.0.50"**
> Calls `mikrotik_add_dns_record(name="myserver.local", address="10.0.0.50")`
**"List all WireGuard peers and their traffic stats"**
> Calls `mikrotik_list_wireguard_peers()` ā Returns peers with RX/TX bytes
**"What API endpoints are available under /container?"**
> Calls `mikrotik_discover_endpoints(path="/container")` ā Browses RouterOS container API
**"Export the full router config as a backup script"**
> Calls `mikrotik_export_config()` ā Returns full RouterOS export with stats
---
## š Architecture
```
src/
āāā index.ts # Entry point, env config
āāā server.ts # MCP server + tool/resource registration
āāā constants.ts # Configuration constants
āāā routeros/
ā āāā client.ts # RouterOS API client (node-routeros)
āāā cache/
ā āāā memory.ts # LRU in-memory cache
āāā discovery/
ā āāā service.ts # Dynamic API discovery service
āāā tools/
ā āāā system.ts # System info & reboot
ā āāā interfaces.ts # Interface management
ā āāā ip-address.ts # IP address CRUD
ā āāā firewall.ts # Firewall rules
ā āāā dhcp.ts # DHCP leases & servers
ā āāā dns.ts # Static DNS records
ā āāā routing.ts # Routes & NAT
ā āāā vpn.ts # WireGuard & IPsec
ā āāā backup.ts # Backup & export
ā āāā execute.ts # Raw command execution
ā āāā discovery.ts # API discovery tools
āāā resources/
ā āāā system-info.ts # System resource
ā āāā interfaces.ts # Interfaces resource
ā āāā firewall.ts # Firewall resource
ā āāā routing.ts # Routing resource
āāā utils/
āāā format.ts # Formatting, truncation, pagination
āāā errors.ts # RouterOS error handling
āāā logger.ts # Structured logging
```
---
## š Security Notes
- All write operations carry `destructiveHint: true` annotation
- Reboot requires explicit `confirm: true` parameter
- Credentials are passed via environment variables (never in code)
- TLS support via `MIKROTIK_SECURE=true` + port 8729
- Consider using a read-only RouterOS API user for monitoring-only setups
---
## š License
MIT Ā© [AI Solutions](https://ai-solutions.ru)
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues