Skip to main content
Glama

Manage Firewall Rule

manage_firewall_rule
DestructiveIdempotent

Add, 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

NameRequiredDescriptionDefault
chainYesFirewall chain (e.g. forward, input, output, srcnat, dstnat)
tableNoFirewall table to manage: filter or natfilter
actionYesAction to perform: add, remove, disable, or enable a firewall rule
dryRunNoIf true, validate and return planned changes without applying
commentNoComment to identify the rule (used as idempotency key); omit for none
dstPortNoDestination port or range
srcPortNoSource port or range
toPortsNoNAT target port or range (nat table only)
disabledNoWhether the rule should be disabled
protocolNoProtocol to match
routerIdNoRouter ID; omit to use the default router.
dstAddressNoDestination address or network
ruleActionYesRouterOS rule action (e.g. accept, drop, reject, masquerade)
srcAddressNoSource address or network
inInterfaceNoIncoming interface
placeBeforeNoPlace the new rule before this rule ID
toAddressesNoNAT target address or range (nat table only, e.g. dst-nat)
outInterfaceNoOutgoing interface
connectionStateNoConnection-tracking states, comma-separated, optionally negated: established,related or !invalid
inInterfaceListNoIncoming interface list, e.g. WAN or !LAN
outInterfaceListNoOutgoing interface list, e.g. WAN or !LAN
autoRevertSecondsNoDead-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
confirmationTokenNoToken from a prior APPROVAL_REQUIRED response. Re-submit the identical call with this token to confirm the destructive action.
connectionNatStateNoConnection NAT state to match, e.g. dstnat or !dstnat

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.17.0
    • addedInput schema / properties / autoRevertSeconds
      Added value: +{
      +  "default": 60,
      +  "description": "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",
      +  "type": "integer"
      +}
  2. Changed14 schema fields changedv1.14.1
    • changedInput schema / properties / comment / description
      Previous value: -"Comment to identify the rule (used as idempotency key)"New value: +"Comment to identify the rule (used as idempotency key); omit for none"
    • addedInput schema / properties / comment / minLength
      Added value: +1
    • addedInput schema / properties / connectionNatState
      Added value: +{
      +  "description": "Connection NAT state to match, e.g. dstnat or !dstnat",
      +  "pattern": "^!?(srcnat|dstnat|srcnat,dstnat|dstnat,srcnat)$",
      +  "type": "string"
      +}
    • addedInput schema / properties / connectionState
      Added value: +{
      +  "description": "Connection-tracking states, comma-separated, optionally negated: established,related or !invalid",
      +  "pattern": "^!?(established|related|new|invalid|untracked)(,(established|related|new|invalid|untracked))*$",
      +  "type": "string"
      +}
    • addedInput schema / properties / dstAddress / minLength
      Added value: +1
    • addedInput schema / properties / dstPort / minLength
      Added value: +1
    • addedInput schema / properties / inInterface / minLength
      Added value: +1
    • addedInput schema / properties / inInterfaceList
      Added value: +{
      +  "description": "Incoming interface list, e.g. WAN or !LAN",
      +  "minLength": 1,
      +  "type": "string"
      +}
    • addedInput schema / properties / outInterface / minLength
      Added value: +1
    • addedInput schema / properties / outInterfaceList
      Added value: +{
      +  "description": "Outgoing interface list, e.g. WAN or !LAN",
      +  "minLength": 1,
      +  "type": "string"
      +}
    • addedInput schema / properties / srcAddress / minLength
      Added value: +1
    • addedInput schema / properties / srcPort / minLength
      Added value: +1
    • addedInput schema / properties / toAddresses
      Added value: +{
      +  "description": "NAT target address or range (nat table only, e.g. dst-nat)",
      +  "minLength": 1,
      +  "type": "string"
      +}
    • addedInput schema / properties / toPorts
      Added value: +{
      +  "description": "NAT target port or range (nat table only)",
      +  "pattern": "^\\d{1,5}(-\\d{1,5})?$",
      +  "type": "string"
      +}
  3. Changed2 schema fields changedv1.6.0
    • changedInput schema / properties / routerId / description
      Previous value: -"Target router identifier from the router registry"New value: +"Router ID; omit to use the default router."
    • changedInput schema / required
      Previous value: -[
      -  "routerId",
      -  "action",
      -  "chain",
      -  "ruleAction"
      -]New value: +[
      +  "action",
      +  "chain",
      +  "ruleAction"
      +]
  4. Addedv1.5.0
  5. Removedv1.1.0
  6. First observedv0.1.0

TDQS

A4.2/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only declare destructive, idempotent, non-read-only, and closed-world; the description goes well beyond by explaining the dead-man switch (autoRevertSeconds armed scheduler job, removed after a fresh REST connection confirms reachability), the conflict/idempotency semantics of the comment key, and the approval-token flow. These are exactly the behaviors an agent needs before invoking a lockout-capable network mutation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with the action list and resource, then layered detail on matching, idempotency, and the safety switch. It is a dense single paragraph that is slightly heavy, but each sentence carries non-redundant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 24-parameter destructive mutation with no output schema, it covers the risky essentials: dry-run, confirmation token, automatic revert, and the already_exists/CONFLICT outcomes. It never sketches the response shape (e.g. planned changes, APPROVAL_REQUIRED payload), leaving that to be discovered at call time.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3; the description still adds meaning by tying comment to idempotency/dedup, noting nat rules take toAddresses/toPorts for dst-nat port forwarding, and flagging autoRevertSeconds as the dead-man switch with 0 disabling it. The remaining 20+ parameters (interfaces, lists, placeBefore, connectionState) rely on the schema alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb set (add, remove, disable, enable) and a specific resource (firewall rule on a MikroTik router), plus a summary of what the rule matches on (addresses, ports, protocol, interfaces, connection/NAT state). This clearly separates it from the log, mangle, and routing-rule siblings, though it never names list_firewall_rules as the read counterpart.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives concrete routing guidance: use enable/disable rather than add when only the disabled state differs, use dry-run to validate, and re-submit with confirmationToken after an APPROVAL_REQUIRED response. It does not say when to reach for list_firewall_rules first to inspect existing rules, so one obvious workflow branch is left implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools