Skip to main content
Glama
gilberth

MCP Cloudflare DNS Server

update_dns_record

Modify a DNS record in Cloudflare by updating its type, name, content, TTL, priority, or proxied status using the specified record ID.

Instructions

Update an existing DNS record

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentNoDNS record content
nameNoDNS record name
priorityNoPriority (for MX records)
proxiedNoWhether the record should be proxied through Cloudflare
recordIdYesThe DNS record ID to update
ttlNoTime to live (TTL) in seconds
typeNoDNS record type

Implementation Reference

  • Main MCP tool handler for 'update_dns_record'. Processes input arguments, builds update object, calls CloudflareApi.updateDnsRecord, handles errors, and formats success/error responses.
    const handleUpdateDnsRecord = async (args: { recordId: string; 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 updates: any = {}; if (args.type) updates.type = DnsRecordType.parse(args.type); if (args.name) updates.name = args.name; if (args.content) updates.content = args.content; if (args.ttl !== undefined) updates.ttl = args.ttl; if (args.priority !== undefined) updates.priority = args.priority; if (args.proxied !== undefined) updates.proxied = args.proxied; const record = await CloudflareApi.updateDnsRecord(args.recordId, updates); return { content: [{ type: "text", text: `✅ DNS record updated 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 updating DNS record: ${error instanceof Error ? error.message : 'Unknown error'}` }], }; } };
  • src/index.ts:118-156 (registration)
    Tool registration in listTools handler, defining name 'update_dns_record', description, and detailed inputSchema matching the handler arguments.
    name: "update_dns_record", description: "Update an existing DNS record", inputSchema: { type: "object", properties: { recordId: { type: "string", description: "The DNS record ID to update", }, 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", minimum: 1, }, priority: { type: "number", description: "Priority (for MX records)", }, proxied: { type: "boolean", description: "Whether the record should be proxied through Cloudflare", }, }, required: ["recordId"], }, },
  • CloudflareApi.updateDnsRecord helper function that validates updates with Zod, makes PATCH request to Cloudflare API endpoint `/zones/{zoneId}/dns_records/{recordId}`, parses response, and returns the updated DnsRecord.
    updateDnsRecord: async (recordId: string, updates: UpdateDnsRecord): Promise<DnsRecord> => { const validatedUpdates = UpdateDnsRecordRequest.parse(updates); const response = await api(`dns_records/${recordId}`, 'PATCH', validatedUpdates); 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 update DNS record'); } return data.result; },
  • Zod schema UpdateDnsRecordRequest for validating optional update fields (type, name, content, ttl, priority, proxied) and inferred TypeScript type UpdateDnsRecord, used in API layer.
    export const UpdateDnsRecordRequest = z.object({ type: DnsRecordType.optional(), name: z.string().optional(), content: z.string().optional(), ttl: z.number().optional(), priority: z.number().optional(), proxied: z.boolean().optional(), }); export type DnsRecord = z.infer<typeof CloudflareDnsRecord>; export type DnsRecordTypeEnum = z.infer<typeof DnsRecordType>; export type ApiResponse = z.infer<typeof CloudflareApiResponse>; export type CreateDnsRecord = z.infer<typeof CreateDnsRecordRequest>; export type UpdateDnsRecord = z.infer<typeof UpdateDnsRecordRequest>;

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