delete_dns_record
Remove a specified DNS record from Cloudflare by providing its ID using this tool on the MCP Cloudflare DNS Server.
Instructions
Delete a DNS record
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| recordId | Yes | The DNS record ID to delete |
Implementation Reference
- src/index.ts:357-378 (handler)The primary handler function for the 'delete_dns_record' tool in the MCP server. It checks configuration, calls the Cloudflare API via CloudflareApi.deleteDnsRecord, handles errors, and returns a formatted response.const handleDeleteDnsRecord = async (args: { recordId: string }) => { try { if (!configureApiIfNeeded()) { return { content: [{ type: "text", text: "❌ Configuration incomplete. Please configure Cloudflare API Token and Zone ID first." }], }; } await CloudflareApi.deleteDnsRecord(args.recordId); return { content: [{ type: "text", text: `✅ DNS record deleted successfully! (ID: ${args.recordId})` }], }; } catch (error) { return { content: [{ type: "text", text: `❌ Error deleting DNS record: ${error instanceof Error ? error.message : 'Unknown error'}` }], }; } };
- src/api.ts:186-193 (helper)Core helper function that performs the actual HTTP DELETE request to Cloudflare's API to delete the DNS record by ID, including response validation.deleteDnsRecord: async (recordId: string): Promise<void> => { const response = await api(`dns_records/${recordId}`, 'DELETE'); const data = CloudflareApiResponse.parse(await response.json()); if (!data.success) { throw new Error(`API Error: ${data.errors.map(e => e.message).join(', ')}`); } },
- src/index.ts:157-170 (registration)Registration of the 'delete_dns_record' tool in the MCP server's listTools response, including name, description, and input schema.{ name: "delete_dns_record", description: "Delete a DNS record", inputSchema: { type: "object", properties: { recordId: { type: "string", description: "The DNS record ID to delete", }, }, required: ["recordId"], }, },
- src/index.ts:195-197 (registration)Dispatch logic in the MCP CallToolRequestHandler that routes calls to 'delete_dns_record' to the appropriate handler function.if (name === "delete_dns_record") { return await handleDeleteDnsRecord(args as { recordId: string }); }
- src/api.ts:188-193 (schema)Response validation using CloudflareApiResponse schema after the DELETE API call.const data = CloudflareApiResponse.parse(await response.json()); if (!data.success) { throw new Error(`API Error: ${data.errors.map(e => e.message).join(', ')}`); } },