by vespo92
OPNSenseMCP is a Model Context Protocol (MCP) server designed for managing OPNsense firewalls with Infrastructure as Code (IaC) capabilities, enabling declarative deployment and management of network infrastructure.
OPNSenseMCP is a Model Context Protocol (MCP) server that facilitates the management of OPNsense firewalls using Infrastructure as Code (IaC) principles. It acts as a proxy, allowing users to define and deploy their network infrastructure declaratively, similar to how software is developed and deployed.
To use OPNSenseMCP, you first need to clone the repository, install dependencies using npm install
, and then build the project with npm run build
. Configuration can be done via environment variables in a .env
file (e.g., OPNSENSE_HOST
, OPNSENSE_API_KEY
, OPNSENSE_API_SECRET
) or through manual configuration within your code. The server supports two transport modes: STDIO for direct integration with Claude Desktop and SSE for HTTP-based integration with agents and containers. You can start the server using npm start
for STDIO mode or npm run start:sse
for SSE mode.
OPNSenseMCP can be used for various network management tasks, including:
Q: What are common issues during connection? A: Connection refused errors often indicate that the OPNsense API is not enabled, firewall rules are blocking access, or SSL settings are incorrect. Authentication failures usually stem from incorrect API key/secret (ensure they are base64 encoded) or insufficient user permissions.
Q: Why is VLAN creation failing? A: Ensure the physical interface exists and is not in use, the VLAN tag is within the valid range (1-4094), and the interface supports VLAN tagging.
Q: How to troubleshoot build errors?
A: Try running npm ci
for a clean dependency installation. Verify that Node.js 18+ is installed and that your TypeScript version matches the project requirements.
A Model Context Protocol (MCP) server for managing OPNsense firewalls with Infrastructure as Code (IaC) capabilities.
=======
# Clone the repository
git clone https://github.com/vespo92/OPNSenseMCP
cd opnsense-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Copy and configure environment
cp .env.example .env
# Edit .env with your OPNsense credentials
The server supports two transport modes:
For direct integration with Claude Desktop:
npm start # or npm run start:stdio
For HTTP-based integration with agents and containers:
npm run start:sse # Starts on port 3000
npm run start:sse -- --port 8080 # Custom port
SSE Endpoints:
GET /sse
- SSE connection endpointPOST /messages
- Message handlingGET /health
- Health checkSee SSE Deployment Guide for container deployment.
The server supports multiple configuration methods:
The server automatically attempts to connect using environment variables on startup. Create a .env
file:
# Required
OPNSENSE_HOST=https://192.168.1.1 # or just 192.168.1.1:55443
OPNSENSE_API_KEY=your_api_key
OPNSENSE_API_SECRET=your_api_secret
# Optional
IAC_ENABLED=true
ENABLE_CACHE=false
REDIS_HOST=localhost
POSTGRES_HOST=localhost
If environment variables are not set or connection fails, use the configure
tool:
// Configure connection manually
await configure({
host: "https://192.168.1.1",
apiKey: "your_api_key",
apiSecret: "your_api_secret",
verifySsl: true
});
# Start the MCP server
npm start
# Or use with Claude Desktop
# Add to claude_desktop_config.json:
{
"mcpServers": {
"opnsense": {
"command": "node",
"args": ["dist/index.js"],
"cwd": "/path/to/opnsense-mcp",
"env": {
"OPNSENSE_HOST": "https://192.168.1.1:55443",
"OPNSENSE_API_KEY": "your_api_key",
"OPNSENSE_API_SECRET": "your_api_secret",
"OPNSENSE_VERIFY_SSL": "true"
}
}
}
}
Deploy network infrastructure declaratively:
{
"name": "home-network",
"resources": [{
"type": "opnsense:network:vlan",
"id": "guest-vlan",
"name": "Guest Network",
"properties": {
"interface": "igc3",
"tag": 10,
"description": "Isolated guest network"
}
}]
}
// Create a new VLAN for IoT devices
const vlan = {
type: "opnsense:network:vlan",
properties: {
interface: "igc3",
tag: 20,
description: "IoT Network - Isolated"
}
};
// Block all traffic from guest network to main LAN
const rule = {
type: "opnsense:firewall:rule",
properties: {
action: "block",
interface: "guest_vlan",
source: "guest_vlan_subnet",
destination: "lan_subnet",
description: "Block guest to LAN"
}
};
// Block social media sites
const blocklist = {
type: "opnsense:dns:blocklist",
properties: {
domains: ["facebook.com", "twitter.com", "tiktok.com"],
description: "Social media block",
enabled: true
}
};
// Deploy a complete guest network with isolation
const guestNetwork = {
name: "guest-network-setup",
resources: [
{
type: "opnsense:network:vlan",
id: "guest-vlan",
properties: {
interface: "igc3",
tag: 10,
description: "Guest WiFi Network"
}
},
{
type: "opnsense:firewall:rule",
id: "guest-internet",
properties: {
action: "pass",
interface: "guest_vlan",
source: "guest_vlan_subnet",
destination: "any",
description: "Allow guest internet"
}
},
{
type: "opnsense:firewall:rule",
id: "block-guest-lan",
properties: {
action: "block",
interface: "guest_vlan",
source: "guest_vlan_subnet",
destination: "lan_subnet",
description: "Isolate guest from LAN"
}
}
]
};
Once configured in Claude Desktop, you can ask Claude to:
Connection refused errors
Authentication failures
VLAN creation fails
Build errors
npm ci
for clean dependency installationFor more detailed troubleshooting, see our Troubleshooting Guide.
Contributions are welcome! Please read our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
Reviews feature coming soon
Stay tuned for community discussions and feedback