purge_cache
Clear Cloudflare's cache for a zone to remove outdated content. Purge all cached files or target specific URLs, tags, and hosts to ensure visitors see updated website content.
Instructions
Purge Cloudflare's cache for a zone. Can purge everything or specific files/tags/hosts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| zone_id | Yes | The zone ID | |
| purge_everything | No | Purge all cached content (use cautiously!) | |
| files | No | Array of URLs to purge | |
| tags | No | Array of cache tags to purge | |
| hosts | No | Array of hosts to purge |
Input Schema (JSON Schema)
{
"properties": {
"files": {
"description": "Array of URLs to purge",
"items": {
"type": "string"
},
"type": "array"
},
"hosts": {
"description": "Array of hosts to purge",
"items": {
"type": "string"
},
"type": "array"
},
"purge_everything": {
"description": "Purge all cached content (use cautiously!)",
"type": "boolean"
},
"tags": {
"description": "Array of cache tags to purge",
"items": {
"type": "string"
},
"type": "array"
},
"zone_id": {
"description": "The zone ID",
"type": "string"
}
},
"required": [
"zone_id"
],
"type": "object"
}
Implementation Reference
- The handler function _purge_cache that executes the tool logic. It builds the purge request body from arguments (purge_everything, files, tags, hosts) and sends a POST request to Cloudflare's /zones/{zone_id}/purge_cache endpoint using _make_request.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 )
- src/cloudflare_mcp_server/__init__.py:234-263 (registration)Registration of the purge_cache tool in the list_tools() decorator callback, defining its name, description, and input schema.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 definition for the purge_cache tool, specifying parameters like zone_id (required), purge_everything, 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"], },