OPNSense MCP Server
OPNSense MCP Server enables AI assistants to manage and automate OPNsense firewall operations via MCP tools.
Firewall Management: Create, update, delete, toggle, and list firewall rules; create rules from presets; find rules by description; apply changes.
Network Configuration: Manage VLANs (create, list, update, delete); view interfaces; list and find DHCP leases; manage ARP table entries (list, find by IP/MAC/interface/hostname, stats); find devices on VLANs.
NAT & Routing: NAT management (outbound rules, mode control, DMZ fixes) via SSH; comprehensive routing diagnostics and auto-fix.
DNS Blocklist: List, block, unblock, search, toggle, and apply predefined domain categories.
HAProxy Load Balancing: Create/list/delete backends, frontends, certificates, ACLs, actions; control service; get stats and backend health.
System Operations: Execute CLI commands over SSH; create/list/restore configuration backups; restart services; test connection.
Automation & Infrastructure-as-Code: Record, play, analyze, export/import macros; plan, apply, destroy deployments via IaC tools.
Safety Modes: Read-only and dry-run enforcement at API/SSH level to prevent unintended changes.
Provides tools for managing OPNSense firewalls, including VLAN creation and management, firewall rule configuration, network interface queries, and DHCP lease management
Implements an audit database for tracking changes made through the OPNSense MCP server
Used as an optional cache layer for improved performance in Phase 3 of the OPNSense MCP server
Click on "Deploy 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 Server list all firewall rules and show me any that allow traffic from the DMZ"
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 Model Context Protocol (MCP) server for comprehensive OPNsense firewall management. This server enables AI assistants like Claude to directly manage firewall configurations, diagnose network issues, and automate complex networking tasks.
Features
š„ Firewall Management
Complete CRUD operations for firewall rules
Proper handling of API-created "automation rules"
Inter-VLAN routing configuration
Batch rule creation and management
Enhanced persistence with multiple fallback methods
š NAT Configuration (SSH-based)
Outbound NAT rule management
NAT mode control (automatic/hybrid/manual/disabled)
No-NAT exception rules for inter-VLAN traffic
Automated DMZ NAT issue resolution
Direct XML configuration manipulation
š Network Diagnostics
Comprehensive routing analysis
ARP table inspection with vendor identification
Interface configuration management
Network connectivity troubleshooting
Auto-fix capabilities for common issues
š„ļø SSH/CLI Execution
Direct command execution on OPNsense
Configuration file manipulation
System-level operations not available via API
Service management and restarts
š Additional Capabilities
VLAN management
DHCP lease viewing and management
DNS blocklist configuration
HAProxy load balancer support
Configuration backup and restore
Infrastructure as Code support
Related MCP server: pfSense MCP Server
Installation
Prerequisites
Node.js 18+ to run the server (Bun 1.1.39+ to develop on it)
OPNsense firewall (v24.7+ recommended)
API credentials for OPNsense
SSH access (optional, for advanced features)
Quick Start with npm
Install the package:
npm install -g opnsense-mcp-serverCreate a
.envfile with your credentials:
# Required
OPNSENSE_HOST=https://your-opnsense-host:port
OPNSENSE_API_KEY=your-api-key
OPNSENSE_API_SECRET=your-api-secret
OPNSENSE_VERIFY_SSL=false
# Optional - for SSH features
OPNSENSE_SSH_HOST=your-opnsense-host
OPNSENSE_SSH_USERNAME=root
OPNSENSE_SSH_PASSWORD=your-password
# Or use SSH key
# OPNSENSE_SSH_KEY_PATH=~/.ssh/id_rsa
# Recommended for a new/production router ā see "Safety Modes" below
# OPNSENSE_READ_ONLY=trueStart the MCP server:
opnsense-mcp-serverā ļø Safety Modes (read this before pointing at a production router)
By default this server can make live, immediate changes to your firewall ā add/delete rules, change NAT, restart services, run whitelisted shell commands over SSH. Two environment variables (operator-only ā a tool call can never set or override them) add a safety net:
Variable | Effect |
| Every mutating API call and every non-read-only SSH command is rejected before it's sent. Write-capable tools are also hidden from the tool list, so the model never sees them as an option. |
| Mutating calls are simulated instead of sent ā you get a log line and a synthetic success response describing what would have happened, with no request reaching the router. |
Both are enforced at the two lowest-level chokepoints this server uses to
reach the router ā the API client and the SSH executor ā so they apply
uniformly across all 140+ tools, not on a per-tool basis. If both are set,
OPNSENSE_READ_ONLY wins.
# First time pointing this at a real router? Start here:
OPNSENSE_READ_ONLY=true
# Once you trust it, watch what it would do before going live:
OPNSENSE_DRY_RUN=true
# Remove both once you're confident.See CONFIGURATION.md for the config reference, or docs/features/safety-modes.md for how it works under the hood.
Quick Start with Bun (Faster)
Bun provides significantly faster startup times and better performance.
Install Bun (if not already installed):
curl -fsSL https://bun.sh/install | bashClone and install:
git clone https://github.com/vespo92/OPNSenseMCP.git
cd OPNSenseMCP
bun installCreate your
.envfile (same as npm version above)Run with Bun:
# Development with hot reload
bun run dev:bun
# Production
bun run start:bunUsing Bun with Claude Desktop
{
"mcpServers": {
"opnsense": {
"command": "bun",
"args": ["run", "/path/to/OPNSenseMCP/src/index.ts"],
"env": {
"OPNSENSE_HOST": "https://your-opnsense:port",
"OPNSENSE_API_KEY": "your-key",
"OPNSENSE_API_SECRET": "your-secret",
"OPNSENSE_VERIFY_SSL": "false"
}
}
}
}Usage with Claude Desktop (npm)
Add to your Claude Desktop configuration (claude_desktop_config.json):
{
"mcpServers": {
"opnsense": {
"command": "npx",
"args": ["opnsense-mcp-server"],
"env": {
"OPNSENSE_HOST": "https://your-opnsense:port",
"OPNSENSE_API_KEY": "your-key",
"OPNSENSE_API_SECRET": "your-secret",
"OPNSENSE_VERIFY_SSL": "false"
}
}
}
}Common Use Cases
Fix DMZ NAT Issues
// Automatically fix DMZ to LAN routing
await mcp.call('nat_fix_dmz', {
dmzNetwork: '10.0.6.0/24',
lanNetwork: '10.0.0.0/24'
});Create Firewall Rules
// Allow NFS from DMZ to NAS
await mcp.call('firewall_create_rule', {
action: 'pass',
interface: 'opt8',
source: '10.0.6.0/24',
destination: '10.0.0.14/32',
protocol: 'tcp',
destination_port: '2049',
description: 'Allow NFS from DMZ'
});Diagnose Routing Issues
// Run comprehensive routing diagnostics
await mcp.call('routing_diagnostics', {
sourceNetwork: '10.0.6.0/24',
destNetwork: '10.0.0.0/24'
});Execute CLI Commands
// Run any OPNsense CLI command
await mcp.call('system_execute_command', {
command: 'pfctl -s state | grep 10.0.6'
});MCP Tools Reference
The server provides 50+ MCP tools organized by category:
Firewall Tools
firewall_list_rules- List all firewall rulesfirewall_create_rule- Create a new rulefirewall_update_rule- Update existing rulefirewall_delete_rule- Delete a rulefirewall_apply_changes- Apply pending changes
NAT Tools
nat_list_outbound- List outbound NAT rulesnat_set_mode- Set NAT modenat_create_outbound_rule- Create NAT rulenat_fix_dmz- Fix DMZ NAT issuesnat_analyze_config- Analyze NAT configuration
Network Tools
arp_list- List ARP table entriesrouting_diagnostics- Diagnose routing issuesrouting_fix_all- Auto-fix routing problemsinterface_list- List network interfacesvlan_create- Create VLAN
System Tools
system_execute_command- Execute CLI commandbackup_create- Create configuration backupservice_restart- Restart a service
For a complete list, see docs/api/mcp-tools.md.
Documentation
Testing
The repository includes comprehensive testing utilities:
# Test NAT functionality
npx tsx scripts/test/test-nat-ssh.ts
# Test firewall rules
npx tsx scripts/test/test-rules.ts
# Test routing diagnostics
npx tsx scripts/test/test-routing.ts
# Run all tests
npm testDevelopment
Building from Source
This repo uses Bun as its development toolchain (install,
build, tests). The published package is still plain Node ā it is consumed as
node dist/index.js ā so Bun is only needed to work on the project, not to
run it.
git clone https://github.com/vespo92/OPNSenseMCP.git
cd OPNSenseMCP
bun install
bun run build
bun run testThe lockfile is bun.lock; there is no package-lock.json. CI runs
bun install --frozen-lockfile, so commit bun.lock alongside any
package.json change.
Project Structure
OPNSenseMCP/
āāā src/ # Source code
ā āāā api/ # API client
ā āāā resources/ # Resource implementations
ā āāā index.ts # MCP server entry
āāā docs/ # Documentation
āāā scripts/ # Utility scripts
ā āāā test/ # Test scripts
ā āāā debug/ # Debug utilities
ā āāā fixes/ # Fix scripts
āāā dist/ # Build outputTroubleshooting
API Authentication Failed
Verify API key and secret are correct
Ensure API access is enabled in OPNsense
Check firewall rules allow API access
SSH Connection Failed
Verify SSH credentials in
.envEnsure SSH is enabled on OPNsense
Check user has appropriate privileges
NAT Features Not Working
NAT management requires SSH access
Add SSH credentials to environment variables
Test with:
npx tsx scripts/test/test-nat-ssh.ts
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
Issues: GitHub Issues
Discussions: GitHub Discussions
Documentation: Full Documentation
Acknowledgments
Built for use with Anthropic's Claude
Implements the Model Context Protocol
Designed for OPNsense firewall
Version: 0.8.2 | Status: Production Ready | Last Updated: August 2025
Available Tools
64 toolsapply_blocklist_categoryC
Apply a predefined category of domain blocks
Inputs: category (required).
block_domainC
Add a domain to the DNS blocklist
Inputs: domain (required), description.
block_multiple_domainsC
Block multiple domains at once
Inputs: domains (required), description.
configureC
Configure OPNsense connection
Inputs: apiKey (required), apiSecret (required), host (required), verifySsl.
create_backupC
Create a configuration backup
Inputs: description.
create_firewall_presetC
Create a firewall rule from a preset
Inputs: interface (required), preset (required), description, destination, +1 more.
create_firewall_ruleC
Create a new firewall rule
Inputs: action (required), destination (required), direction (required), interface (required), +6 more.
create_vlanC
Create a new VLAN
Inputs: interface (required), tag (required), description, pcp.
delete_firewall_ruleC
Delete a firewall rule
Inputs: uuid (required).
delete_vlanC
Delete a VLAN
Inputs: tag (required).
find_arp_by_hostnameC
Find ARP entries by hostname pattern
Inputs: pattern (required).
find_arp_by_interfaceC
Find ARP entries on specific interface
Inputs: interface (required).
find_arp_by_ipC
Find ARP entries by IP address or subnet
Inputs: ipPattern (required).
find_arp_by_macC
Find ARP entries by MAC address
Inputs: macPattern (required).
find_device_by_macC
Find device by MAC address
Inputs: mac (required).
find_device_by_nameC
Find devices by hostname pattern
Inputs: pattern (required).
find_devices_on_vlanC
Find devices on specific VLAN
Inputs: vlanTag (required).
find_firewall_rulesC
Find firewall rules by description
Inputs: description (required).
get_arp_statsC
Get ARP table statistics
Inputs: no named parameters.
get_devices_by_interfaceB
Group devices by network interface
Inputs: no named parameters.
get_firewall_ruleC
Get firewall rule details
Inputs: uuid (required).
get_guest_devicesB
Get all devices on guest network (VLAN 4)
Inputs: no named parameters.
get_interfacesB
List available network interfaces
Inputs: no named parameters.
get_vlanC
Get VLAN details
Inputs: tag (required).
haproxy_acl_createC
Create an ACL for HAProxy frontend
Inputs: expression (required), frontend (required), name (required).
haproxy_action_createC
Create an action for HAProxy frontend
Inputs: frontend (required), type (required), backend, condition, +1 more.
haproxy_backend_createC
Create a new HAProxy backend
Inputs: balance (required), mode (required), name (required), description, +1 more.
haproxy_backend_deleteC
Delete an HAProxy backend
Inputs: uuid (required).
haproxy_backend_healthC
Get health status of a specific backend
Inputs: backend (required).
haproxy_backend_listB
List all HAProxy backends
Inputs: no named parameters.
haproxy_certificate_createC
Create a certificate for HAProxy
Inputs: name (required), type (required), ca, certificate, +3 more.
haproxy_certificate_listB
List available certificates for HAProxy
Inputs: no named parameters.
haproxy_frontend_createC
Create a new HAProxy frontend
Inputs: backend (required), bind (required), mode (required), name (required), +4 more.
haproxy_frontend_deleteC
Delete an HAProxy frontend
Inputs: uuid (required).
haproxy_frontend_listB
List all HAProxy frontends
Inputs: no named parameters.
haproxy_service_controlC
Control HAProxy service (start, stop, restart, reload)
Inputs: action (required).
haproxy_statsC
Get HAProxy statistics
Inputs: no named parameters.
iac_apply_deploymentC
Apply a deployment plan
Inputs: planId (required), autoApprove.
iac_destroy_deploymentC
Destroy deployed resources
Inputs: deploymentId (required), force.
iac_list_resource_typesB
List available resource types
Inputs: category.
iac_plan_deploymentC
Plan infrastructure deployment changes
Inputs: name (required), resources (required), dryRun.
list_arp_entriesB
List all ARP table entries
Inputs: no named parameters.
list_backupsB
List available backups
Inputs: no named parameters.
list_dhcp_leasesC
List all DHCP leases
Inputs: interface.
list_dns_blocklistB
List all DNS blocklist entries
Inputs: no named parameters.
list_firewall_rulesC
List all firewall rules
Inputs: no named parameters.
list_vlansB
List all VLANs
Inputs: no named parameters.
macro_analyzeC
Analyze a macro to detect patterns and parameters
Inputs: id (required).
macro_deleteC
Delete a saved macro
Inputs: id (required).
macro_exportC
Export all macros to a file
Inputs: path (required).
macro_generate_toolC
Generate an MCP tool definition from a macro
Inputs: id (required), save.
macro_importC
Import macros from a file
Inputs: path (required), overwrite.
macro_listB
List all saved macros
Inputs: no named parameters.
macro_playC
Play a saved macro
Inputs: id (required), dryRun, parameters.
macro_start_recordingC
Start recording API calls to create a macro
Inputs: description (required), name (required).
macro_stop_recordingB
Stop recording and save the macro
Inputs: no named parameters.
restore_backupC
Restore a configuration backup
Inputs: backupId (required).
search_dns_blocklistC
Search DNS blocklist entries
Inputs: pattern (required).
test_connectionB
Test API connection and authentication
Inputs: no named parameters.
toggle_blocklist_entryB
Enable/disable a DNS blocklist entry
Inputs: uuid (required).
toggle_firewall_ruleC
Toggle firewall rule enabled/disabled
Inputs: uuid (required).
unblock_domainB
Remove a domain from the DNS blocklist
Inputs: domain (required).
update_firewall_ruleC
Update a firewall rule
Inputs: uuid (required), description, destination, destinationPort, +3 more.
update_vlanC
Update VLAN description
Inputs: description (required), tag (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogā¦
TDQS
Scored across 64 tools
The tool set has clear groupings by domain (e.g., ARP, firewall, HAProxy, macros), which helps disambiguation within groups, but there is significant overlap across some tools. For example, multiple ARP-related tools (find_arp_by_hostname, find_arp_by_interface, find_arp_by_ip, find_arp_by_mac) have very similar purposes and could be confused, and the macro tools (macro_play, macro_start_recording, macro_stop_recording) have overlapping functionalities. However, descriptions provide enough detail to differentiate them in most cases.
Naming is mostly consistent with a verb_noun pattern (e.g., create_firewall_rule, delete_vlan, list_arp_entries), and snake_case is used throughout. There are minor deviations, such as 'configure' and 'test_connection' which omit the noun, and 'iac_apply_deployment' uses a prefix, but overall the pattern is predictable and readable across the set.
With 64 tools, the count is excessive for a single server, making it feel heavy and potentially overwhelming. While OPNsense is a broad platform, the tools cover multiple distinct domains (e.g., firewall, VLAN, HAProxy, macros, ARP), suggesting they might be better split into separate, more focused servers. This large number increases complexity and reduces coherence.
The tool surface is quite comprehensive for the OPNsense domain, covering core areas like firewall rules (create, get, list, update, delete, toggle), VLAN management, DNS blocklisting, HAProxy configuration, and macro operations. Minor gaps exist, such as no direct tools for DHCP configuration beyond listing leases, but overall, it provides good CRUD/lifecycle coverage and few dead ends for agents.
Maintenance
Related MCP Connectors
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
Manage a Discord server from Claude, ChatGPT or any MCP client. Sign in with Discord, no bot token.
Hosted OpenAI Ads MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server implementation for managing OPNsense firewalls. This server allows Claude and other MCP-compatible clients to interact with all features exposed by the OPNsense API.1AGPL 3.0
- AlicenseCqualityBmaintenanceA production-grade server that enables natural language interaction with pfSense firewalls through Claude Desktop and other GenAI applications, supporting multiple access levels and functional categories.332123MIT
- -licenseNot gradedqualityNot gradedmaintenanceA production-ready server that connects Claude Desktop to Firewalla network management capabilities, allowing users to monitor devices, analyze network traffic, manage security alerts, and configure firewall rules through natural language.-
- AlicenseNot gradedqualityDmaintenanceEnables natural language management of OPNsense firewalls through AI clients, providing tools for firewall rules, system health, VPN monitoring, and more.AGPL 3.0