/**
* Gandi Domain management tools
*/
import { json, error, type ToolDefinition } from "../lib/mcp-core.js";
import { GandiClient } from "../lib/client.js";
import type { GandiDomain, GandiDomainDetails, GandiDomainCheck, GandiContact } from "../types/index.js";
export function createDomainTools(gandiClient: GandiClient): ToolDefinition[] {
/**
* List managed domains
*/
const listDomainsTool: ToolDefinition = {
name: "gandi_domains_list",
description: "List all domain names managed by Gandi account",
inputSchema: {
type: "object",
properties: {},
required: [],
},
handler: async () => {
try {
const domains = await gandiClient.get<GandiDomain[]>("/domain/domains");
return json({
domains: domains.map(d => ({
fqdn: d.fqdn,
status: d.status,
auto_renew: d.auto_renew,
services: d.services,
created_at: d.dates.created_at,
registry_ends_at: d.dates.registry_ends_at
})),
count: domains.length
});
} catch (err: any) {
return error(`Failed to list domains: ${err.message}`);
}
},
};
/**
* Get domain details
*/
const getDomainTool: ToolDefinition = {
name: "gandi_domains_get",
description: "Get detailed information about a specific domain",
inputSchema: {
type: "object",
properties: {
domain: {
type: "string",
description: "Domain name (e.g., example.com)",
},
},
required: ["domain"],
},
handler: async (args) => {
const domain = args.domain as string;
try {
const domainDetails = await gandiClient.get<GandiDomainDetails>(`/domain/domains/${domain}`);
return json({ domain: domainDetails });
} catch (err: any) {
if (err.message.includes('404')) {
return error(`Domain '${domain}' not found or not managed by this account`);
}
return error(`Failed to get domain details: ${err.message}`);
}
},
};
/**
* Check domain availability
*/
const checkDomainTool: ToolDefinition = {
name: "gandi_domains_check",
description: "Check if a domain name is available for registration",
inputSchema: {
type: "object",
properties: {
domain: {
type: "string",
description: "Domain name to check (e.g., example.com)",
},
},
required: ["domain"],
},
handler: async (args) => {
const domain = args.domain as string;
try {
const checkResult = await gandiClient.get<GandiDomainCheck>("/domain/check", { name: domain });
return json({
domain: checkResult.name,
status: checkResult.status,
available: checkResult.status === 'available',
process: checkResult.process,
prices: checkResult.prices
});
} catch (err: any) {
return error(`Failed to check domain availability: ${err.message}`);
}
},
};
/**
* List domain contacts
*/
const listDomainContactsTool: ToolDefinition = {
name: "gandi_domains_contacts",
description: "List contacts associated with a domain",
inputSchema: {
type: "object",
properties: {
domain: {
type: "string",
description: "Domain name (e.g., example.com)",
},
},
required: ["domain"],
},
handler: async (args) => {
const domain = args.domain as string;
try {
const contacts = await gandiClient.get<GandiContact[]>(`/domain/domains/${domain}/contacts`);
return json({
domain,
contacts: contacts.map(c => ({
id: c.id,
type: c.type,
given: c.given,
family: c.family,
email: c.email,
phone: c.phone,
country: c.country,
city: c.city,
data_obfuscated: c.data_obfuscated,
mail_obfuscated: c.mail_obfuscated
})),
count: contacts.length
});
} catch (err: any) {
if (err.message.includes('404')) {
return error(`Domain '${domain}' not found or not managed by this account`);
}
return error(`Failed to get domain contacts: ${err.message}`);
}
},
};
return [
listDomainsTool,
getDomainTool,
checkDomainTool,
listDomainContactsTool,
];
}