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
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"recordId": "<recordId>"
},
"name": "update_dns_record"
}
}Input 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>;