We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/johnsorrentino/mcp-namecheap'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
import axios from 'axios';
import { parseString } from 'xml2js';
import { promisify } from 'util';
import { NamecheapConfig, NamecheapResponse, DomainInfo, DomainCheckResult } from './types.js';
const parseXML = promisify(parseString);
export class NamecheapClient {
private config: NamecheapConfig;
private baseUrl: string;
constructor(config: NamecheapConfig) {
this.config = config;
this.baseUrl = config.sandbox
? 'https://api.sandbox.namecheap.com/xml.response'
: 'https://api.namecheap.com/xml.response';
}
private async makeRequest(command: string, additionalParams: Record<string, string> = {}): Promise<any> {
const params = new URLSearchParams({
ApiUser: this.config.apiUser,
ApiKey: this.config.apiKey,
UserName: this.config.userName,
ClientIp: this.config.clientIp,
Command: command,
...additionalParams
});
try {
const response = await axios.get(`${this.baseUrl}?${params.toString()}`);
const parsed = await parseXML(response.data) as NamecheapResponse;
if (parsed.ApiResponse.$.Status !== 'OK') {
const errors = parsed.ApiResponse.Errors;
if (errors && errors.length > 0) {
throw new Error(`Namecheap API Error: ${errors[0].Error[0]._}`);
}
throw new Error('Unknown Namecheap API error');
}
return parsed.ApiResponse.CommandResponse[0];
} catch (error: any) {
if (axios.isAxiosError(error)) {
throw new Error(`HTTP Error: ${error.message}`);
}
throw error;
}
}
async getList(): Promise<DomainInfo[]> {
const response = await this.makeRequest('namecheap.domains.getList');
if (!response.DomainGetListResult || !response.DomainGetListResult[0] || !response.DomainGetListResult[0].Domain) {
return [];
}
const domains = response.DomainGetListResult[0].Domain;
return domains.map((domain: any) => ({
id: domain.$.ID,
name: domain.$.Name,
user: domain.$.User,
created: domain.$.Created,
expires: domain.$.Expires,
isExpired: domain.$.IsExpired === 'true',
isLocked: domain.$.IsLocked === 'true',
autoRenew: domain.$.AutoRenew === 'true',
whoisGuard: domain.$.WhoisGuard,
isPremium: domain.$.IsPremium === 'true',
isOurDns: domain.$.IsOurDNS === 'true'
}));
}
async check(domainList: string[]): Promise<DomainCheckResult[]> {
const domainListParam = domainList.join(',');
const response = await this.makeRequest('namecheap.domains.check', {
DomainList: domainListParam
});
if (!response.DomainCheckResult) {
return [];
}
const results = Array.isArray(response.DomainCheckResult)
? response.DomainCheckResult
: [response.DomainCheckResult];
return results.map((result: any) => ({
domain: result.$.Domain,
available: result.$.Available === 'true',
errorCode: result.$.ErrorCode,
description: result.$.Description,
isPremiumName: result.$.IsPremiumName === 'true',
premiumRegistrationPrice: result.$.PremiumRegistrationPrice,
premiumRenewalPrice: result.$.PremiumRenewalPrice,
premiumRestorePrice: result.$.PremiumRestorePrice,
premiumTransferPrice: result.$.PremiumTransferPrice,
icannFee: result.$.IcannFee,
eapFee: result.$.EapFee
}));
}
async setCustom(domainName: string, nameservers: string[]): Promise<boolean> {
const nameserverParams: Record<string, string> = {};
nameservers.forEach((ns, index) => {
nameserverParams[`Nameserver${index + 1}`] = ns;
});
const response = await this.makeRequest('namecheap.domains.dns.setCustom', {
SLD: domainName.split('.')[0],
TLD: domainName.split('.').slice(1).join('.'),
...nameserverParams
});
return response.DomainDNSSetCustomResult &&
response.DomainDNSSetCustomResult[0] &&
response.DomainDNSSetCustomResult[0].$.IsSuccess === 'true';
}
}