MCP Connector

Manage OPNsense Firewall Configurations

Control an OPNsense firewall from an AI assistant - firewall rules, NAT, VLANs, DHCP, and network diagnostics via 50+ tools.

Works with opnsensenpmgithub

Maintainer of this project? Claim this page to edit the listing.


91
Spark score
out of 100
Updated last month
Version 0.11.0
Models
claudeuniversal

Add to Favorites

Why it matters

Automate comprehensive OPNsense firewall management, enabling AI assistants to directly configure rules, diagnose network issues, and streamline complex networking tasks.

Outcomes

What it gets done

01

Perform CRUD operations on firewall rules

02

Automate outbound NAT rule management

03

Diagnose and fix routing issues

04

Manage VLAN configurations

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-opnsense-mcp | bash

Capabilities

Tools your agent gets

firewall_list_rules

List all firewall rules

firewall_create_rule

Create a new firewall rule

firewall_update_rule

Update an existing firewall rule

firewall_delete_rule

Delete a firewall rule

firewall_apply_changes

Apply pending firewall changes

nat_list_outbound

List outbound NAT rules

nat_set_mode

Set NAT mode configuration

nat_create_outbound_rule

Create a new NAT rule

+7 tools

Overview

OPNsense MCP Server

An MCP server giving AI assistants control over OPNsense: firewall rules, NAT, VLANs, DHCP, and network diagnostics via 50+ tools combining API and SSH. Use it when an assistant needs to manage OPNsense firewall rules, NAT, or diagnostics - write tools make live changes to production infrastructure.

What it does

OPNsense MCP Server gives AI assistants like Claude direct control over an OPNsense firewall - managing firewall rules, NAT configuration, VLANs, DHCP, DNS blocklists, HAProxy, and running network diagnostics - through 50+ MCP tools combining the OPNsense API with SSH-based operations for features the API doesn't expose.

When to use - and when NOT to

Use it when you want Claude to create, update, or delete firewall rules; configure outbound NAT (including automated DMZ NAT issue resolution); run routing and ARP diagnostics with auto-fix for common problems; manage VLANs and DHCP leases; or execute arbitrary CLI commands directly on the firewall. NAT management specifically requires SSH access in addition to API credentials, since it manipulates XML configuration directly. Do not use write tools like firewall_create_rule, nat_fix_dmz, or system_execute_command casually - they make live changes to production network infrastructure and firewall state. If something goes wrong, the project's own troubleshooting guidance is straightforward: for API authentication failures, verify the key/secret and that API access is enabled and not blocked by a firewall rule; for SSH failures, verify the credentials, that SSH is enabled on OPNsense, and that the user has appropriate privileges; and NAT features specifically won't work at all without SSH credentials configured, testable directly via the repo's test-nat-ssh.ts script.

Capabilities

Firewall: firewall_list_rules, firewall_create_rule, firewall_update_rule, firewall_delete_rule, firewall_apply_changes (full CRUD, with proper handling of API-created "automation rules" and inter-VLAN routing).
NAT (SSH-based): nat_list_outbound, nat_set_mode, nat_create_outbound_rule, nat_fix_dmz (automated DMZ NAT resolution), nat_analyze_config.
Network diagnostics: arp_list (with vendor identification), routing_diagnostics, routing_fix_all, interface_list, vlan_create.
System/SSH: system_execute_command (direct CLI execution), backup_create, service_restart.

50+ tools total, covering DHCP lease viewing, DNS blocklist configuration, HAProxy load balancer support, and configuration backup/restore for Infrastructure as Code workflows.

How to install

Requires Node.js 18+ (or Bun 1.0+), OPNsense v24.7+ recommended, and API credentials:

npm install -g opnsense-mcp-server

Configure a .env file:

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

Run opnsense-mcp-server, or configure Claude Desktop:

{
  "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"
      }
    }
  }
}

Bun is supported as a faster alternative runtime. NAT-related tools require the SSH environment variables set in addition to API credentials.

Who it's for

Network administrators and homelab/SMB IT teams running OPNsense who want an AI assistant to manage firewall rules, NAT, and diagnostics conversationally instead of navigating the OPNsense web UI.

Source README

OPNsense MCP Server

npm version
License: MIT

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

Installation

Prerequisites

  • Node.js 18+ or Bun 1.0+
  • OPNsense firewall (v24.7+ recommended)
  • API credentials for OPNsense
  • SSH access (optional, for advanced features)

Quick Start with npm

  1. Install the package:
npm install -g opnsense-mcp-server
  1. Create a .env file 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
  1. Start the MCP server:
opnsense-mcp-server

Quick Start with Bun (Faster)

Bun provides significantly faster startup times and better performance.

  1. Install Bun (if not already installed):
curl -fsSL https://bun.sh/install | bash
  1. Clone and install:
git clone https://github.com/vespo92/OPNSenseMCP.git
cd OPNSenseMCP
bun install
  1. Create your .env file (same as npm version above)

  2. Run with Bun:

# Development with hot reload
bun run dev:bun

# Production
bun run start:bun

Using 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 rules
  • firewall_create_rule - Create a new rule
  • firewall_update_rule - Update existing rule
  • firewall_delete_rule - Delete a rule
  • firewall_apply_changes - Apply pending changes

NAT Tools

  • nat_list_outbound - List outbound NAT rules
  • nat_set_mode - Set NAT mode
  • nat_create_outbound_rule - Create NAT rule
  • nat_fix_dmz - Fix DMZ NAT issues
  • nat_analyze_config - Analyze NAT configuration

Network Tools

  • arp_list - List ARP table entries
  • routing_diagnostics - Diagnose routing issues
  • routing_fix_all - Auto-fix routing problems
  • interface_list - List network interfaces
  • vlan_create - Create VLAN

System Tools

  • system_execute_command - Execute CLI command
  • backup_create - Create configuration backup
  • service_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 test

Development

Building from Source

git clone https://github.com/vespo92/OPNSenseMCP.git
cd OPNSenseMCP
npm install
npm run build

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 output

Troubleshooting

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 .env
  • Ensure 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

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.