pihole-mcp
pihole-mcp
一个 MCP(模型上下文协议) 服务器,让 Claude 等 AI 助手能够完全控制你的 Pi-hole v6 DNS 广告拦截器——查询日志、允许/拒绝列表、组管理、gravity 重载和统计信息。从第一天起就为多实例部署而设计:通过单个 MCP 端点管理一个或多个 Pi-hole 实例。
为什么?
Pi-hole 的管理 API 功能强大,但用脚本调用起来很繁琐。这个 MCP 服务器将每个 Pi-hole API 操作转化为任何兼容 MCP 的 AI 助手都可以直接调用的工具。无需在管理界面中点击或编写 curl 命令,只需让 AI 检查正在拦截什么、将域名加入白名单,或比较各实例之间的统计信息。
非常适合运行多个 Pi-hole 的家庭实验室用户(主 + 备,或按 VLAN 划分)、大规模管理 DNS 过滤的网络管理员,以及任何希望获得 AI 辅助 DNS 管理的人。
Related MCP server: MCP Pi-hole Server
功能特性
多实例支持 - 通过环境变量配置 1 到 N 个 Pi-hole 实例
完整的 Pi-hole v6 API 覆盖 - 查询日志、允许/拒绝列表(完整 CRUD)、组管理、拦截控制、本地 DNS(A + CNAME)记录、gravity 重载、统计信息
智能正则检测 - 根据元字符分析自动将域名路由到精确或正则列表
正则地雷检测器 - 发现看起来应该是正则的拒绝精确条目(分类错误的规则)
Docker 就绪 - 多阶段 Dockerfile,包含非 root 用户、健康检查和安全性加固
可流式 HTTP 传输 - 适用于任何支持基于 HTTP 的 MCP 客户端
Docker secrets 支持 - 通过环境变量或
/run/secrets/文件提供密码
快速开始
Docker(推荐)
git clone https://github.com/ranklancer/pihole-mcp.git
cd pihole-mcp
cp .env.example .env
# Edit .env with your Pi-hole URL(s) and password(s)
mkdir -p secrets
echo "your-pihole-password" > secrets/pihole_password
chmod 600 secrets/pihole_password
cp docker-compose.example.yml docker-compose.yml
docker compose up -dNode.js
npm install
npm run build
export PIHOLE_INSTANCES=pihole
export PIHOLE_BASE_URL=http://pihole.example.com
export PIHOLE_PASSWORD=your-password
npm start配置
所有配置均通过环境变量完成。完整参考请参见 .env.example。
单实例
PIHOLE_INSTANCES=pihole
PIHOLE_BASE_URL=http://192.0.2.100
PIHOLE_PASSWORD=your-password多实例
PIHOLE_INSTANCES=primary,secondary
PRIMARY_BASE_URL=http://192.0.2.100
PRIMARY_PASSWORD=password1
SECONDARY_BASE_URL=https://198.51.100.101
SECONDARY_PASSWORD=password2
SECONDARY_INSECURE_TLS=true对于 PIHOLE_INSTANCES 中的每个实例名称,请提供:
变量 | 必需 | 描述 |
| 是 | Pi-hole 基础 URL(例如 |
| 是 | Pi-hole API 密码(或使用 Docker secrets) |
| 否 | 自签名证书设为 |
支持 Docker secrets 作为后备方案:/run/secrets/<name>_password(小写)。
可用的 MCP 工具
工具 | 描述 |
| 使用过滤器获取查询日志(限制、时间范围、客户端、域名、状态) |
| 添加到允许列表(自动检测精确 vs 正则) |
| 添加到拒绝列表(自动检测精确 vs 正则) |
| 列出所有允许列表条目(精确 + 正则合并) |
| 列出所有拒绝列表条目(精确 + 正则合并) |
| 获取 Pi-hole 统计信息摘要 |
| 触发 gravity 重载 |
| 对 Pi-hole 组执行 CRUD 操作 |
| 检测拒绝精确列表中的错误分类正则 |
| 启用/禁用拦截,可带可选的自动恢复计时器 |
| 更新或删除允许/拒绝域名(完成 CRUD) |
| 列出/添加/删除本地 DNS A 记录 |
| 列出/添加/删除本地 CNAME 记录 |
每个工具都接受可选的 instance 参数来指定目标 Pi-hole。默认为第一个配置的实例。
连接到你的 MCP 客户端
服务器监听在 http://HOST:PORT/mcp(默认:http://localhost:3000/mcp)。
Claude Desktop / Claude Code
添加到你的 MCP 设置中:
{
"mcpServers": {
"pihole": {
"url": "http://localhost:3031/mcp"
}
}
}Supergateway(stdio 包装器)
如果你的 MCP 客户端仅支持 stdio 传输,请使用 supergateway:
npx -y supergateway --streamableHttp http://localhost:3031/mcp健康检查
curl http://localhost:3031/health
# {"ok":true,"service":"pihole-mcp","version":"0.3.0"}开发
npm install
npm run dev # Watch mode — recompiles on save
npm start # Run the server要求
Node.js >= 20
启用了 API 访问的 Pi-hole v6
与你的 Pi-hole 实例之间的网络连通性
相关项目
Pi-hole — 全网广告拦截
Model Context Protocol — AI 工具集成的开放标准
MCP Server Registry — MCP 服务器目录
许可证
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceA server that exposes Pi-hole functionality as tools for AI assistants, allowing them to retrieve local DNS settings and query history through natural language.8MIT
- AlicenseAqualityBmaintenanceConnects AI assistants to Pi-hole network-wide ad blocker, enabling monitoring of DNS traffic statistics, controlling blocking settings, managing whitelist/blacklist domains, viewing query logs, and performing maintenance tasks through natural language.16786MIT
- FlicenseNot gradedqualityDmaintenanceEnables control of Pi-hole v6 ad blocking, allowing users to toggle DNS blocking status and retrieve real-time statistics like query counts and blocked domains. It provides a structured interface for monitoring and managing network-level ad filtering through the Pi-hole REST API.
- AlicenseAqualityCmaintenanceMCP server for Pi-hole v6 that enables management of blocklists, DNS blocking, domain allow/deny lists, and query diagnostics through natural language.19MIT
Related MCP Connectors
Universal AI API Orchestrator — 1,554 tools, 96 services. One install.
Log, query, and edit expenses, budgets, and accounts in Ledgy from any MCP-compatible AI assistant.
Buy & manage domains from any AI chat: availability, register, DNS, email forwarding, AI bot stats.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ranklancer/pihole-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server