Skip to main content

A Model Context Protocol server for Pi-hole

Project description

🍓 pihole-mcp-serer

A Model Context Protocol (MCP) server for Pi-hole. This server exposes Pi-hole functionality as tools that can be used by AI assistants.

Dependencies

Docker

uv (Optional, for Development)

If you want to run the application locally, use uv. Install it with your package manager of choice.

Environment

Create a .env file in the project root with your Pi-hole credentials:

# Primary Pi-hole (required)
PIHOLE_URL=https://your-pihole.local/
PIHOLE_PASSWORD=your-admin-password
#PIHOLE_NAME=Primary        # optional, defaults to URL if unset

# Secondary Pi-hole (optional)
#PIHOLE2_URL=https://secondary-pihole.local/
#PIHOLE2_PASSWORD=password2
#PIHOLE2_NAME=Secondary     # optional

# Up to 4 Pi-holes:
#PIHOLE3_URL=...
#PIHOLE3_PASSWORD=...
#PIHOLE3_NAME=...

#PIHOLE4_URL=...
#PIHOLE4_PASSWORD=...
#PIHOLE4_NAME=...

Project Structure

The project follows a modular organization for better maintainability:

/
├── main.py                # Main application entry point
├── tools/                 # Pi-hole tools organized by functionality
│   ├── __init__.py
│   ├── config.py          # Configuration-related tools (DNS settings)
│   └── metrics.py         # Metrics and query-related tools
├── resources/             # MCP resources
│   ├── __init__.py
│   └── common.py          # Common resources (piholes://, version://)
├── docker-compose.yml     # Docker Compose configuration for production
├── docker-compose.dev.yml # Docker Compose for development with volume mounts
└── Dockerfile             # Docker build configuration

This structure separates the code into logical components while maintaining compatibility with all run modes.

Running the Server

There are several ways to run the Pi-hole MCP server:

Using Docker (Recommended for Production)

# Standard deployment
docker-compose up -d

The server will be available at http://localhost:8383

Development Mode with Docker

For development, use the dev compose file which builds locally:

docker-compose -f docker-compose.dev.yml up

MCP Inspector

You can run the MCP inspector using uv and the mcp CLI:

uv run mcp dev main.py

This will start an interactive interface at http://localhost:6274 where you can test tools and resources.

API

This MCP server exposes the following resources and tools:

Resources

  • piholes://: Returns information about all configured Pi-holes
  • version://: Returns the MCP server version
  • list-tools://: Returns a list of tool categories
    • list-tools://{category}: Returns a list of tools within a specific category

Tools

Each tool call returns results as a list of dictionaries with the following structure:

[
  {
    "pihole": "Pi-hole Name",
    "data": [...]  # Result data from this Pi-hole
  },
  ...
]

Configuration

  • list_local_dns: Lists all local DNS settings from Pi-hole(s)
  • add_local_a_record: Adds a local A record to Pi-hole(s).
  • add_local_cname_record: Adds a local CNAME record to Pi-hole(s).
  • remove_local_a_record: Removes all A records for a hostname.
  • remove_local_cname_record: Removes all CNAME records for a hostname.

Metrics

  • list_queries: Fetches the recent DNS query history from Pi-hole(s)
  • list_query_suggestions: Get query filter suggestions
  • list_query_history: Get activity graph data for queries over time

Testing in goose

Goose is a CLI LLM client that's useful for testing and development. Follow their install instructions here.

The following assumes you've completed the initial setup with goose configure.

Configure Extension

  1. Type goose configure to open the configuration menu.
  2. Select Add Extension
  3. Select Remote Extension
  4. It will ask for a name. It doesn't matter what you name it. I called mine pihole-mcp.
  5. When it asks "What is the SSE endpoint URI?" enter http://localhost:8383/sse.
  6. Enter a timeout.
  7. Add a description if you'd like.
  8. Select No when it asks about environment variables. Screenshot of configuration

Start a Session

Once the server is installed, start a chat session.

goose session

Try asking it: "What are my local DNS records?"

Screenshot of local DNS tool

...or telling it: "Show me my recent DNS queries."

Screenshot of queries

Claude Desktop

Claude's desktop client currently only support's the STDIO protocol, however you can use a proxy to communicate with the SSE endpoint.

Add the following to your claude_desktop_config.json file.

{
  "mcpServers": {
    "pihole": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:8383/sse"
      ]
    }
  }
}

If you're connecting to a different host on your local network and using an unsecured connection, you'll need to explicitly allow it with the --allow-http argument. For example:

{
  "mcpServers": {
    "pihole": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://192.168.1.255:8383/sse",
        "--allow-http"
      ]
    }
  }
}

Afterwards, completely restart the application and try it out.

Claude DNS info

Claude query info

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_sbarbett_pihole_mcp_server-0.2.3.tar.gz.

File metadata

  • Download URL: iflow_mcp_sbarbett_pihole_mcp_server-0.2.3.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_sbarbett_pihole_mcp_server-0.2.3.tar.gz
Algorithm Hash digest
SHA256 6da1c33237c7e2c6d63e429255ee19a69f15542036197ae0bcad3ed2a2651696
MD5 d2b14896507189108cbc3493495aa71c
BLAKE2b-256 0e52fe732018d8b9fb81c121fee8d105ab270056b9c128e77c9104670c9bfa0f

See more details on using hashes here.

File details

Details for the file iflow_mcp_sbarbett_pihole_mcp_server-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_sbarbett_pihole_mcp_server-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 32.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_sbarbett_pihole_mcp_server-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 213d96647187f643d924779357d626bae4fc6f38358d5e84ba32cbd563795002
MD5 05e79b135014470b4df2b87715525c22
BLAKE2b-256 81aeaf11126cc57be0fd187758cae2236ad344e28f454877f00e21413407564a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page