index.ts•2.64 kB
import { z } from "zod";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { getBrasilApiData, formatErrorResponse } from "../../utils/api.js";
/**
* Register Registro BR related tools to the MCP server
* @param server MCP Server instance
*/
export function registerRegistroBrTools(server: McpServer) {
// Tool to check domain availability and status in Registro.br
server.tool(
"registrobr-domain-check",
"Check the status and availability of a .br domain name",
{
domain: z.string()
.describe("Domain name to check (with or without .br extension)")
},
async ({ domain }) => {
console.error(`Checking domain status: ${domain}`);
// Make sure we're using the domain name only without http or https
let cleanDomain = domain.toLowerCase();
cleanDomain = cleanDomain.replace(/^https?:\/\//i, "");
cleanDomain = cleanDomain.replace(/^www\./i, "");
// If domain doesn't end with .br, we don't add it automatically
// as the API accepts any domain name to evaluate
const result = await getBrasilApiData(`/registrobr/v1/${cleanDomain}`);
if (!result.success) {
return formatErrorResponse(`Error checking domain: ${result.message}`);
}
// Format the response data
const domainInfo = result.data;
// Create a formatted response based on the domain status
let statusText;
if (domainInfo.status === "AVAILABLE") {
statusText = `${cleanDomain} is AVAILABLE for registration`;
} else if (domainInfo.status === "REGISTERED") {
statusText = `${cleanDomain} is REGISTERED`;
// Add more details if available
if (domainInfo.hosts && domainInfo.hosts.length > 0) {
statusText += `\nNameservers: ${domainInfo.hosts.join(", ")}`;
}
if (domainInfo.expiresAt) {
statusText += `\nExpires at: ${domainInfo.expiresAt}`;
}
if (domainInfo.suggestions && domainInfo.suggestions.length > 0) {
statusText += `\n\nSimilar available domains:\n${domainInfo.suggestions.join("\n")}`;
}
} else {
statusText = `Status for ${cleanDomain}: ${domainInfo.status}`;
if (domainInfo.suggestions && domainInfo.suggestions.length > 0) {
statusText += `\n\nSuggested available domains:\n${domainInfo.suggestions.join("\n")}`;
}
}
return {
content: [{
type: "text" as const,
text: `
Domain Check Result:
${statusText}
`
}]
};
}
);
}