LO

lucamarien/opnsense-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

25 stars 11 forks 质量 83 趋势 15MIT

一台通过AI助手管理OPNsense防火墙的安全MCP服务器。拥有10个域的62个工具,支持只读默认、保存点回滚和安全审计。

概览

一台安全的模型上下文协议(MCP)服务器,通过 Claude Code、Cursor 及其他兼容 MCP 的工具等 AI 助手管理 OPNsense 防火墙。 涵盖10个领域:系统、防火墙、网络、DNS、DHCP、VPN、HAProxy、服务、诊断和安全。 - - MCP 服务器依赖于 OPNsense 24.7 引入的基于 MVC 的 API 端点。旧版本使用不同的 API 结构,且不兼容。服务器在首次连接时自动检测 OPNsense 版本,并选择正确的端点命名(25.7 之前用 camelCase,25.7+ 用 snake_case)。OPNsense 26.x 完全支持,包括其修改后的固件状态响应格式。 该MCP服务器以安全为首要考虑: - — 写入操作需要通过 OPNSENSE_ALLOW_WRITES=true 明确选择加入- — OPNsense 仍提供保存点 API,防火墙修改则使用其内置的 60 秒自动还原功能;更改必须明确确认,否则会自动回滚。

概述(AI 翻译)

一台安全的模型上下文协议(MCP)服务器,通过 Claude Code、Cursor 及其他兼容 MCP 的工具等 AI 助手管理 OPNsense 防火墙。

81个工具,涵盖10个领域:系统、防火墙、网络、DNS、DHCP、VPN、HAProxy、服务、诊断和安全。

要求

  • Python 3.11+
  • OPNsense 24.7 或更新版本 — MCP 服务器依赖于 OPNsense 24.7 引入的基于 MVC 的 API 端点。旧版本使用不同的 API 结构,且不兼容。服务器在首次连接时自动检测 OPNsense 版本,并选择正确的端点命名(25.7 之前用 camelCase,25.7+ 用 snake_case)。OPNsense 26.x 完全支持,包括其修改后的固件状态响应格式。

安全模型

该MCP服务器以安全为首要考虑:

  • 默认只读 — 写操作需要通过[[T0])显式选择加入。
  • 保存点/回滚(OPNsense 访问 >用户
  1. 编辑现有用户或创建专用 API 用户:
  • 用于生产环境,创建一个专用用户(例如,mcp-api),仅拥有所需的权限

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

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.

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=true
  • Savepoint/rollback (OPNsense < 26.7 only) — where OPNsense still offers the savepoint API, firewall modifications use its built-in 60-second auto-revert; changes must be explicitly confirmed or they roll back automatically. OPNsense 26.7 removed that API upstream — the server detects the missing endpoint at runtime and applies firewall changes immediately, with no automatic rollback
  • Endpoint blocklist — dangerous endpoints (halt, reboot, poweroff, firmware update/upgrade) are hard-blocked at the API client level and can never be called
  • API-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

  1. Log in to your OPNsense web interface
  2. Go to System > Access > Users
  3. 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 needed
    • For read-only access, assign the user to a group with read-only API access
  4. Scroll down to the API keys section and click the + button
  5. A key/secret pair will be generated and a file (apikey.txt) will be downloaded
  6. The file contains two lines — key=your-api-key-here and secret=your-api-secret-here
  7. Store 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
在 GitHub 查看完整 README

安装

docker 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 uhlenheide/opnsense-mcp-server
新手?先看 mcpskill.org 教程 →

配置

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