OPNsense MCP Server
Provides tools for managing OPNsense firewalls, including system status, firewall rules, network diagnostics, DNS, DHCP, VPN, HAProxy, services, and security settings.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@OPNsense MCP Servershow me the current firewall rules"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
OPNsense MCP Server
A secure Model Context Protocol (MCP) server for managing OPNsense firewalls through AI assistants like Claude Code, Cursor, and other MCP-compatible tools.
81 tools across 10 domains: system, firewall, network, DNS, DHCP, VPN, HAProxy, services, diagnostics, and security.
Requirements
Python 3.11+
OPNsense 24.7 or newer — the MCP server relies on the MVC-based API endpoints introduced in OPNsense 24.7. Older versions use a different API structure that is not compatible. The server auto-detects the OPNsense version on first connect and selects the correct endpoint naming (camelCase for pre-25.7, snake_case for 25.7+). OPNsense 26.x is fully supported, including its changed firmware status response format.
Related MCP server: allcanuse-mcp
Security Model
This MCP server is designed with security as the primary concern:
Read-only by default — write operations require explicit opt-in via
OPNSENSE_ALLOW_WRITES=trueSavepoint/rollback — all firewall modifications use OPNsense's built-in 60-second auto-revert mechanism; changes must be explicitly confirmed or they roll back automatically
Endpoint blocklist — dangerous endpoints (
halt,reboot,poweroff,firmware update/upgrade) are hard-blocked at the API client level and can never be calledAPI-only — no SSH access, no command execution, no direct config file manipulation
Local transport — STDIO only, no network-exposed HTTP/SSE endpoints
No credential exposure — API keys are never included in tool output, logs, or error messages
Input validation — hostname parameters are validated against shell metacharacter injection
Sensitive data stripping — config backup strips passwords and keys by default
Quick Start
1. Create an OPNsense API Key
Log in to your OPNsense web interface
Go to System > Access > Users
Either edit an existing user or create a dedicated API user:
For production use, create a dedicated user (e.g.,
mcp-api) with only the privileges neededFor read-only access, assign the user to a group with read-only API access
Scroll down to the API keys section and click the + button
A key/secret pair will be generated and a file (
apikey.txt) will be downloadedThe file contains two lines —
key=your-api-key-hereandsecret=your-api-secret-hereStore these credentials securely — the secret cannot be retrieved again from OPNsense
Tip: For a read-only setup (recommended for getting started), you don't need to change any permissions — the default API access is sufficient for all read-only tools.
2. Install
# Using pip
pip install opnsense-mcp-server
# Using uv (recommended for isolated environments)
uv pip install opnsense-mcp-server
# Using Docker
docker pull lucamarien/opnsense-mcp-server
# From source
git clone https://github.com/lucamarien/opnsense-mcp-server
cd opnsense-mcp-server
pip install -e .3. Configure Your AI Assistant
Claude Code
Add to your project's .mcp.json:
{
"mcpServers": {
"opnsense": {
"command": "opnsense-mcp",
"env": {
"OPNSENSE_URL": "https://192.168.1.1/api",
"OPNSENSE_API_KEY": "your-api-key-here",
"OPNSENSE_API_SECRET": "your-api-secret-here",
"OPNSENSE_VERIFY_SSL": "false",
"OPNSENSE_ALLOW_WRITES": "false"
}
}
}
}Alternative: Use
"command": "python", "args": ["-m", "opnsense_mcp"]if theopnsense-mcpCLI is not on your PATH.
Or add it globally to ~/.claude/claude_code_config.json.
Claude Code (Docker)
{
"mcpServers": {
"opnsense": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "OPNSENSE_URL=https://192.168.1.1/api",
"-e", "OPNSENSE_API_KEY=your-api-key-here",
"-e", "OPNSENSE_API_SECRET=your-api-secret-here",
"-e", "OPNSENSE_VERIFY_SSL=false",
"-e", "OPNSENSE_ALLOW_WRITES=false",
"lucamarien/opnsense-mcp-server"
]
}
}
}Cursor
Add to your Cursor MCP settings (Settings > MCP):
{
"mcpServers": {
"opnsense": {
"command": "opnsense-mcp",
"env": {
"OPNSENSE_URL": "https://192.168.1.1/api",
"OPNSENSE_API_KEY": "your-api-key-here",
"OPNSENSE_API_SECRET": "your-api-secret-here",
"OPNSENSE_VERIFY_SSL": "false"
}
}
}
}Configuration
Environment Variable | Default | Description |
| (required) | OPNsense API base URL (must end with |
| (required) | API key from OPNsense user settings |
| (required) | API secret from OPNsense user settings |
|
| Verify SSL certificate ( |
|
| Enable write operations (firewall rules, service control) |
Custom ports: If your OPNsense web GUI runs on a non-standard port (e.g., 10443), include it in the URL: https://192.168.1.1:10443/api
Available Tools (81)
System (7 tools)
Tool | Description |
| System info including firmware version, product name, and architecture |
| List all services and their running status. Params: |
| Gateway availability, latency, and dpinger health checks |
| Download |
| Scan the full configuration, parse it into sections, and collect runtime inventory (firmware, plugins, DHCP, DNS, interfaces, services). Results are cached per session. Params: |
| Get a specific config section as structured JSON. Params: |
| MCP server version, write mode status, detected OPNsense version, and API style |
Network (5 tools)
Tool | Description |
| Per-interface traffic statistics (bytes in/out, packets, errors) |
| ARP table showing IP-to-MAC address mappings |
| NDP (Neighbor Discovery Protocol) table showing IPv6-to-MAC address mappings |
| IPv6 configuration and address status for all interfaces (method, live addresses, summary) |
| Configured static routes. Params: |
Firewall (21 tools)
Tool | Description | Writes |
| List MVC firewall filter rules. Params: | No |
| List alias definitions (IP lists, port groups, GeoIP, URLs). Params: | No |
| List NAT port forwarding (DNAT) rules. Params: | No |
| List firewall rule categories and their UUIDs. Params: | No |
| Recent firewall log entries with client-side filtering. Params: | No |
| Confirm pending changes, cancelling 60-second auto-rollback. Params: | Yes |
| Toggle a rule's enabled/disabled state with savepoint. Params: | Yes |
| Create a new filter rule with savepoint. Params: | Yes |
| Delete a filter rule by UUID with savepoint. Params: | Yes |
| Create a new alias. Params: | Yes |
| Create a NAT port forwarding rule with savepoint. Params: | Yes |
| Create a new firewall rule category. Params: | Yes |
| Delete a firewall rule category by UUID with savepoint. Params: | Yes |
| Assign categories to a firewall rule with savepoint. Params: | Yes |
| Create essential ICMPv6 rules required for IPv6 operation (NDP, RA, ping6) per RFC 4890. Params: | Yes |
| Update an existing alias (name, content, type, description). Read-modify-write. Params: | Yes |
| Delete an alias by UUID. Check rule references first. Params: | Yes |
| Toggle alias enabled/disabled state. Params: | Yes |
| Update filter rule fields with savepoint. Params: | Yes |
| Update NAT port forwarding rule with savepoint. Params: | Yes |
| Delete a NAT port forwarding rule by UUID with savepoint. Params: | Yes |
DNS (13 tools)
Tool | Description | Writes |
| Unbound host overrides (local DNS records). Params: | No |
| DNS forward zones (domain-specific servers). Params: | No |
| Unbound resolver statistics (queries, cache hits, uptime) | No |
| Apply pending DNS resolver configuration changes | Yes |
| Add an Unbound DNS host override (A/AAAA record) and apply immediately. Params: | Yes |
| List DNSBL blocklist configurations with providers and status. Params: | No |
| Get full DNSBL configuration by UUID (providers, allowlists, settings). Params: | No |
| Update DNSBL settings (read-modify-write). Params: | Yes |
| Add domains to DNSBL allowlist without overwriting. Params: | Yes |
| Remove domains from DNSBL allowlist. Params: | Yes |
| Reload DNSBL blocklist files and restart Unbound (no config change, recovery tool) | Yes |
| Update an Unbound DNS host override and apply immediately. Params: | Yes |
| Delete an Unbound DNS host override and apply immediately. Params: | Yes |
DHCP (8 tools)
Tool | Description | Writes |
| Active DHCPv4 leases from the ISC DHCP server | No |
| DHCPv4 leases from the Kea DHCP server. Params: | No |
| DHCPv4 and DHCPv6 leases from the dnsmasq DNS/DHCP server. Params: | No |
| Configured DHCP address ranges (both DHCPv4 and DHCPv6 with RA config). Params: | No |
| Create a new DHCP range (IPv4 or IPv6 with Router Advertisement configuration). Params: | Yes |
| Apply pending dnsmasq DNS/DHCP configuration changes | Yes |
| Update a DHCP range (addresses, lease time, RA config) and apply. Params: | Yes |
| Delete a DHCP range by UUID and apply. Params: | Yes |
VPN (3 tools)
Tool | Description |
| WireGuard tunnel and peer status (requires os-wireguard plugin) |
| IPsec VPN tunnel status — IKE (Phase 1) and ESP/AH (Phase 2) sessions |
| OpenVPN connection status — instances, sessions, and routes |
HAProxy (8 tools)
Full configuration management for the HAProxy load balancer (requires os-haproxy plugin).
Tool | Description | Writes |
| HAProxy service status and backend health | No |
| Search HAProxy resources by type. Params: | No |
| Get detailed configuration for a specific resource. Params: | No |
| Validate HAProxy configuration syntax before applying | No |
| Create a new HAProxy resource. Params: | Yes |
| Update an existing HAProxy resource (partial updates). Params: | Yes |
| Delete a HAProxy resource by UUID. Params: | Yes |
| Apply pending HAProxy configuration changes | Yes |
Note: HAProxy changes do NOT use savepoint protection — they apply immediately on reconfigure. Always call
opn_haproxy_configtestbeforeopn_reconfigure_haproxy.
Services (11 tools)
Tool | Description | Writes |
| ACME/Let's Encrypt certificates and their status. Params: | No |
| Scheduled cron jobs. Params: | No |
| CrowdSec security engine status and active decisions | No |
| CrowdSec security alerts (detected threats). Params: | No |
| Dynamic DNS accounts and their update status. Params: | No |
| Create a new Dynamic DNS account. Params: | Yes |
| Apply pending Dynamic DNS configuration changes | Yes |
| Update a Dynamic DNS account (password is write-only). Params: | Yes |
| Delete a Dynamic DNS account by UUID. Params: | Yes |
| mDNS Repeater status and configuration (enabled, interfaces, blocklist). Requires | No |
| Configure mDNS Repeater for cross-VLAN device discovery (HomeKit, Chromecast, AirPlay). Params: | Yes |
Diagnostics (4 tools)
Tool | Description |
| Ping a host from the firewall to test connectivity. Params: |
| Trace network path to a destination. Params: |
| DNS lookup from the firewall. Params: |
| Query active PF state table. Params: |
Security (1 tool)
Tool | Description |
| Comprehensive 11-area security audit: firmware, firewall rules (MVC + legacy, port grouping, insecure protocols), NAT forwarding, DNS security (DNSSEC, DoT), system hardening (SSH, HTTPS, syslog), services, certificates (ACME + system + CAs), VPN (WireGuard config, IPsec, OpenVPN), HAProxy (headers, health checks), gateways. Findings tagged with PCI DSS v4.0, BSI IT-Grundschutz, NIST 800-41, CIS compliance references. |
Write Operations and Savepoints
Write operations require OPNSENSE_ALLOW_WRITES=true and use OPNsense's savepoint mechanism for safety:
Before any firewall change, a savepoint is created automatically
The change is applied (rule toggle, add, or delete)
A 60-second countdown starts — if not confirmed, OPNsense automatically reverts the change
Use
opn_confirm_changeswith the returnedrevisionto make changes permanent
This means if an AI assistant makes a bad firewall change that locks you out, the change will automatically revert within 60 seconds.
Note:
opn_reconfigure_unbound,opn_reconfigure_haproxy,opn_reconfigure_ddclient,opn_reconfigure_dnsmasq, andopn_configure_mdns_repeaterrequire writes but don't use savepoints — they apply service configuration changes and are not automatically revertible.
IPv6 Support
Fully Automated via MCP
IPv6 Firewall Rules — Create rules with
ip_protocol="inet6"(savepoint-protected)HAProxy IPv6 Bindings — Frontends with
[::]:443or[2001:db8::1]:443bind addressesHAProxy IPv6 Backends — Servers with IPv6 addresses,
resolvePrefer: ipv6on backendsDynamic DNS with IPv6 — DDNS accounts with IPv6-capable checkip methods
DHCPv6 Ranges (dnsmasq) — IPv6 DHCP ranges with Router Advertisement configuration
DNS AAAA Records — Unbound host overrides with IPv6 addresses
IPv6 Diagnostics — Traceroute with
ip_version="6", ping via hostname
Requires Manual GUI Configuration
These settings lack MVC API support in OPNsense and must be configured via the web GUI:
WAN IPv6 setup — PPPoE with DHCPv6 prefix delegation, static IPv6, SLAAC
LAN IPv6 addressing — Track Interface mode, static /64 assignment, prefix ID
Interface assignment — Assigning physical ports to WAN/LAN/OPT roles
6to4/6rd tunnels — Transition tunnel mechanisms
Known Limitations
ISC DHCP / Kea DHCPv6: Not implemented. Only dnsmasq (the modern default) is supported for DHCPv6 ranges and Router Advertisements. ISC DHCP is deprecated; Kea DHCPv6 lease visibility is limited in the API.
radvd: Not implemented as a separate tool set. Dnsmasq handles Router Advertisements natively via range configuration. Only one RA daemon should run per interface.
Dual-stack firewall rules:
inet46(dual-stack) works correctly in MVC API rules (opn_add_firewall_rule). However,inet46in legacy XML filter rules (GUI) silently produces no PF output — this is a known OPNsense bug that only affects legacy rules.Legacy GUI rules: Firewall rules created via the traditional OPNsense GUI are not accessible through the MVC API. Use
opn_get_config_section("filter")for read-only access.
Recommended IPv6 Migration Workflow
Manual (GUI): Configure WAN IPv6 (DHCPv6-PD from ISP or static)
Manual (GUI): Configure LAN interfaces (Track Interface mode for prefix delegation)
MCP: Configure Router Advertisements via
opn_add_dnsmasq_rangewith RA flagsMCP: Create IPv6 firewall rules (ICMPv6 must be allowed for NDP/RA/PMTUD)
MCP: Add IPv6 DNS records via
opn_add_dns_overrideMCP: Configure Dynamic DNS with IPv6 checkip method
MCP: Add IPv6 bind addresses to HAProxy frontends
MCP: Verify with
opn_ping,opn_traceroute(ip_version="6"),opn_gateway_status
Version Compatibility
OPNsense Version | Status |
24.7 (Thriving Tiger) | Supported |
25.1 (Ultimate Unicorn) | Supported |
25.7 (Visionary Viper) | Supported (auto-detects snake_case API) |
26.1+ | Supported |
The server automatically detects the OPNsense version on first connection and selects the correct API endpoint naming convention (camelCase for pre-25.7, snake_case for 25.7+).
Note on firewall rules: opn_list_firewall_rules shows rules managed via the MVC/automation API. Rules configured through the OPNsense GUI use a legacy format not accessible via this API. This is a known OPNsense limitation.
Troubleshooting
Connection Issues
"Connection refused" or timeout errors
Verify
OPNSENSE_URLends with/api(e.g.,https://192.168.1.1/api)If using a non-standard port, include it:
https://192.168.1.1:10443/apiEnsure the OPNsense web GUI is accessible from the machine running the MCP server
SSL certificate errors
For self-signed certificates (default OPNsense setup), set
OPNSENSE_VERIFY_SSL=falseFor production, install a proper certificate on OPNsense and keep
OPNSENSE_VERIFY_SSL=true
Authentication Issues
401 Unauthorized
Verify
OPNSENSE_API_KEYandOPNSENSE_API_SECRETare correctAPI keys are case-sensitive — copy them exactly from the downloaded
apikey.txtCheck that the API user is not disabled in OPNsense
Verify the API user has sufficient privileges for the operations you're attempting
403 Forbidden
The API user may lack permissions for the requested endpoint
For write operations, ensure
OPNSENSE_ALLOW_WRITES=trueis set
Tool-Specific Issues
opn_list_firewall_rules returns empty results
This tool only shows MVC/automation rules, not legacy GUI rules
Create rules via the automation API or
opn_add_firewall_ruleto see them
opn_ping times out
The firewall may not have a route to the target host
Check gateway status with
opn_gateway_statusDefault timeout is 30 seconds (30 poll cycles)
opn_download_config shows [REDACTED] values
This is the default behavior for security. Pass
include_sensitive=trueto include passwords and keys (use with caution in AI conversations)
Write operations fail with "writes not enabled"
Set
OPNSENSE_ALLOW_WRITES=truein your MCP server configurationThis is intentionally disabled by default for safety
Savepoint confirmation fails
The
revisionparameter must match exactly what was returned by the write operationConfirmations must happen within 60 seconds or the change auto-reverts
Diagnostic Commands
If you need to debug the MCP server:
# Test API connectivity directly
curl -k -u "your-key:your-secret" https://your-opnsense-ip/api/core/firmware/status
# Run the server directly
python -m opnsense_mcp
# Run tests to verify installation
pytest -vDevelopment
# Clone and install dev dependencies
git clone https://github.com/lucamarien/opnsense-mcp-server
cd opnsense-mcp-server
pip install -e ".[dev]"
# Run all tests (no real OPNsense needed — all tests use mocked API)
pytest -v
# Full CI pipeline (lint, format, type check, security scan, tests)
make validate
# Individual checks
ruff check src/ tests/ # Lint (includes bandit security checks)
ruff format src/ tests/ # Format
mypy src/ --strict # Type checkingBest Practices
Domain-specific guides for common firewall configuration tasks:
WhatsApp Calling Firewall Rules — Allow WhatsApp voice/video calls through a default-deny firewall using URL table aliases and scoped rules
These guides show real-world MCP tool usage patterns and explain the security considerations behind each approach.
Contributing
See CONTRIBUTING.md for detailed guidelines. Key points:
All tests must use mocked API responses — never connect to a real OPNsense
No overlapping tools — each tool must have a distinct purpose
Write clear docstrings — they're the AI's only guide to tool selection
Return structured data (dicts), not formatted strings
Run
make validatebefore submitting
License
MIT
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/lucamarien/opnsense-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server