cloudflare-dns-mcp_update_dns_record
Modify DNS records in Cloudflare by updating zone name, record ID, type, name, content, TTL, and other parameters directly through structured API tools.
Instructions
Update an existing DNS record by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | No | ||
| name | No | ||
| port | No | ||
| priority | No | ||
| proxied | No | ||
| record_id | Yes | ||
| target | No | ||
| ttl | No | ||
| type | No | ||
| weight | No | ||
| zone_name | Yes |
Implementation Reference
- src/tools/dns-records.ts:195-228 (handler)Executes the tool logic: parses input, resolves zone ID, fetches existing record for partial updates, validates special record types (MX, SRV), merges parameters, ensures TXT quoting, performs Cloudflare PUT API call to update the record, returns MCP-formatted response with updated record details.handler: async (params: z.infer<typeof UpdateDnsRecordInputSchema>) => { const { zone_name, record_id, ...rest } = UpdateDnsRecordInputSchema.parse(params); 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; // Cloudflare requires all mandatory fields; fetch current record if partial update const existing = await client.get<typeof DNSRecordSchema['_type']>(`/zones/${zoneId}/dns_records/${record_id}`); // Validate edge-cases again on update if ((rest.type ?? existing.type) === 'MX' && (rest.priority ?? existing.priority) === undefined) { throw new Error('MX record update requires "priority"'); } if ((rest.type ?? existing.type) === 'SRV') { const required = ['priority', 'weight', 'port', 'target']; for (const f of required) { if ((rest as any)[f] === undefined && (existing as any)[f] === undefined) { throw new Error(`SRV record update requires "${f}"`); } } } const merged = { ...existing, ...rest } as any; if ((merged.type ?? existing.type) === 'TXT' && merged.content) { merged.content = ensureTxtQuotes(merged.content); } const payload = merged; const record = await client.put<typeof DNSRecordSchema['_type']>(`/zones/${zoneId}/dns_records/${record_id}`, payload); return { content: [ { type: "text", text: JSON.stringify({ ...record, zone_name }, null, 2) } ] }; },
- src/tools/dns-records.ts:177-194 (schema)Input schema (Zod) defining parameters for updating a DNS record: zone_name (required), record_id (required), and optional fields like type, name, content, ttl, priority, etc. Tool definition includes input/output schemas converted to JSON Schema.const UpdateDnsRecordInputSchema = z.object({ zone_name: z.string(), record_id: z.string(), type: z.string().optional(), name: z.string().optional(), content: z.string().optional(), ttl: z.number().optional(), priority: z.number().optional(), weight: z.number().optional(), port: z.number().optional(), target: z.string().optional(), proxied: z.boolean().optional(), }); const updateDnsRecordTool: Tool = { name: 'cloudflare-dns-mcp/update_dns_record', description: 'Update an existing DNS record by ID', inputSchema: zodToJsonSchema(UpdateDnsRecordInputSchema) as any, outputSchema: zodToJsonSchema(DnsRecordOutputSchema) as any,
- src/tools/dns-records.ts:328-339 (registration)Registration of the update_dns_record tool within the getDnsTools function's returned tools object.return { tools: { 'cloudflare-dns-mcp/echo': echoTool, 'cloudflare-dns-mcp/list_dns_records': listDnsRecordsTool, // create DNS record 'cloudflare-dns-mcp/create_dns_record': createDnsRecordTool, 'cloudflare-dns-mcp/list_zones': listZonesTool, 'cloudflare-dns-mcp/list_zone_settings': listZoneSettingsTool, 'cloudflare-dns-mcp/list_ssl_certs': listSslCertsTool, 'cloudflare-dns-mcp/update_dns_record': updateDnsRecordTool, 'cloudflare-dns-mcp/delete_dns_record': deleteDnsRecordTool, },
- src/index.ts:18-32 (registration)Main server registration: imports getDnsTools (line 5), calls it to get dnsTools, spreads dnsTools.tools into allTools aggregate.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, ...securityTools.tools, ...sslCertTools.tools, ...echoTools.tools, ...redirectTools.tools, ...zoneTools.tools, } as Record<string, any>;
- src/index.ts:48-52 (helper)Sanitizes tool names by replacing non-alphanumeric chars (like '/') with '_', creating 'cloudflare-dns-mcp_update_dns_record' from 'cloudflare-dns-mcp/update_dns_record' for client use.const toolsMap: Record<string, any> = {}; for (const tool of Object.values(allTools)) { const safeName = tool.name.replace(/[^a-zA-Z0-9_-]/g, '_'); toolsMap[safeName] = tool; }