update_dns_record
Update an existing DNS record by modifying its type, name, content, TTL, proxy status, and other attributes.
Instructions
Update an existing DNS record. Can modify type, name, content, TTL, proxy status, etc.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| zone_id | Yes | The zone ID | |
| record_id | Yes | The DNS record ID to update | |
| type | Yes | DNS record type | |
| name | Yes | DNS record name | |
| content | Yes | DNS record content | |
| ttl | No | Time to live | |
| proxied | No | Whether the record is proxied through Cloudflare | |
| priority | No | Priority (for MX, SRV records) | |
| comment | No | Comment for the DNS record |
Implementation Reference
- Handler function that updates a DNS record via Cloudflare API. Constructs a PUT request to /zones/{zone_id}/dns_records/{record_id} with the required fields (type, name, content) and optional fields (ttl, proxied, priority, comment).
async def _update_dns_record(self, args: dict) -> Any: """Update DNS record.""" data = { "type": args["type"], "name": args["name"], "content": args["content"], } if "ttl" in args: data["ttl"] = args["ttl"] if "proxied" in args: data["proxied"] = args["proxied"] if "priority" in args: data["priority"] = args["priority"] if "comment" in args: data["comment"] = args["comment"] return await self._make_request( f"/zones/{args['zone_id']}/dns_records/{args['record_id']}", method="PUT", data=data, ) - Schema/input definition for the update_dns_record tool. Defines required fields (zone_id, record_id, type, name, content) and optional fields (ttl, proxied, priority, comment).
Tool( name="update_dns_record", description="Update an existing DNS record. Can modify type, name, content, TTL, proxy status, etc.", inputSchema={ "type": "object", "properties": { "zone_id": {"type": "string", "description": "The zone ID"}, "record_id": { "type": "string", "description": "The DNS record ID to update", }, "type": {"type": "string", "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"}, "proxied": { "type": "boolean", "description": "Whether the record is proxied through Cloudflare", }, "priority": { "type": "number", "description": "Priority (for MX, SRV records)", }, "comment": { "type": "string", "description": "Comment for the DNS record", }, }, "required": ["zone_id", "record_id", "type", "name", "content"], }, ), - src/cloudflare_mcp_server/__init__.py:414-415 (registration)Registration in call_tool handler that routes the 'update_dns_record' tool name to the _update_dns_record method.
elif name == "update_dns_record": result = await self._update_dns_record(arguments) - Helper function _make_request used by _update_dns_record to perform the actual HTTP PUT request to the Cloudflare API.
async def _make_request( self, endpoint: str, method: str = "GET", data: Optional[dict] = None, params: Optional[dict] = None, ) -> Any: """Make a request to the Cloudflare API.""" url = f"{CLOUDFLARE_API_BASE}{endpoint}" headers = { "Authorization": f"Bearer {self.api_token}", "Content-Type": "application/json", } try: response = await self.client.request( method=method, url=url, json=data, params=params, headers=headers, ) response.raise_for_status() result = response.json() if not result.get("success"): errors = result.get("errors", []) raise Exception(f"Cloudflare API error: {json.dumps(errors)}") return result.get("result") except httpx.HTTPError as e: raise Exception(f"HTTP error occurred: {str(e)}")