Manage Firewall Rule
manage_firewall_ruleAdd, remove, enable, or disable MikroTik firewall and NAT rules using match criteria, comments for idempotency, dry-run checks, and an automatic rollback safeguard.
Instructions
Add, remove, disable, or enable a firewall rule on a MikroTik router. Matches addresses, ports, protocol, interfaces, interface lists, and connection/NAT state; nat rules take toAddresses/toPorts (e.g. a dst-nat port forward). Uses comment as idempotency key for deduplication and identification: a repeated add returns already_exists only when the match, NAT targets, and disabled state agree, otherwise CONFLICT (use enable/disable when only the disabled state differs). Supports dry-run mode. Every real write is guarded by a dead-man switch (autoRevertSeconds, default 60): a RouterOS scheduler job that undoes the change is armed first and removed only once the router answers a new REST connection afterwards, so a rule that locks out management reverts itself.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"action": "<action>",
"chain": "<chain>",
"ruleAction": "<ruleAction>"
},
"name": "manage_firewall_rule"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | Yes | Firewall chain (e.g. forward, input, output, srcnat, dstnat) | |
| table | No | Firewall table to manage: filter or nat | filter |
| action | Yes | Action to perform: add, remove, disable, or enable a firewall rule | |
| dryRun | No | If true, validate and return planned changes without applying | |
| comment | No | Comment to identify the rule (used as idempotency key); omit for none | |
| dstPort | No | Destination port or range | |
| srcPort | No | Source port or range | |
| toPorts | No | NAT target port or range (nat table only) | |
| disabled | No | Whether the rule should be disabled | |
| protocol | No | Protocol to match | |
| routerId | No | Router ID; omit to use the default router. | |
| dstAddress | No | Destination address or network | |
| ruleAction | Yes | RouterOS rule action (e.g. accept, drop, reject, masquerade) | |
| srcAddress | No | Source address or network | |
| inInterface | No | Incoming interface | |
| placeBefore | No | Place the new rule before this rule ID | |
| toAddresses | No | NAT target address or range (nat table only, e.g. dst-nat) | |
| outInterface | No | Outgoing interface | |
| connectionState | No | Connection-tracking states, comma-separated, optionally negated: established,related or !invalid | |
| inInterfaceList | No | Incoming interface list, e.g. WAN or !LAN | |
| outInterfaceList | No | Outgoing interface list, e.g. WAN or !LAN | |
| autoRevertSeconds | No | Dead-man switch: before the write, arm a RouterOS scheduler job that undoes it after this many seconds; it is removed once the router answers a new REST connection after the change. 0 turns it off. Default 60 | |
| confirmationToken | No | Token from a prior APPROVAL_REQUIRED response. Re-submit the identical call with this token to confirm the destructive action. | |
| connectionNatState | No | Connection NAT state to match, e.g. dstnat or !dstnat |