Skip to main content
Glama
gilberth

MCP Cloudflare DNS Server

create_dns_record

Add a new DNS record to Cloudflare domains by specifying type, name, content, TTL, priority, and proxy settings. Simplifies DNS management for automated setups.

Instructions

Create a new DNS record

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesDNS record content
nameYesDNS record name
priorityNoPriority (for MX records)
proxiedNoWhether the record should be proxied through Cloudflare
ttlNoTime to live (TTL) in seconds (default: 1 for auto)
typeYesDNS record type

Implementation Reference

  • MCP tool handler for create_dns_record: handles tool call dispatch, input processing, API configuration check, calls CloudflareApi.createDnsRecord, and returns formatted response.
    const handleCreateDnsRecord = async (args: { type: string; name: string; content: string; ttl?: number; priority?: number; proxied?: boolean }) => { try { if (!configureApiIfNeeded()) { return { content: [{ type: "text", text: "❌ Configuration incomplete. Please configure Cloudflare API Token and Zone ID first." }], }; } const recordData: any = { type: DnsRecordType.parse(args.type), name: args.name, content: args.content, }; if (args.ttl !== undefined) recordData.ttl = args.ttl; if (args.priority !== undefined) recordData.priority = args.priority; if (args.proxied !== undefined) recordData.proxied = args.proxied; const record = await CloudflareApi.createDnsRecord(recordData); return { content: [{ type: "text", text: `✅ DNS record created successfully! 🔹 Name: ${record.name} 🔹 Type: ${record.type} 🔹 Content: ${record.content} 🔹 ID: ${record.id} ${record.proxied ? '🟠 Proxied through Cloudflare' : ''}` }], }; } catch (error) { return { content: [{ type: "text", text: `❌ Error creating DNS record: ${error instanceof Error ? error.message : 'Unknown error'}` }], }; } };
  • Core implementation: validates input with Zod schema, performs POST request to Cloudflare /dns_records endpoint, parses and returns the created DnsRecord.
    createDnsRecord: async (record: CreateDnsRecord): Promise<DnsRecord> => { const validatedRecord = CreateDnsRecordRequest.parse(record); const response = await api('dns_records', 'POST', validatedRecord); const data = CloudflareApiResponse.parse(await response.json()); if (!data.success) { throw new Error(`API Error: ${data.errors.map(e => e.message).join(', ')}`); } if (!data.result || Array.isArray(data.result)) { throw new Error('Failed to create DNS record'); } return data.result; },
  • Zod schema defining input shape and validation for create_dns_record parameters.
    export const CreateDnsRecordRequest = z.object({ type: DnsRecordType, name: z.string(), content: z.string(), ttl: z.number().optional().default(1), priority: z.number().optional(), proxied: z.boolean().optional(), });
  • src/index.ts:81-116 (registration)
    Tool registration in ListTools response: defines name, description, and JSON inputSchema matching the Zod schema.
    { name: "create_dns_record", description: "Create a new DNS record", inputSchema: { type: "object", properties: { type: { type: "string", enum: ["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "CAA", "PTR"], description: "DNS record type", }, name: { type: "string", description: "DNS record name", }, content: { type: "string", description: "DNS record content", }, ttl: { type: "number", description: "Time to live (TTL) in seconds (default: 1 for auto)", minimum: 1, }, priority: { type: "number", description: "Priority (for MX records)", }, proxied: { type: "boolean", description: "Whether the record should be proxied through Cloudflare", }, }, required: ["type", "name", "content"], }, },
  • Zod enum schema for valid DNS record types, used in CreateDnsRecordRequest.
    export const DnsRecordType = z.enum([ "A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "CAA", "PTR" ]);

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