OPNsense MCP

OPNsense MCP

Enables remote agents to securely read firewall and NAT rules, inspect routing tables and logs, and execute safety-gated mutation plans through a bearer-authenticated MCP endpoint.

Category
访问服务器

README

OPNsense MCP

A safety-focused remote Model Context Protocol server for OPNsense's MVC API. It exposes stateful Streamable HTTP for remote agents, uses the API's native HTTP Basic authentication upstream, and fails closed when it cannot determine whether an OPNsense command is read-only.

One server instance represents one OPNsense firewall. The firewall URL and API credentials stay in the server environment; agents authenticate to MCP with a separate bearer token and cannot redirect requests to arbitrary network targets. Deploy one isolated instance per firewall when managing multiple appliances.

Architecture

Remote agent --HTTPS + MCP bearer token--> OPNsense MCP --HTTPS + API key/secret--> OPNsense

The MCP endpoint uses the current Streamable HTTP transport at /mcp. Sessions are stateful so one-time mutation plans remain bound to the agent's MCP session. Sessions are capped, expire after inactivity, and authenticate on every HTTP request.

The built-in HTTP listener is intended to sit behind a TLS reverse proxy, ingress controller, VPN, or private overlay. Do not expose its plain HTTP port directly to an untrusted network.

OPNsense API Model

OPNsense routes API requests as:

/api/<module>/<controller>/<command>/<parameter...>

The important behaviors for automation are:

  • API keys use HTTP Basic authentication: key as username, secret as password.
  • Access is still constrained by the key owner's OPNsense ACL privileges.
  • Requests and most responses are JSON. Downloads and streams may not be.
  • GET and POST do not map cleanly to safe and unsafe operations. Some reads use POST, and some mutations use GET.
  • Mutable model controllers commonly expose get, search, add, set, del, and toggle operations.
  • Array model records use UUIDs. A get without a UUID often returns a blank record populated with defaults.
  • A successful model mutation usually writes staged configuration. A separate apply or reconfigure activates it.
  • Model writes return values such as {"result":"saved"} or {"result":"failed","validations":...}; HTTP 200 alone does not prove semantic success.
  • OPNsense configuration locking, model validation, revision context, and ACL checks happen server-side and should not be bypassed.

Official references:

Safety Model

opnsense_request accepts only commands classified as reads. Classification is based on the command, not its HTTP method.

Mutations use two tools:

  • opnsense_plan_change reports the exact request and its risk without contacting OPNsense.
  • opnsense_execute_change requires a matching one-time token that expires after five minutes.

Risk classes distinguish staged writes, activation, disruptive service or firmware operations, and catastrophic reset/restore operations. Unknown commands fail closed as mutations.

The write mode is controlled outside the agent:

  • disabled permits reads only.
  • plan permits mutation analysis but never creates an execution token.
  • enabled permits execution with a matching token.

Use a dedicated OPNsense user and grant only the effective privileges required by the intended tools. For read-only deployments, also grant System: Deny config write (user-config-readonly) in OPNsense.

Curated Read Tools

The guarded generic client is supplemented by fixed read-only tools for common operational tasks:

  • opnsense_get_firewall_logs reads structured packet-filter events.
  • opnsense_get_logs reads bounded pages from core and service logs, including system, configd, gateways, VPN, DNS, DHCP, IDS, routing, and web UI logs.
  • opnsense_list_firewall_rules reads filter rules visible to the automation API.
  • opnsense_list_nat_rules reads destination, source, one-to-one, or NPT rules.
  • opnsense_get_route_table reads either the live kernel routing table or configured static routes.

These tools call fixed query endpoints directly. They cannot select mutating sibling actions such as clearing logs, flushing states, changing rules, or applying configuration. Results remain subject to the API user's OPNsense ACL privileges.

Setup

npm install
npm run build

Configure the environment using .env.example as a reference. Environment files are not loaded automatically and are ignored by Git. Generate a separate MCP token with openssl rand -hex 32; do not reuse an OPNsense API credential.

Prefer a publicly trusted certificate or set OPNSENSE_CA_FILE to the private CA certificate. OPNSENSE_TLS_VERIFY=false exists for isolated development only.

Run the remote server on loopback for a local TLS reverse proxy:

OPNSENSE_URL=https://firewall.example \
OPNSENSE_API_KEY=... \
OPNSENSE_API_SECRET=... \
MCP_AUTH_TOKEN=<random-token-at-least-32-characters> \
node dist/index.js

The MCP URL is http://127.0.0.1:3000/mcp. Publish it as HTTPS through the reverse proxy and pass the token as:

Authorization: Bearer <MCP_AUTH_TOKEN>

Example remote client configuration for clients that support URL and custom headers:

{
  "mcpServers": {
    "opnsense": {
      "url": "https://mcp.example.com/mcp",
      "headers": {
        "Authorization": "Bearer ${MCP_AUTH_TOKEN}"
      }
    }
  }
}

Client configuration formats vary. Store the token in the client's secret facility rather than committing it in a configuration file.

Docker Compose

compose.yaml binds port 3000 to host loopback so a reverse proxy can terminate TLS safely.

export OPNSENSE_URL=https://firewall.example
export OPNSENSE_API_KEY=...
export OPNSENSE_API_SECRET=...
export MCP_AUTH_TOKEN="$(openssl rand -hex 32)"
export MCP_ALLOWED_HOSTS=mcp.example.com
docker compose up -d --build

When connecting directly to localhost:3000 during development, include localhost in MCP_ALLOWED_HOSTS. The unauthenticated health endpoint is available at /health and returns no target or credential details.

Remote Security

  • MCP_AUTH_TOKEN is mandatory for HTTP transport and must contain at least 32 characters.
  • MCP_ALLOWED_HOSTS is mandatory when binding to a non-loopback address and prevents Host-header DNS rebinding.
  • Requests with a browser Origin header are rejected unless the exact origin appears in MCP_ALLOWED_ORIGINS.
  • MCP_MAX_SESSIONS, MCP_SESSION_TTL_MS, and MCP_RATE_LIMIT_PER_MINUTE bound remote resource use.
  • Keep OPNSENSE_TLS_VERIFY=true. Use OPNSENSE_CA_FILE for an internal CA rather than disabling verification.
  • Keep OPNSENSE_WRITE_MODE=disabled for monitoring-only deployments.
  • Restrict the OPNsense API user with effective ACL privileges and user-config-readonly where appropriate.
  • Put the MCP endpoint behind HTTPS, firewall policy, and preferably a VPN or private network.

MCP_ALLOW_UNAUTHENTICATED=true exists only for isolated local development and should never be used for a remotely reachable listener.

Stdio Compatibility

Local clients can still launch the server as a subprocess:

OPNSENSE_URL=https://firewall.example \
OPNSENSE_API_KEY=... \
OPNSENSE_API_SECRET=... \
MCP_TRANSPORT=stdio \
node dist/index.js

Configuration

  • OPNSENSE_URL: fixed firewall base URL.
  • OPNSENSE_API_KEY: API key for the dedicated OPNsense user.
  • OPNSENSE_API_SECRET: API secret for that key.
  • OPNSENSE_WRITE_MODE: disabled, plan, or enabled.
  • OPNSENSE_CA_FILE: optional private CA PEM file.
  • OPNSENSE_TLS_VERIFY: defaults to true.
  • MCP_TRANSPORT: http by default, or stdio.
  • MCP_HOST: listener address, default 127.0.0.1.
  • MCP_PORT: listener port, default 3000.
  • MCP_PATH: MCP endpoint path, default /mcp.
  • MCP_AUTH_TOKEN: remote-agent bearer token.
  • MCP_ALLOWED_HOSTS: comma-separated hostnames accepted in the HTTP Host header.
  • MCP_ALLOWED_ORIGINS: comma-separated browser origins; empty rejects browser-originated requests.
  • MCP_MAX_SESSIONS: concurrent session cap, default 100.
  • MCP_SESSION_TTL_MS: idle session lifetime, default one hour.
  • MCP_RATE_LIMIT_PER_MINUTE: per-client HTTP request limit, default 120.

For example, a read call for system status uses:

{
  "module": "core",
  "controller": "system",
  "command": "status"
}

Current Limits

  • OPNsense does not publish a complete OpenAPI contract. The generated reference identifies routes and likely methods, but usually omits body schemas.
  • Plugin endpoints exist only when their packages are installed and ACL-authorized.
  • Semantic response validation is not yet endpoint-specific.
  • The lexical risk classifier is intentionally conservative. Curated tools should eventually use an audited endpoint manifest with explicit request and response schemas.
  • Plan tokens reduce accidental and mismatched execution, but MCP hosts should still present destructive tool approval to a human.
  • Remote authentication currently uses a deployment-wide static bearer token rather than an OAuth authorization server. Use separate deployments or an authenticating reverse proxy when agents require distinct identities.
  • Session state is in memory and is not shared across replicas. Run one replica unless external session storage and routing affinity are added.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选