Skip to main content
Glama
jeffgolden

Cloudflare MCP Server

by jeffgolden

cloudflare-dns-mcp_list_waf_rules

Retrieve Web Application Firewall (WAF) rules for a specific zone using the Cloudflare MCP Server, enabling efficient rule management and security monitoring.

Instructions

List Web Application Firewall (WAF) rules for a zone

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rule_typeNo
zone_nameYes

Implementation Reference

  • The handler function that implements the core logic of listing WAF rules: parses input, fetches zone ID, queries Cloudflare firewall/rules endpoint, and formats response as MCP content.
    handler: async (params: z.infer<typeof ListWafRulesInputSchema>) => {
      const { zone_name, rule_type } = ListWafRulesInputSchema.parse(params);
    
      // Resolve zone ID
      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 query: Record<string, any> = {};
      if (rule_type) query.mode = rule_type;
    
      const wafRules = await client.get<Array<typeof WafRuleSchema['_type']>>(`/zones/${zoneId}/firewall/rules`, query);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(wafRules, null, 2)
          }
        ]
      };
    },
  • Zod input schema for the tool: requires zone_name, optional rule_type.
    const ListWafRulesInputSchema = z.object({
      zone_name: z.string(),
      rule_type: z.string().optional(), // Placeholder – Cloudflare uses "mode" & "action"
    });
  • Shared Zod schema for individual WafRule objects, used to type the output array items.
    const WafRuleSchema = z.object({
      id: z.string(),
      description: z.string(),
      action: z.string(),
      expression: z.string(),
      paused: z.boolean(),
      priority: z.number().optional(),
    });
  • Registration of the list_waf_rules tool in the security tools map returned by getSecurityTools(client). This map is spread into the main server tools in src/index.ts.
    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,
    },
  • src/index.ts:19-27 (registration)
    Main server registration: calls getSecurityTools and spreads its tools into the aggregate allTools used for MCP server handlers.
    const securityTools = getSecurityTools(cfClient);
    const sslCertTools = getSslCertTools(cfClient);
    const zoneTools = getZoneManagementTools(cfClient);
    const echoTools = getEchoTools();
    const redirectTools = getRedirectTools(cfClient);
    
    const allTools = {
      ...dnsTools.tools,
      ...securityTools.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/jeffgolden/cloudflare_mcp'

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