"""Cache purge tools.""" from typing import Annotated from pydantic import Field from ..client import client from ..config import logger def register_cache_tools(mcp): @mcp.tool() async def bunny_purge_zone( pullzone_id: Annotated[int, Field(description="Pull Zone ID to purge all cache for")], ) -> str: """Purge the entire cache for a Pull Zone.""" try: await client.post(f"/pullzone/{pullzone_id}/purgeCache") return f"Cache purged for Pull Zone {pullzone_id}" except Exception as e: logger.error("bunny_purge_zone failed: %s", e) return f"Error: {e}" @mcp.tool() async def bunny_purge_url( url: Annotated[str, Field(description="Full URL to purge from cache (e.g. https://cdn.example.com/path/to/file)")], ) -> str: """Purge a specific URL from the CDN cache.""" try: await client.get("/purge", params={"url": url}) return f"Cache purged for URL: {url}" except Exception as e: logger.error("bunny_purge_url failed: %s", e) return f"Error: {e}"