pfSense MCP Server

Enables natural language interaction with pfSense firewalls through GenAI applications.

pfSense Enhanced MCP Server

MseeP.ai Security Assessment Badge Version License MCP pfSense API Tests

A Model Context Protocol (MCP) server for managing pfSense firewalls through Claude Desktop, Claude Code, and other MCP-compatible clients. Verified against the pfSense REST API v2 PHP source code for production accuracy.

Supported pfSense Versions

pfSense VersionREST API PackageStatus
pfSense CE 2.8.1v2.7.3Verified
pfSense Plus 25.11v2.7.3Verified
pfSense CE 2.8.0v2.6.0+Supported
pfSense Plus 24.11v2.6.0+Supported
pfSense CE 26.03Not yet availablePending REST API package build

Requires the pfSense REST API v2 package by jaredhendrickson13.

Quick Start

1. Install pfSense REST API Package

SSH into your pfSense box and install the package for your version:

# pfSense CE 2.8.1
pkg-static add https://github.com/pfrest/pfSense-pkg-RESTAPI/releases/latest/download/pfSense-2.8.1-pkg-RESTAPI.pkg

# pfSense Plus 25.11
pkg-static -C /dev/null add https://github.com/pfrest/pfSense-pkg-RESTAPI/releases/latest/download/pfSense-25.11-pkg-RESTAPI.pkg

Then in the pfSense web UI: System > REST API to enable it, and System > User Manager > [your user] to generate an API key.

2. Setup MCP Server

git clone https://github.com/gensecaihq/pfsense-mcp-server.git
cd pfsense-mcp-server
pip install -r requirements.txt

cp .env.example .env
# Edit .env with your pfSense URL and API key

3. Configure Claude Desktop

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "pfsense": {
      "command": "python",
      "args": ["-m", "src.main"],
      "cwd": "/path/to/pfsense-mcp-server",
      "env": {
        "PFSENSE_URL": "https://your-pfsense.local",
        "PFSENSE_API_KEY": "your-api-key",
        "PFSENSE_VERSION": "CE_2_8_0",
        "AUTH_METHOD": "api_key",
        "VERIFY_SSL": "true"
      }
    }
  }
}

4. Start the Server

# stdio mode (default — for Claude Desktop / Claude Code)
python -m src.main

# HTTP mode (for remote access, requires MCP_API_KEY for bearer auth)
python -m src.main -t streamable-http --port 3000

MCP Tools (41 total)

Firewall Rules (9 tools)

ToolDescription
search_firewall_rulesSearch rules with filtering by interface, source IP, port, type, description
find_blocked_rulesFind all block/reject rules
create_firewall_rule_advancedCreate rule with position control and validation
update_firewall_ruleUpdate an existing rule by ID
delete_firewall_ruleDelete a rule by ID
move_firewall_ruleReorder a rule to a new position
apply_firewall_changesExplicitly trigger pf filter reload
bulk_block_ipsBlock multiple IPs with a single apply
get_pf_rulesRead the compiled pf ruleset (/tmp/rules.debug)

Aliases (5 tools)

ToolDescription
search_aliasesSearch aliases by name, type, or contained IP
create_aliasCreate a new alias (host, network, port, url)
update_aliasUpdate an existing alias
delete_aliasDelete an alias
manage_alias_addressesAdd or remove addresses from an alias

NAT Port Forwards (4 tools)

ToolDescription
search_nat_port_forwardsSearch port forward rules
create_nat_port_forwardCreate a port forward with validation
update_nat_port_forwardUpdate a port forward
delete_nat_port_forwardDelete a port forward

DHCP (7 tools)

ToolDescription
search_dhcp_leasesSearch active DHCP leases
search_dhcp_static_mappingsSearch static DHCP reservations
create_dhcp_static_mappingCreate a static mapping
update_dhcp_static_mappingUpdate a static mapping
delete_dhcp_static_mappingDelete a static mapping
get_dhcp_server_configGet DHCP server configuration
update_dhcp_server_configUpdate DHCP server settings

Services (2 tools)

ToolDescription
search_servicesList services with status filtering
control_serviceStart, stop, or restart a service by name

Logs & Monitoring (3 tools)

ToolDescription
get_firewall_logGet firewall log entries (max 50 lines)
analyze_blocked_trafficGroup blocked traffic by source IP with threat scoring
search_logs_by_ipSearch logs for a specific IP address

System (4 tools)

ToolDescription
system_statusGet CPU, memory, disk, and version info
search_interfacesSearch network interfaces
find_interfaces_by_statusFind interfaces by status (up/down)
get_arp_tableGet ARP table (IP-to-MAC mappings)

Utility (7 tools)

ToolDescription
follow_api_linkFollow a HATEOAS link
enable_hateoas / disable_hateoasToggle HATEOAS link inclusion
refresh_object_idsRe-query endpoint to get fresh IDs
find_object_by_fieldLook up object by field value
get_api_capabilitiesGet REST API settings
test_enhanced_connectionTest connection and feature availability

API Endpoint Coverage

CategoryEndpointsOperations
Firewall Rules/firewall/rules, /firewall/rule, /firewall/applyFull CRUD + apply
Aliases/firewall/aliases, /firewall/aliasFull CRUD + append/remove
NAT/firewall/nat/port_forwards, /firewall/nat/port_forwardFull CRUD
DHCP Leases/status/dhcp_server/leasesRead
DHCP Static Mappings/services/dhcp_server/static_mappings, /services/dhcp_server/static_mappingFull CRUD
DHCP Server Config/services/dhcp_servers, /services/dhcp_serverRead + Update
Services/status/services, /status/serviceRead + Control
Firewall Logs/status/logs/firewallRead (text-based filtering)
System Logs/status/logs/system, /status/logs/dhcp, /status/logs/openvpn, /status/logs/authRead
System Status/status/systemRead
Interfaces/status/interfacesRead
ARP Table/diagnostics/arp_tableRead
Diagnostics/diagnostics/command_promptExecute
API Settings/system/restapi/settingsRead

Not Yet Implemented

  • Routing — static routes, gateways, gateway groups
  • VPN — OpenVPN servers/clients, IPsec, WireGuard
  • DNS — resolver/forwarder config, host overrides
  • Certificates — CA, certificate, CSR management
  • Users — user/group CRUD, LDAP/RADIUS
  • NAT Outbound / 1:1 — outbound NAT rules
  • Advanced — schedules, traffic shaper, virtual IPs

Architecture

src/
  main.py          Entry point (argparse, connection test, mcp.run())
  server.py        FastMCP instance + API client singleton
  client.py        HTTP client for pfSense REST API v2
  models.py        Enums, dataclasses (QueryFilter, SortOptions, etc.)
  helpers.py       Validation, pagination, safety guards
  middleware.py    Bearer auth middleware for HTTP transport
  tools/
    firewall.py    9 tools
    aliases.py     5 tools
    nat.py         4 tools
    dhcp.py        7 tools
    services.py    2 tools
    logs.py        3 tools
    system.py      4 tools
    utility.py     7 tools

Environment Variables

VariableRequiredDefaultDescription
PFSENSE_URLYeshttps://pfsense.localpfSense URL
PFSENSE_API_KEYYes (for api_key auth)REST API key
AUTH_METHODNoapi_keyapi_key, basic, or jwt
PFSENSE_VERSIONNoCE_2_8_0CE_2_8_0, CE_2_8_1, CE_26_03, PLUS_24_11, PLUS_25_11
VERIFY_SSLNotrueVerify SSL certificates
ENABLE_HATEOASNofalseInclude HATEOAS links in responses
LOG_LEVELNoINFODEBUG, INFO, WARNING, ERROR
MCP_TRANSPORTNostdiostdio or streamable-http
MCP_HOSTNo0.0.0.0Bind address for HTTP mode
MCP_PORTNo3000Port for HTTP mode
MCP_API_KEYRequired for HTTP modeBearer token for HTTP transport auth

Docker

# Build
docker build -t pfsense-mcp .

# Run in stdio mode
docker run --rm -e PFSENSE_URL=https://pfsense.local -e PFSENSE_API_KEY=your-key pfsense-mcp

# Run in HTTP mode (docker-compose)
docker compose up

The docker-compose.yml runs in streamable-http mode on port 3000 with bearer auth.

Testing

# Run all 223 tests
python -m pytest tests/ -v

# With coverage
python -m pytest tests/ --cov=src --cov-report=term-missing

# Only tool tests
python -m pytest tests/tools/ -v

# Only client tests
python -m pytest tests/test_api_client.py -v

Safety Guards

  • Page size capped at 200 — prevents pfSense PHP memory exhaustion
  • Log lines capped at 50 — same reason
  • Port format validation — rejects "53 853" which crashes the pf compiler
  • IP validation — validates addresses before sending to API
  • Log type allowlist — prevents path traversal via log endpoint
  • Bearer auth required for HTTP transport mode (fail-closed)
  • Control parameters in JSON body — verified against pfSense API PHP source

Known Limitations

  • Firewall log API only exposes raw text field; per-field filtering is done client-side
  • HATEOAS toggle is a global API setting, not per-request (the tools toggle a local session flag)
  • pfSense object IDs are non-persistent array indices that change after deletions
  • Log retrieval is capped at 50 lines per request to prevent PHP memory exhaustion

Community & Contributions

We Need Your Help!

This MCP server has been verified against the pfSense REST API v2 PHP source code, but real-world testing across diverse pfSense environments is essential. Whether you're a pfSense veteran, Python developer, or GenAI enthusiast, there are many ways to contribute.

How You Can Help

Testing & Feedback

  • Test with your pfSense setup and report what works (and what doesn't)
  • Share use cases — tell us how you're using the MCP tools
  • Performance feedback across different network sizes

Bug Reports & Issues

  • Open an issue with detailed reproduction steps
  • Suggest new MCP tools or API integrations
  • Help improve documentation based on real-world usage

Code Contributions

  • Add tools for missing endpoint categories (VPN, routing, DNS, certificates)
  • Add support for pfSense packages (Snort, Suricata, HAProxy)
  • Improve test coverage for edge cases
  • Performance optimizations

Documentation

  • Real-world example prompts that work well with Claude
  • Integration guides for other MCP clients
  • Video tutorials for setup and usage

Getting Started as a Contributor

  1. Fork the repository and create a feature branch
  2. Run the test suite: python -m pytest tests/ -v
  3. Update tests for any new features
  4. Submit a pull request with a clear description

Ideas for Contributions

High Priority

  • VPN status and configuration tools (OpenVPN, IPsec, WireGuard)
  • Routing and gateway management
  • DNS resolver/forwarder configuration
  • Certificate management

Medium Priority

  • Support for pfSense packages (Snort, ntopng, FreeRADIUS)
  • Multi-pfSense instance management
  • GraphQL API integration
  • Enhanced log parsing and analysis

Stay Connected

  • GitHub Issues: Report bugs and request features
  • Pull Requests: Contribute code and documentation
  • Releases: Follow for updates

License

MIT License — see LICENSE for details.

Acknowledgments

相关服务器