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
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | DNS record content | |
| name | No | DNS record name | |
| priority | No | Priority (for MX records) | |
| proxied | No | Whether the record should be proxied through Cloudflare | |
| recordId | Yes | The DNS record ID to update | |
| ttl | No | Time to live (TTL) in seconds | |
| type | No | DNS record type |
Implementation Reference
- src/index.ts:313-355 (handler)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"], }, },
- src/api.ts:169-183 (helper)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; },
- src/types.ts:59-72 (schema)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>;