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 分