list_zones
Retrieve all zones (domains) in your Cloudflare account with details like ID, name, status, and nameservers. Filter results by name or status.
Instructions
List all zones (domains) in the Cloudflare account. Returns zone details including ID, name, status, and nameservers.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Filter zones by name (optional) | |
| status | No | Filter by status: active, pending, initializing, moved, deleted, deactivated (optional) | |
| page | No | Page number for pagination (default: 1) | |
| per_page | No | Number of zones per page (default: 20, max: 50) |
Implementation Reference
- The _list_zones method is the handler implementation. It builds query parameters from the args dict (name, status, page, per_page) and calls _make_request to GET /zones.
async def _list_zones(self, args: dict) -> Any: """List zones.""" params = {} if args.get("name"): params["name"] = args["name"] if args.get("status"): params["status"] = args["status"] if args.get("page"): params["page"] = args["page"] if args.get("per_page"): params["per_page"] = args["per_page"] return await self._make_request("/zones", params=params) - The tool registration in list_tools() includes the name 'list_zones', description, and inputSchema defining optional parameters: name (string), status (string), page (number), per_page (number).
name="list_zones", description=( "List all zones (domains) in the Cloudflare account. " "Returns zone details including ID, name, status, and nameservers." ), inputSchema={ "type": "object", "properties": { "name": { "type": "string", "description": "Filter zones by name (optional)", }, "status": { "type": "string", "description": "Filter by status: active, pending, initializing, moved, deleted, deactivated (optional)", }, "page": { "type": "number", "description": "Page number for pagination (default: 1)", }, "per_page": { "type": "number", "description": "Number of zones per page (default: 20, max: 50)", }, }, }, - src/cloudflare_mcp_server/__init__.py:406-407 (registration)The call_tool handler dispatches to _list_zones when tool name is 'list_zones'.
if name == "list_zones": result = await self._list_zones(arguments) - The _make_request helper method handles the HTTP request to the Cloudflare API, parsing the response and returning the result.
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")