cloudflare-dns-mcp_purge_cache
Purge Cloudflare cache for a specified zone by selecting purge type (everything, files, tags, hosts) and targeting specific resources. Streamlines cache management for improved performance.
Instructions
Purge Cloudflare cache for a zone
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| purge_type | No | everything | |
| targets | No | ||
| zone_name | Yes |
Implementation Reference
- src/tools/zone-management.ts:126-149 (handler)Handler function that executes the cache purge logic: resolves zone ID, constructs purge body based on type and targets, calls Cloudflare POST /zones/{id}/purge_cache API.handler: async (params: any) => { const { zone_name, purge_type, targets } = PurgeCacheInputSchema.parse(params); const zones = await client.get<any[]>('/zones', { name: zone_name }); if (zones.length === 0) throw new Error(`Zone ${zone_name} not found`); const zoneId = zones[0].id; let body: any = {}; if (purge_type === 'everything') { body = { purge_everything: true }; } else { if (!targets || targets.length === 0) { throw new Error('targets must be provided when purge_type is not "everything"'); } body = { [`${purge_type}`]: targets }; } return { content: [ { type: "text", text: JSON.stringify(await client.post(`/zones/${zoneId}/purge_cache`, body), null, 2) } ] }; },
- src/tools/zone-management.ts:114-118 (schema)Zod schema for input validation: requires zone_name, optional purge_type (defaults to 'everything'), optional targets array.const PurgeCacheInputSchema = z.object({ zone_name: z.string(), purge_type: z.enum(['everything', 'files', 'tags', 'hosts']).optional().default('everything'), targets: z.array(z.string()).optional(), });
- src/tools/zone-management.ts:153-159 (registration)Registration of purge_cache tool within the getZoneManagementTools function's return object (note: slash-separated name).tools: { 'cloudflare-dns-mcp/list_zones': listZonesTool, 'cloudflare-dns-mcp/get_zone_settings': getZoneSettingsTool, 'cloudflare-dns-mcp/update_zone_settings': updateZoneSettingsTool, 'cloudflare-dns-mcp/purge_cache': purgeCacheTool, }, };
- src/index.ts:49-52 (registration)Global registration in MCP server: sanitizes tool names by replacing '/' with '_', creating 'cloudflare-dns-mcp_purge_cache' key used by clients.for (const tool of Object.values(allTools)) { const safeName = tool.name.replace(/[^a-zA-Z0-9_-]/g, '_'); toolsMap[safeName] = tool; }
- src/index.ts:25-32 (registration)Aggregates tools from all modules including zoneTools (containing purge_cache) into single allTools object for server.const allTools = { ...dnsTools.tools, ...securityTools.tools, ...sslCertTools.tools, ...echoTools.tools, ...redirectTools.tools, ...zoneTools.tools, } as Record<string, any>;