Skip to main content
Glama
jeffgolden

Cloudflare MCP Server

by jeffgolden

cloudflare-dns-mcp_update_security_rule

Modify an existing firewall security rule to enhance protection across Cloudflare zones. Specify zone, rule ID, action, priority, and expression for precise updates.

Instructions

Update an existing firewall security rule

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionNo
descriptionNo
expressionNo
pausedNo
priorityNo
rule_idYes
zone_nameYes

Implementation Reference

  • The main handler function that implements the logic to update a Cloudflare WAF security rule by fetching the zone, preparing the update body, and calling the Cloudflare PUT API.
    handler: async (params: z.infer<typeof UpdateSecurityRuleInputSchema>) => { const { zone_name, rule_id, description, expression, action, priority, paused } = UpdateSecurityRuleInputSchema.parse(params); const zones = await client.get<Array<{ id: string; name: string }>>('/zones', { name: zone_name }); if (zones.length === 0) throw new Error(`Zone ${zone_name} not found`); const zoneId = zones[0].id; const body: any = { id: rule_id }; if (description !== undefined) body.description = description; if (expression !== undefined) { // need to include filter id per Cloudflare API const existing = await client.get<any>(`/zones/${zoneId}/firewall/rules/${rule_id}`); const filterId = existing.filter?.id; body.filter = { id: filterId, expression }; } if (action !== undefined) body.action = action; if (priority !== undefined) body.priority = priority; if (paused !== undefined) body.paused = paused; const updated = await client.put<typeof WafRuleSchema["_type"]>(`/zones/${zoneId}/firewall/rules/${rule_id}`, body); return { content: [ { type: "text", text: JSON.stringify(updated, null, 2) } ] }; },
  • Zod schema defining the input parameters for the update_security_rule tool.
    const UpdateSecurityRuleInputSchema = z.object({ zone_name: z.string(), rule_id: z.string(), description: z.string().optional(), expression: z.string().optional(), action: z.string().optional(), priority: z.number().optional(), paused: z.boolean().optional(), });
  • Tool object definition including name, description, schemas, and handler reference for 'cloudflare-dns-mcp/update_security_rule'.
    const updateSecurityRuleTool: Tool = { name: 'cloudflare-dns-mcp/update_security_rule', description: 'Update an existing firewall security rule', inputSchema: zodToJsonSchema(UpdateSecurityRuleInputSchema) as any, outputSchema: zodToJsonSchema(WafRuleSchema) as any, annotations: { destructiveHint: true }, handler: async (params: z.infer<typeof UpdateSecurityRuleInputSchema>) => { const { zone_name, rule_id, description, expression, action, priority, paused } = UpdateSecurityRuleInputSchema.parse(params); const zones = await client.get<Array<{ id: string; name: string }>>('/zones', { name: zone_name }); if (zones.length === 0) throw new Error(`Zone ${zone_name} not found`); const zoneId = zones[0].id; const body: any = { id: rule_id }; if (description !== undefined) body.description = description; if (expression !== undefined) { // need to include filter id per Cloudflare API const existing = await client.get<any>(`/zones/${zoneId}/firewall/rules/${rule_id}`); const filterId = existing.filter?.id; body.filter = { id: filterId, expression }; } if (action !== undefined) body.action = action; if (priority !== undefined) body.priority = priority; if (paused !== undefined) body.paused = paused; const updated = await client.put<typeof WafRuleSchema["_type"]>(`/zones/${zoneId}/firewall/rules/${rule_id}`, body); return { content: [ { type: "text", text: JSON.stringify(updated, null, 2) } ] }; }, };
  • Registration of the update_security_rule tool (and related security tools) in the tools map returned by getSecurityTools function.
    return { tools: { 'cloudflare-dns-mcp/list_waf_rules': listWafRulesTool, 'cloudflare-dns-mcp/create_security_rule': createSecurityRuleTool, 'cloudflare-dns-mcp/update_security_rule': updateSecurityRuleTool, 'cloudflare-dns-mcp/delete_security_rule': deleteSecurityRuleTool, }, };

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