Skip to main content
Glama

get_forward_destinations

Retrieve upstream DNS server stats to see how many queries each forwarder served.

Instructions

Upstream DNS server stats (which forwarders served how many queries).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler/implementation of the get_forward_destinations tool — makes a GET request to /stats/upstreams via the Pi-hole client.
    @mcp.tool()
    async def get_forward_destinations() -> dict:
        """Upstream DNS server stats (which forwarders served how many queries)."""
        return await client.get("/stats/upstreams")
  • The register() function decorates get_forward_destinations with @mcp.tool(), registering it as an MCP tool. stats.py contributes 8 tools total.
    def register(mcp: FastMCP, client: PiholeClient) -> int:
        @mcp.tool()
        async def get_stats() -> dict:
            """Get summary statistics (total queries, blocked queries, blocking percentage, unique domains, clients)."""
            return await client.get("/stats/summary")
    
        @mcp.tool()
        async def get_top_blocked(count: int = 10) -> dict:
            """Get top blocked domains by query count."""
            return await client.get("/stats/top_domains", params={"blocked": "true", "count": count})
    
        @mcp.tool()
        async def get_top_permitted(count: int = 10) -> dict:
            """Get top allowed (permitted) domains by query count."""
            return await client.get("/stats/top_domains", params={"blocked": "false", "count": count})
    
        @mcp.tool()
        async def get_top_clients(count: int = 10, blocked: bool = False) -> dict:
            """Get top clients by query count. Set blocked=true for top clients by blocked query count."""
            params: dict = {"count": count}
            if blocked:
                params["blocked"] = "true"
            return await client.get("/stats/top_clients", params=params)
    
        @mcp.tool()
        async def get_query_types() -> dict:
            """Breakdown of DNS query types (A, AAAA, PTR, SRV, etc)."""
            return await client.get("/stats/query_types")
    
        @mcp.tool()
        async def get_forward_destinations() -> dict:
            """Upstream DNS server stats (which forwarders served how many queries)."""
            return await client.get("/stats/upstreams")
    
        @mcp.tool()
        async def get_recent_blocked(count: int = 10) -> dict:
            """Recently blocked domains."""
            return await client.get("/stats/recent_blocked", params={"count": count})
    
        @mcp.tool()
        async def get_history() -> dict:
            """Time-series activity graph: timestamps, allowed/blocked/other counts per bucket."""
            return await client.get("/history")
    
        return 8
  • Top-level registration orchestrator — calls stats.register(mcp, client) which registers get_forward_destinations.
    def register_all(mcp: FastMCP, client: PiholeClient) -> int:
        """Register every tool module against the FastMCP instance. Returns tool count."""
        count = 0
        for module in (stats, queries, blocking, domains, local_dns, maintenance):
            count += module.register(mcp, client)
        return count
  • Server entry point that triggers registration of all tools including get_forward_destinations.
    _tool_count = register_all(mcp, _client)
  • The PiholeClient.get() helper called by get_forward_destinations to issue the HTTP GET to /stats/upstreams.
    class PiholeClient:
        """Async HTTP client for Pi-hole v6 REST API with session auth and auto-refresh."""
    
        _REFRESH_BUFFER_SECONDS = 60
    
        def __init__(self, config: PiholeConfig):
            self._config = config
            self._http = httpx.AsyncClient(
                base_url=config.api_base,
                verify=config.verify_tls,
                timeout=config.timeout_seconds,
            )
            self._sid: str | None = None
            self._sid_expires_at: float = 0.0
    
        async def close(self) -> None:
            if self._sid:
                try:
                    await self._http.delete(
                        "/auth",
                        headers={"X-FTL-SID": self._sid},
                    )
                except Exception:
                    pass
                self._sid = None
            await self._http.aclose()
    
        async def _authenticate(self) -> None:
            resp = await self._http.post(
                "/auth",
                json={"password": self._config.password},
            )
            if resp.status_code != 200:
                raise PiholeAuthError(
                    f"Authentication failed: HTTP {resp.status_code} {resp.text}"
                )
            payload = resp.json()
            session = payload.get("session") or {}
            sid = session.get("sid")
            valid = session.get("valid") or session.get("validity")
            if not sid:
                raise PiholeAuthError(f"No session SID in auth response: {payload}")
            self._sid = sid
            validity_seconds = int(valid) if valid else 300
            self._sid_expires_at = time.time() + validity_seconds
    
        async def _ensure_session(self) -> str:
            now = time.time()
            if not self._sid or now >= (self._sid_expires_at - self._REFRESH_BUFFER_SECONDS):
                await self._authenticate()
            assert self._sid
            return self._sid
    
        async def request(
            self,
            method: str,
            path: str,
            *,
            params: dict[str, Any] | None = None,
            json: Any | None = None,
        ) -> Any:
            """Issue a request, auto-authenticating and retrying once on 401."""
            sid = await self._ensure_session()
            resp = await self._http.request(
                method,
                path,
                params=params,
                json=json,
                headers={"X-FTL-SID": sid},
            )
            if resp.status_code == 401:
                self._sid = None
                sid = await self._ensure_session()
                resp = await self._http.request(
                    method,
                    path,
                    params=params,
                    json=json,
                    headers={"X-FTL-SID": sid},
                )
            if resp.status_code >= 400:
                try:
                    body = resp.json()
                except ValueError:
                    body = resp.text
                raise PiholeAPIError(resp.status_code, f"{method} {path} failed", body)
            if resp.status_code == 204 or not resp.content:
                return None
            return resp.json()
    
        async def get(self, path: str, *, params: dict[str, Any] | None = None) -> Any:
            return await self.request("GET", path, params=params)
    
        async def post(self, path: str, *, json: Any | None = None) -> Any:
            return await self.request("POST", path, json=json)
    
        async def patch(self, path: str, *, json: Any | None = None) -> Any:
            return await self.request("PATCH", path, json=json)
    
        async def delete(self, path: str) -> Any:
            return await self.request("DELETE", path)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It only states the data retrieved, without disclosing behavioral traits like read-only nature, side effects, or performance impact.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence (10 words) that front-loads the core purpose, with no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no input parameters and an existing output schema (which covers return structure), the description adequately summarizes the tool's function, though it could briefly mention that it's a read operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has zero parameters with 100% coverage; the description adds nothing about parameters, but they are fully defined by schema. Baseline 4 applies for no-parameter tools.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it retrieves 'Upstream DNS server stats' and specifies 'which forwarders served how many queries', making the tool's purpose specific and distinct from siblings like get_stats or get_query_types.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for forwarder statistics but provides no explicit guidance on when to use this tool versus alternatives or any when-not-to-use scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/chris2ao/pihole-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server