Skip to main content
Glama
gilberth

MCP Cloudflare DNS Server

list_dns_records

Retrieve and filter DNS records for a configured zone on Cloudflare. Supports filtering by record name or type, helping manage domain configurations efficiently.

Instructions

List all DNS records for the configured zone

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNoFilter by record name (optional)
typeNoFilter by record type (optional)

Implementation Reference

  • The main MCP tool handler for 'list_dns_records'. Configures API, fetches records via CloudflareApi.findDnsRecords, formats response text, handles empty results and errors.
    const handleListDnsRecords = async (args: { name?: string; type?: string }) => {
      try {
        if (!configureApiIfNeeded()) {
          return {
            content: [{ type: "text", text: "❌ Configuration incomplete. Please configure Cloudflare API Token and Zone ID first." }],
          };
        }
        
        const records = await CloudflareApi.findDnsRecords(args.name, args.type);
        
        if (records.length === 0) {
          return {
            content: [{ type: "text", text: "No DNS records found matching the criteria." }],
          };
        }
        
        const recordsText = records.map(record => 
          `🔹 ${record.name} (${record.type}) → ${record.content} [ID: ${record.id}]${record.proxied ? ' 🟠 Proxied' : ''}`
        ).join('\n');
        
        return {
          content: [{ 
            type: "text", 
            text: `✅ Found ${records.length} DNS record(s):\n\n${recordsText}`
          }],
        };
      } catch (error) {
        return {
          content: [{ type: "text", text: `❌ Error listing DNS records: ${error instanceof Error ? error.message : 'Unknown error'}` }],
        };
      }
    };
  • Core API helper that calls Cloudflare DNS records endpoint with optional name/type filters, parses JSON response using Zod CloudflareApiResponse schema, returns DnsRecord[].
    findDnsRecords: async (name?: string, type?: string): Promise<DnsRecord[]> => {
      let endpoint = 'dns_records';
      const params = new URLSearchParams();
      
      if (name) params.append('name', name);
      if (type) params.append('type', type);
      
      if (params.toString()) {
        endpoint += `?${params.toString()}`;
      }
      
      const response = await api(endpoint);
      const rawData = await response.json();
      
      try {
        const data = CloudflareApiResponse.parse(rawData);
        
        if (!data.success) {
          throw new Error(`API Error: ${data.errors.map(e => e.message).join(', ')}`);
        }
        
        if (!data.result) {
          return [];
        }
        
        // Handle both array and single object results
        const records = Array.isArray(data.result) ? data.result : [data.result];
        return records.filter(record => record !== null);
      } catch (parseError) {
        console.error('API Response parsing failed:', parseError);
        console.error('Raw API Response:', JSON.stringify(rawData, null, 2));
        throw new Error(`Failed to parse API response: ${parseError instanceof Error ? parseError.message : 'Unknown error'}`);
      }
    },
  • src/index.ts:49-66 (registration)
    Tool registration in ListTools handler: defines name, description, and input schema for 'list_dns_records'.
    {
      name: "list_dns_records",
      description: "List all DNS records for the configured zone",
      inputSchema: {
        type: "object",
        properties: {
          name: {
            type: "string",
            description: "Filter by record name (optional)",
          },
          type: {
            type: "string",
            enum: ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "CAA", "PTR"],
            description: "Filter by record type (optional)",
          },
        },
      },
    },
  • Zod schema for Cloudflare API response parsing, used in findDnsRecords to validate and extract DNS records.
    export const CloudflareApiResponse = z.object({
      success: z.boolean(),
      errors: z.array(z.object({
        code: z.number(),
        message: z.string(),
      })),
      messages: z.array(z.object({
        code: z.number(),
        message: z.string(),
      })),
      result: z.union([
        z.array(CloudflareDnsRecord),
        CloudflareDnsRecord,
        z.null(),
      ]).optional(),
      result_info: z.object({
        page: z.number(),
        per_page: z.number(),
        count: z.number(),
        total_count: z.number(),
      }).optional(),
    });
  • Zod schema defining the structure of a Cloudflare DNS record, used for response validation.
    export const CloudflareDnsRecord = z.object({
      id: z.string(),
      zone_id: z.string().optional(),
      zone_name: z.string().optional(),
      name: z.string(),
      type: DnsRecordType,
      content: z.string(),
      proxied: z.boolean().optional(),
      ttl: z.number(),
      priority: z.number().optional(),
      created_on: z.string(),
      modified_on: z.string(),
      meta: z.object({
        auto_added: z.boolean().optional(),
        managed_by_apps: z.boolean().optional(),
        managed_by_argo_tunnel: z.boolean().optional(),
      }).optional(),
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It states it lists records but doesn't mention pagination, rate limits, authentication needs, or what 'configured zone' means operationally. This leaves significant gaps in understanding how the tool behaves beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It front-loads the core purpose ('List all DNS records') and adds necessary context ('for the configured zone'), making it appropriately sized and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool with two parameters and siblings. It doesn't explain return values, error conditions, or how 'configured zone' is determined, leaving the agent with insufficient context for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents the optional 'name' and 'type' parameters. The description adds no additional parameter semantics beyond implying filtering capability through 'List all DNS records', which the schema already covers. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('DNS records for the configured zone'), making the purpose immediately understandable. It distinguishes itself from siblings like 'get_dns_record' by indicating it returns multiple records, though it doesn't explicitly contrast with other list-like operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'get_dns_record' (for a single record) or 'create_dns_record'. The description implies it's for listing all records, but doesn't specify scenarios or prerequisites, leaving usage context unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/gilberth/mcp-cloudflare'

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