Skip to main content
Glama
ry-ops

Cloudflare MCP Server

by ry-ops

purge_cache

Remove cached content from a Cloudflare zone to force fresh delivery. Supports full purge or selective removal by URL, tag, or host.

Instructions

Purge Cloudflare's cache for a zone. Can purge everything or specific files/tags/hosts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
zone_idYesThe zone ID
purge_everythingNoPurge all cached content (use cautiously!)
filesNoArray of URLs to purge
tagsNoArray of cache tags to purge
hostsNoArray of hosts to purge

Implementation Reference

  • Tool registration for 'purge_cache' in the list_tools handler. Defines schema with zone_id (required), purge_everything (boolean), files, tags, and hosts (arrays of strings).
    Tool(
        name="purge_cache",
        description="Purge Cloudflare's cache for a zone. Can purge everything or specific files/tags/hosts.",
        inputSchema={
            "type": "object",
            "properties": {
                "zone_id": {"type": "string", "description": "The zone ID"},
                "purge_everything": {
                    "type": "boolean",
                    "description": "Purge all cached content (use cautiously!)",
                },
                "files": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Array of URLs to purge",
                },
                "tags": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Array of cache tags to purge",
                },
                "hosts": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "Array of hosts to purge",
                },
            },
            "required": ["zone_id"],
        },
    ),
  • Input schema for purge_cache tool: requires zone_id, accepts purge_everything (boolean), and optional arrays files, tags, hosts.
    inputSchema={
        "type": "object",
        "properties": {
            "zone_id": {"type": "string", "description": "The zone ID"},
            "purge_everything": {
                "type": "boolean",
                "description": "Purge all cached content (use cautiously!)",
            },
            "files": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Array of URLs to purge",
            },
            "tags": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Array of cache tags to purge",
            },
            "hosts": {
                "type": "array",
                "items": {"type": "string"},
                "description": "Array of hosts to purge",
            },
        },
        "required": ["zone_id"],
    },
  • Handler function for purge_cache tool. Builds data payload based on purge_everything flag (preferred, purges all) or selective files/tags/hosts arrays, then POSTs to Cloudflare API /zones/{zone_id}/purge_cache.
    async def _purge_cache(self, args: dict) -> Any:
        """Purge cache."""
        data = {}
    
        if args.get("purge_everything"):
            data["purge_everything"] = True
        else:
            if args.get("files"):
                data["files"] = args["files"]
            if args.get("tags"):
                data["tags"] = args["tags"]
            if args.get("hosts"):
                data["hosts"] = args["hosts"]
    
        return await self._make_request(
            f"/zones/{args['zone_id']}/purge_cache", method="POST", data=data
        )
  • Routing: call_tool dispatcher maps 'purge_cache' name to _purge_cache handler method.
    elif name == "purge_cache":
        result = await self._purge_cache(arguments)
  • Helper _make_request used by _purge_cache to make HTTP calls to the Cloudflare API. Handles auth, JSON serialization, error checking, and result extraction.
    async def _make_request(
        self,
        endpoint: str,
        method: str = "GET",
        data: Optional[dict] = None,
        params: Optional[dict] = None,
    ) -> Any:
        """Make a request to the Cloudflare API."""
        url = f"{CLOUDFLARE_API_BASE}{endpoint}"
        headers = {
            "Authorization": f"Bearer {self.api_token}",
            "Content-Type": "application/json",
        }
    
        try:
            response = await self.client.request(
                method=method,
                url=url,
                json=data,
                params=params,
                headers=headers,
            )
            response.raise_for_status()
            result = response.json()
    
            if not result.get("success"):
                errors = result.get("errors", [])
                raise Exception(f"Cloudflare API error: {json.dumps(errors)}")
    
            return result.get("result")
    
        except httpx.HTTPError as e:
            raise Exception(f"HTTP error occurred: {str(e)}")
Behavior2/5

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

With no annotations, the description should fully disclose behavior. It mentions the destructive nature of 'purge_everything' with a caution, but omits details on rate limits, authentication requirements, reversibility, or effects on non-purged content.

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 extremely concise, with two sentences that efficiently convey the core function and options. No superfluous words.

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

Completeness2/5

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

Given the lack of output schema and annotations, the description is incomplete. It doesn't explain return values, error conditions, or the requirement that at least one purge method (purge_everything, files, tags, hosts) must be specified. The 'zone_id' parameter is mentioned but its format is not clarified.

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

Parameters3/5

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

Schema coverage is 100%, so baseline is 3. The description adds no extra meaning beyond the schema; it simply paraphrases the parameter options without additional constraints or format details.

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 the action (purge cache), the resource (Cloudflare zone), and the modes (everything or specific files/tags/hosts). It distinctly separates this tool from sibling tools like DNS or KV operations.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool over others or when not to use it. The only hint is the caution on 'purge_everything', but no differentiation between purge modes or prerequisites.

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/ry-ops/cloudflare-mcp-server'

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