mcp-namecheap
Version:
MCP server for interacting with Namecheap API
153 lines • 8.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.configSchema = void 0;
exports.default = createServer;
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
const zod_1 = require("zod");
const namecheap_client_js_1 = require("./namecheap-client.js");
const tld_cache_js_1 = require("./tld-cache.js");
// Configuration schema for Smithery
const configSchema = zod_1.z.object({
NAMECHEAP_API_KEY: zod_1.z.string().describe("Namecheap API key"),
NAMECHEAP_API_USER: zod_1.z.string().describe("Namecheap API username"),
NAMECHEAP_CLIENT_IP: zod_1.z.string().describe("Whitelisted IP address for API access"),
NAMECHEAP_USE_SANDBOX: zod_1.z.boolean().optional().default(false).describe("Use sandbox API endpoint")
});
exports.configSchema = configSchema;
function createServer({ config }) {
const server = new mcp_js_1.McpServer({
name: "mcp-namecheap",
version: "1.0.0",
});
const namecheapClient = new namecheap_client_js_1.NamecheapClient(config.NAMECHEAP_API_KEY, config.NAMECHEAP_API_USER, config.NAMECHEAP_CLIENT_IP, config.NAMECHEAP_USE_SANDBOX);
const tldCache = new tld_cache_js_1.TldCache(namecheapClient);
// Domain listing tool
server.tool("namecheap_domains_list", "Get a list of domains in your Namecheap account", {
listType: zod_1.z.enum(["ALL", "EXPIRING", "EXPIRED"]).optional().default("ALL").describe("Type of list to return"),
page: zod_1.z.number().optional().default(1).describe("Page number for pagination"),
pageSize: zod_1.z.number().optional().default(20).describe("Number of domains per page"),
searchTerm: zod_1.z.string().optional().describe("Filter domains by search term"),
sortBy: zod_1.z.enum(["NAME", "NAME_DESC", "EXPIREDATE", "EXPIREDATE_DESC", "CREATEDATE", "CREATEDATE_DESC"]).optional().describe("Sort order for results")
}, async (args) => {
const result = await namecheapClient.domainsList(args);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// Domain availability check
server.tool("namecheap_domains_check", "Check if domains are available for registration (supports bulk checks)", {
domainList: zod_1.z.array(zod_1.z.string()).describe("List of domain names to check availability")
}, async (args) => {
const result = await namecheapClient.domainsCheck(args);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// Get domain information
server.tool("namecheap_domains_getinfo", "Get detailed information about a specific domain", {
domainName: zod_1.z.string().describe("Domain name to get information for"),
hostName: zod_1.z.string().optional().describe("Hosted domain name")
}, async (args) => {
const result = await namecheapClient.domainsGetInfo(args);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// Get domain contacts
server.tool("namecheap_domains_getcontacts", "Get contact information for a domain", {
domainName: zod_1.z.string().describe("Domain name to get contacts for")
}, async (args) => {
const result = await namecheapClient.domainsGetContacts(args);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// Register domain
server.tool("namecheap_domains_create", "Register a new domain name", {
domainName: zod_1.z.string().describe("Domain name to register"),
years: zod_1.z.number().min(1).max(10).describe("Number of years to register"),
registrantFirstName: zod_1.z.string().describe("Registrant first name"),
registrantLastName: zod_1.z.string().describe("Registrant last name"),
registrantAddress1: zod_1.z.string().describe("Registrant address line 1"),
registrantCity: zod_1.z.string().describe("Registrant city"),
registrantStateProvince: zod_1.z.string().describe("Registrant state/province"),
registrantPostalCode: zod_1.z.string().describe("Registrant postal code"),
registrantCountry: zod_1.z.string().describe("Registrant country code"),
registrantPhone: zod_1.z.string().describe("Registrant phone number"),
registrantEmailAddress: zod_1.z.string().describe("Registrant email address"),
registrantOrganizationName: zod_1.z.string().optional().describe("Registrant organization name"),
techFirstName: zod_1.z.string().optional().describe("Tech contact first name"),
techLastName: zod_1.z.string().optional().describe("Tech contact last name"),
techEmailAddress: zod_1.z.string().optional().describe("Tech contact email"),
adminFirstName: zod_1.z.string().optional().describe("Admin contact first name"),
adminLastName: zod_1.z.string().optional().describe("Admin contact last name"),
adminEmailAddress: zod_1.z.string().optional().describe("Admin contact email"),
nameservers: zod_1.z.string().optional().describe("Comma-separated list of nameservers"),
addFreeWhoisguard: zod_1.z.enum(["yes", "no"]).optional().default("yes").describe("Add free WhoisGuard privacy protection"),
wgEnabled: zod_1.z.enum(["yes", "no"]).optional().default("yes").describe("Enable WhoisGuard privacy protection")
}, async (args) => {
const result = await namecheapClient.domainsCreate(args);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// Get TLD list
server.tool("namecheap_domains_gettldlist", "Get a list of all supported TLDs with filtering and pagination", {
page: zod_1.z.number().optional().default(1).describe("Page number for pagination"),
pageSize: zod_1.z.number().optional().default(50).max(200).describe("Number of TLDs per page"),
search: zod_1.z.string().optional().describe("Search for TLDs containing this text"),
registerable: zod_1.z.boolean().optional().describe("Filter to only show TLDs that can be registered via API"),
sortBy: zod_1.z.enum(["name", "popularity"]).optional().default("name").describe("Sort TLDs by name or popularity")
}, async (args) => {
const result = await tldCache.getTlds({
search: args.search,
registerable: args.registerable,
page: args.page,
pageSize: args.pageSize,
sortBy: args.sortBy,
});
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// DNS get list
server.tool("namecheap_dns_getlist", "Get DNS host records for a domain", {
sld: zod_1.z.string().describe("Second level domain (e.g., 'example' from 'example.com')"),
tld: zod_1.z.string().describe("Top level domain (e.g., 'com' from 'example.com')")
}, async (args) => {
const result = await namecheapClient.dnsGetList(args.sld, args.tld);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// DNS set custom nameservers
server.tool("namecheap_dns_setcustom", "Set custom nameservers for a domain", {
sld: zod_1.z.string().describe("Second level domain"),
tld: zod_1.z.string().describe("Top level domain"),
nameservers: zod_1.z.array(zod_1.z.string()).describe("List of nameserver addresses")
}, async (args) => {
const result = await namecheapClient.dnsSetCustom(args.sld, args.tld, args.nameservers);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
// DNS set host records
server.tool("namecheap_dns_sethosts", "Set DNS host records for a domain", {
sld: zod_1.z.string().describe("Second level domain"),
tld: zod_1.z.string().describe("Top level domain"),
hosts: zod_1.z.array(zod_1.z.object({
hostname: zod_1.z.string().describe("Subdomain or @ for root"),
recordType: zod_1.z.enum(["A", "AAAA", "CNAME", "MX", "TXT", "NS", "SRV", "CAA"]).describe("DNS record type"),
address: zod_1.z.string().describe("Value for the DNS record"),
ttl: zod_1.z.number().optional().default(1800).describe("Time to live in seconds"),
mxPriority: zod_1.z.number().optional().describe("Priority for MX records")
})).describe("Array of DNS host records")
}, async (args) => {
const result = await namecheapClient.dnsSetHosts(args.sld, args.tld, args.hosts);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
};
});
return server.server;
}
//# sourceMappingURL=smithery.js.map