OPNsense MCP server
An MCP server that lets Claude Code read my OPNsense firewall freely and change rules only through guarded tools, with a validation report first, a backup before every write, and nothing live until a separate apply.
A firewall is the last place you want an AI to improvise. This is an MCP (Model Context Protocol) server for OPNsense, the firewall I run, written in Python with FastMCP. It lets Claude Code read the firewall freely and change rules only through a few narrow tools that take a backup first and stop short of making anything live.
The first job was diagnosis, not change. In October 2025 I wanted Claude Code to look at the firewall rules itself when a connection between two parts of the network timed out, instead of working from my screenshots of the web interface. So we built the read tools first: list the rules, show the interfaces and the routes, and test the API connection. The spec put writes last, in plain words: “Only after read operations are proven reliable should we enable modifications.” The first write tool, for adding a rule, came five days later, and its guards were committed before it: the validator and the backup manager first, then the write calls.
What adding a rule does
- The tool builds the rule and runs it through a validator. The answer starts with a validation report and a preview of the rule.
- If the report has an error-level finding, the tool stops there and asks for a typed “yes.” Nothing is written.
- It downloads the firewall configuration and saves a backup. If the backup fails, it aborts: “Backup is mandatory before write operations.”
- It sets a savepoint with an automatic rollback after 60 seconds, adds the rule, and only then cancels the rollback. If the add fails, the firewall rolls back by itself.
- The change is still not live. A separate call,
apply_firewall_changes, reloads the firewall.
Modifying and deleting a rule came in February 2026. Both take a backup first, both leave the change inactive until the apply call, and both warn in capital letters when the change could lock you out of the firewall’s own management. A modify shows the rule before and after.
The idea worth copying
The guards run in the tool, not in the model’s instructions. And the validator does not pretend to be the authority. It checks a rule against five principles (default deny, least privilege, defense in depth, separation of duties, and explicit justification) and scores it from 0 to 100. Its own documentation says what it is: “This validator provides ADVISORY warnings, not blocking enforcement. Human oversight is the final authority on rule acceptance.” The hard stops are the ones that protect a way back: no backup, no write; nothing live until apply.
Where it stands
The last change to the code was in February 2026, when we added the modify and delete tools and the savepoint. Since then the firewall has moved into code. In September 2026 I set a policy for which tool does what: “Ansible owns the shape. MCP makes small changes inside that shape. API is the fallback for MCP. SSH looks but does not touch.” In late October the firewall rules were imported into Terraform, so rule changes can go through review as code. This server keeps the small, bounded changes and the reading. The repository is private.
The same policy has a drift rule: a change made through this tool is temporary by default, and anything meant to last goes into code the same day.