dns_export_zone
Export a DNS zone file in standard BIND format for backup or transfer. Returns zone contents as text.
Instructions
Export a DNS zone file in standard BIND format. Returns the zone file as text.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| zone | Yes | Zone domain name to export |
Implementation Reference
- src/tools/zones.ts:248-252 (handler)Handler function for dns_export_zone tool. Validates the zone domain, calls the Technitium DNS API /api/zones/export endpoint to get the BIND zone file, and returns the result as JSON.
handler: async (args) => { const zone = validateDomain(args.zone as string); const text = await client.callRawTextGet("/api/zones/export", { zone }); return JSON.stringify({ zone, zoneFile: text }, null, 2); }, - src/tools/zones.ts:231-246 (schema)Schema/definition for dns_export_zone tool. Defines the tool name, description, and input schema requiring a 'zone' string parameter (the domain name to export).
{ definition: { name: "dns_export_zone", description: "Export a DNS zone file in standard BIND format. Returns the zone file as text.", inputSchema: { type: "object", properties: { zone: { type: "string", description: "Zone domain name to export", }, }, required: ["zone"], }, }, - src/tools/zones.ts:231-254 (registration)Registration of dns_export_zone as a tool entry inside the zoneTools() function, which is exported and included via getAllTools() in src/tools/index.ts.
{ definition: { name: "dns_export_zone", description: "Export a DNS zone file in standard BIND format. Returns the zone file as text.", inputSchema: { type: "object", properties: { zone: { type: "string", description: "Zone domain name to export", }, }, required: ["zone"], }, }, readonly: true, handler: async (args) => { const zone = validateDomain(args.zone as string); const text = await client.callRawTextGet("/api/zones/export", { zone }); return JSON.stringify({ zone, zoneFile: text }, null, 2); }, }, ]; - src/validate.ts:5-17 (helper)validateDomain helper function used in the handler to normalize and validate the zone domain name.
export function validateDomain(domain: string): string { if (!domain || typeof domain !== "string") { throw new Error("Domain name is required"); } const trimmed = domain.trim().toLowerCase(); if (trimmed.length > 253) { throw new Error("Domain name exceeds maximum length of 253 characters"); } if (!DOMAIN_RE.test(trimmed)) { throw new Error("Invalid domain name format"); } return trimmed; } - src/client.ts:166-210 (helper)callRawTextGet method on TechnitiumClient used to make the GET request to the /api/zones/export endpoint and return raw text (the BIND zone file).
async callRawTextGet( endpoint: string, params: Record<string, string> = {} ): Promise<string> { await this.ensureAuth(); const qs = new URLSearchParams({ ...params, token: this.sessionToken!, }); const resp = await fetch(`${this.config.url}${endpoint}?${qs.toString()}`, { method: "GET", }); const text = await resp.text(); try { const json = JSON.parse(text) as TechnitiumResponse; if (json.status === "invalid-token") { this.sessionToken = null; audit.logAuth("token_expired", false); await this.ensureAuth(); const retryQs = new URLSearchParams({ ...params, token: this.sessionToken!, }); const retryResp = await fetch( `${this.config.url}${endpoint}?${retryQs.toString()}`, { method: "GET" } ); return retryResp.text(); } if (json.status !== "ok") { throw new Error(json.errorMessage || `API error: ${json.status}`); } } catch (e) { if (e instanceof SyntaxError) { return text; } throw e; } return text; }