Skip to main content
Glama
guilhermelirio

Brasil API MCP

registrobr-domain-check

Check .br domain availability and registration status to determine if a Brazilian domain name is ready for use or already taken.

Instructions

Check the status and availability of a .br domain name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
domainYesDomain name to check (with or without .br extension)

Implementation Reference

  • The core handler function that processes the domain input, calls the BrasilAPI, and formats the markdown response with availability status, nameservers, expiry, and suggestions.
        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}
    ` 
            }]
          };
        }
      );
  • Zod input schema defining the 'domain' parameter for the tool.
    {
      domain: z.string()
        .describe("Domain name to check (with or without .br extension)")
    },
  • The registration function for the Registro.br tool, called from main index to add the tool to the MCP server.
    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}
    ` 
            }]
          };
        }
      );
    }
  • Utility function to make API requests to BrasilAPI, handling success and error responses. Used to fetch domain data.
    export async function getBrasilApiData(endpoint: string, params: Record<string, any> = {}) {
      try {
        const url = `${BASE_URL}${endpoint}`;
        console.error(`Making request to: ${url}`);
        
        const response = await axios.get(url, { params });
        return { 
          data: response.data,
          success: true
        };
      } catch (error: any) {
        console.error(`Error in API request: ${error.message}`);
        
        // Handle API errors in a structured format
        if (error.response) {
          return {
            success: false,
            statusCode: error.response.status,
            message: error.response.data?.message || error.message,
            error: error.response.data
          };
        }
        
        return {
          success: false,
          message: error.message,
          error
        };
      }
    }
  • Utility function to format error messages into MCP-compatible responses. Used when API calls fail.
    export function formatErrorResponse(message: string) {
      return {
        content: [{ 
          type: "text" as const, 
          text: message 
        }],
        isError: true
      };
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/guilhermelirio/brasil-api-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server