Skip to main content
Glama
jeffgolden

Cloudflare MCP Server

by jeffgolden

cloudflare-dns-mcp_create_dns_record

Automate DNS record creation in a specified Cloudflare zone by defining parameters like record type, name, content, TTL, and optional proxy settings.

Instructions

Create a new DNS record in a given zone

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes
nameYes
portNo
priorityNo
proxiedNo
targetNo
ttlNo
typeYes
weightNo
zone_nameYes

Implementation Reference

  • Handler function that implements the logic to create a new DNS record in a Cloudflare zone. Finds the zone, validates inputs, handles special record types (TXT, CAA, MX, SRV), calls the Cloudflare POST API, and returns the result in MCP format.
    handler: async (params: z.infer<typeof CreateDnsRecordInputSchema>) => {
      const { zone_name, ...rest } = CreateDnsRecordInputSchema.parse(params);
      // Find 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 quotedContent = rest.type === 'TXT' ? ensureTxtQuotes(rest.content) : rest.content;
      // validate edge-cases
      if (rest.type === 'MX' && rest.priority === undefined) {
        throw new Error('MX record requires "priority"');
      }
      if (rest.type === 'SRV') {
        const required = ['priority', 'weight', 'port', 'target'];
        for (const f of required) {
          if ((rest as any)[f] === undefined) throw new Error(`SRV record requires "${f}"`);
        }
      }
    
      let body: any;
      if (rest.type === 'CAA') {
        const caaData = parseCAAContent(quotedContent);
        body = {
          type: rest.type,
          name: rest.name,
          data: caaData,
          ttl: rest.ttl,
        };
      } else {
        body = {
          type: rest.type,
          name: rest.name,
          content: quotedContent,
          ttl: rest.ttl,
          priority: rest.priority,
          proxied: rest.proxied,
          ...(rest.weight !== undefined && { weight: rest.weight }),
          ...(rest.port !== undefined && { port: rest.port }),
          ...(rest.target !== undefined && { target: rest.target }),
        };
      }
      const record = await client.post<typeof DNSRecordSchema['_type']>(`/zones/${zoneId}/dns_records`, body);
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({ ...record, zone_name }, null, 2)
          }
        ]
      };
    },
  • Zod input schema for the create_dns_record tool defining parameters like zone_name, type, name, content, ttl, etc.
    const CreateDnsRecordInputSchema = z.object({
      zone_name: z.string(),
      type: z.string(),
      name: z.string(),
      content: z.string(),
      ttl: z.number().optional().default(1),
      priority: z.number().optional(),
      weight: z.number().optional(),
      port: z.number().optional(),
      target: z.string().optional(),
      proxied: z.boolean().optional().default(false),
    });
  • Local registration of the create_dns_record tool in the getDnsTools() function's return object.
    'cloudflare-dns-mcp/create_dns_record': createDnsRecordTool,
  • src/index.ts:5-26 (registration)
    Global registration: imports getDnsTools, calls it to get tools including create_dns_record, and spreads into allTools. Note: tool names are later sanitized by replacing '/' with '_'.
    import { getDnsTools } from './tools/dns-records.js';
    import { getSecurityTools } from './tools/security.js';
    import { getSslCertTools } from './tools/ssl-certs.js';
    import { getZoneManagementTools } from './tools/zone-management.js';
    import { getEchoTools } from './tools/echo.js';
    import { getRedirectTools } from './tools/redirects.js';
    import { CloudflareClient } from './cloudflare-client.js';
    
    dotenv.config();
    
    async function main() {
      const cfClient = new CloudflareClient();
    
      const dnsTools = getDnsTools(cfClient);
      const securityTools = getSecurityTools(cfClient);
      const sslCertTools = getSslCertTools(cfClient);
      const zoneTools = getZoneManagementTools(cfClient);
      const echoTools = getEchoTools();
      const redirectTools = getRedirectTools(cfClient);
    
      const allTools = {
        ...dnsTools.tools,
  • Helper functions ensureTxtQuotes (for TXT records) and parseCAAContent (for CAA records) used in the handler.
    // Ensure TXT record value is wrapped in double quotes; Cloudflare permits full string.
      const ensureTxtQuotes = (val: string) => (val.startsWith('"') ? val : `"${val}"`);
    
      // Parse a CAA record string of the form "<flags> <tag> <value>" into the object Cloudflare expects.
      const parseCAAContent = (content: string) => {
        const match = content.match(/^(\d+)\s+(issue|issuewild|iodef)\s+(.+)$/);
        if (!match) {
          throw new Error('CAA content must be in the format: "flags tag value" (e.g., "0 issue cloudflare.com")');
        }
        return {
          flags: Number(match[1]),
          tag: match[2],
          value: match[3].replace(/^"(.*)"$/, '$1'), // strip surrounding quotes if user provided them
        } as const;
      };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states 'Create' which implies a write/mutation operation, but doesn't cover critical aspects like authentication requirements, rate limits, error conditions, whether the operation is idempotent, or what happens on success/failure. This leaves significant gaps for agent decision-making.

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 extremely concise at just 8 words, front-loading the core purpose without any wasted words. It efficiently communicates the essential action and scope in a single, clear sentence.

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?

For a write operation with 10 parameters, 0% schema coverage, no annotations, and no output schema, the description is severely inadequate. It doesn't explain parameter meanings, behavioral characteristics, success criteria, or provide any context beyond the basic action. This leaves the agent poorly equipped to use the tool correctly.

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

Parameters2/5

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

The description mentions 'in a given zone' which hints at the 'zone_name' parameter, but with 10 parameters and 0% schema description coverage, it fails to explain what any parameters mean or how they interact. Key required parameters like 'type', 'name', and 'content' are completely unexplained, leaving the agent to guess their purpose and format.

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 action ('Create') and resource ('new DNS record in a given zone'), making the purpose immediately understandable. It distinguishes from siblings like 'list_dns_records' (read vs. write) and 'update_dns_record' (create vs. modify), though it doesn't explicitly mention these distinctions.

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. It doesn't mention prerequisites (e.g., needing an existing zone), compare to sibling tools like 'update_dns_record' for modifications, or specify scenarios where DNS record creation is appropriate versus other operations.

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

Related 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