Pi-hole MCP Server

io.github.ranklancer由 GitHub 帳號 ranklancer 發布v0.2.0更新於 Oct 26, 2026

MCP server for Pi-hole v6 API — manage multiple instances: queries, lists, groups, stats

概覽

AI 產生的概覽

讓助理查詢與管理一個或多個 Pi-hole v6 DNS 廣告封鎖器的 MCP 伺服器,可查看查詢日誌、允許/拒絕清單、群組、用戶端與統計。

可以做什麼
  • 依條件篩選讀取查詢日誌,並取得各執行個體的統計摘要
  • 列出、新增、更新與刪除允許清單與拒絕清單網域,自動判斷精確比對或正規表示式,並偵測分類錯誤的正規表示式項目
  • 管理群組與用戶端及其群組歸屬
  • 啟用或停用封鎖(可設定自動回復計時),並觸發 gravity 重新載入
  • 列出、新增與刪除本機 DNS A 記錄與 CNAME 記錄
  • 每次呼叫可指定目標執行個體,預設使用第一個執行個體
適用情境
適合執行一個或多個 Pi-hole v6 執行個體的 homelab 或網路管理員,希望以對話方式查看被封鎖的流量、調整過濾規則或比較各執行個體統計,而不必操作管理介面或撰寫 curl 指令。
執行需求
以本機 Node.js 程序(Node.js 20 或更新版本)或 Docker 執行;需要能連線至已開啟 API 的 Pi-hole v6 執行個體。透過環境變數設定:PIHOLE_INSTANCES、PIHOLE_BASE_URL 與 PIHOLE_PASSWORD,以及每個執行個體的 NAME_BASE_URL、NAME_PASSWORD 與選用的 NAME_INSECURE_TLS;密碼也可來自 Docker secret 檔案。
安裝前請注意
需要 Pi-hole API 密碼(PIHOLE_PASSWORD 或各執行個體密碼變數),應存放在受保護的 env 檔案或密鑰中。工具會變更實際 DNS 過濾:新增、修改與刪除允許/拒絕項目、群組、用戶端與本機 DNS 記錄,切換封鎖開關並重新載入 gravity。選用的 HTTP 傳輸端點沒有身分驗證,應只綁定到 localhost 或可信任網路。NAME_INSECURE_TLS 會關閉對自簽憑證的 TLS 驗證。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Pi-hole MCP Server,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

pihole-mcp

[License: MIT] [Node.js] [Pi-hole v6] [MCP]

An MCP (Model Context Protocol) server that gives AI assistants like Claude full control over your Pi-hole v6 DNS ad-blocker - query logs, allow/deny lists, group management, gravity reload, and stats. Designed from day one for multi-instance deployments: manage one or many Pi-hole instances from a single MCP endpoint.

Why?

Pi-hole's admin API is powerful but cumbersome to script against. This MCP server turns every Pi-hole API action into a tool that any MCP-compatible AI assistant can call directly. Instead of clicking through the admin UI or writing curl commands, just ask your AI to check what's being blocked, allowlist a domain, or compare stats across instances.

Perfect for homelabbers running multiple Pi-holes (primary + secondary, or per-VLAN), network admins managing DNS filtering at scale, and anyone who wants AI-assisted DNS management.

Features

  • Multi-instance support - configure 1 to N Pi-hole instances via environment variables
  • Full Pi-hole v6 API coverage - query logs, allow/deny lists (full CRUD), group and client management, blocking control, local DNS (A + CNAME) records, gravity reload, stats
  • Smart regex detection - automatically routes domains to exact or regex lists based on metacharacter analysis
  • Regex landmine detector - finds deny-exact entries that look like they should be regex (miscategorized rules)
  • Docker-ready - multi-stage Dockerfile with non-root user, health checks, and security hardening
  • Streamable HTTP or stdio transport - run as a long-lived HTTP service, or let the MCP client spawn it on demand
  • Docker secrets support - passwords via env vars or /run/secrets/ files

Quick Start

Docker (recommended)

bash
git clone https://github.com/ranklancer/pihole-mcp.gitcd pihole-mcpcp .env.example .env# Edit .env with your Pi-hole URL(s) and password(s)
mkdir -p secretsecho "your-pihole-password" > secrets/pihole_passwordchmod 600 secrets/pihole_password
cp docker-compose.example.yml docker-compose.ymldocker compose up -d

Node.js

bash
npm installnpm run buildexport PIHOLE_INSTANCES=piholeexport PIHOLE_BASE_URL=http://pihole.example.comexport PIHOLE_PASSWORD=your-passwordnpm start

Local on demand (stdio, no Docker)

The MCP client starts the server as a child process when needed and talks to it over stdin/stdout. No port is opened and nothing keeps running in the background.

bash
npm cinpm run buildcp .env.example .envchmod 600 .env# Edit .env with your Pi-hole URL(s) and password(s)

Register it with Claude Code (user scope):

bash
claude mcp add --scope user pihole -- bash -c \  'set -a; . ~/path/to/pihole-mcp/.env; set +a; MCP_TRANSPORT=stdio exec node ~/path/to/pihole-mcp/dist/index.js'

Or add it manually to your MCP client config:

json
{  "mcpServers": {    "pihole": {      "type": "stdio",      "command": "bash",      "args": ["-c", "set -a; . ~/path/to/pihole-mcp/.env; set +a; MCP_TRANSPORT=stdio exec node ~/path/to/pihole-mcp/dist/index.js"]    }  }}

HOST and PORT from .env are ignored in stdio mode.

Configuration

All configuration is via environment variables. See .env.example for the full reference.

Single Instance

env
PIHOLE_INSTANCES=piholePIHOLE_BASE_URL=http://192.0.2.100PIHOLE_PASSWORD=your-password

Multiple Instances

env
PIHOLE_INSTANCES=primary,secondaryPRIMARY_BASE_URL=http://192.0.2.100PRIMARY_PASSWORD=password1SECONDARY_BASE_URL=https://198.51.100.101SECONDARY_PASSWORD=password2SECONDARY_INSECURE_TLS=true

For each instance name in PIHOLE_INSTANCES, provide:

VariableRequiredDescription
<NAME>_BASE_URLYesPi-hole base URL (e.g. http://pihole.local)
<NAME>_PASSWORDYesPi-hole API password (or use Docker secrets)
<NAME>_INSECURE_TLSNoSet true for self-signed certs (default: false)

Docker secrets are supported as a fallback: /run/secrets/<name>_password (lowercase).

Available MCP Tools

ToolDescription
pihole_query_logFetch query log with filters (limit, time range, client IP or name, domain, status)
pihole_allow_domainAdd to allowlist (auto-detects exact vs regex)
pihole_deny_domainAdd to denylist (auto-detects exact vs regex)
pihole_list_allowlistList all allowlist entries (exact + regex merged)
pihole_list_denylistList all denylist entries (exact + regex merged)
pihole_stats_summaryGet Pi-hole statistics summary
pihole_reload_listsTrigger gravity reload
pihole_group_managementCRUD operations on Pi-hole groups
pihole_client_managementCRUD operations on Pi-hole clients and their group assignments
pihole_check_regex_typesDetect miscategorized regex in deny-exact list
pihole_set_blockingEnable/disable blocking, with optional auto-revert timer
pihole_domain_managementUpdate or delete an allow/deny domain (completes CRUD)
pihole_local_dnsList/add/delete local DNS A records
pihole_local_cnameList/add/delete local CNAME records

Every tool accepts an optional instance parameter to target a specific Pi-hole. Defaults to the first configured instance.

Connecting to Your MCP Client

This section applies to the HTTP transport (Docker or npm start). For stdio, see Local on demand.

The server listens on http://HOST:PORT/mcp (default: http://localhost:3000/mcp). The HTTP endpoint has no authentication, so keep it bound to localhost or a trusted network.

Claude Desktop / Claude Code

Add to your MCP settings:

json
{  "mcpServers": {    "pihole": {      "url": "http://localhost:3031/mcp"    }  }}

Health Check

bash
curl http://localhost:3031/health# {"ok":true,"service":"pihole-mcp","version":"0.3.0"}

Development

bash
npm installnpm run dev     # Watch mode — recompiles on savenpm start       # Run the server

Requirements

  • Node.js >= 20
  • Pi-hole v6 with API access enabled
  • Network connectivity to your Pi-hole instance(s)

Related Projects

License

MIT

來源:README.md,提交 40f73e2

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.2.0最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分