Skip to main content
Glama
jeffgolden

Cloudflare MCP Server

by jeffgolden

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
NameRequiredDescriptionDefault
purge_typeNoeverything
targetsNo
zone_nameYes

Implementation Reference

  • 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) } ] }; },
  • 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(), });
  • 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>;

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/jeffgolden/cloudflare_mcp'

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