Skip to main content
Glama
guilhermelirio

Brasil API MCP

cnpj-search

Retrieve Brazilian company registration details by entering a valid 14-digit CNPJ number to access official business information.

Instructions

Query information about a Brazilian company by its CNPJ (National Registry of Legal Entities)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cnpjYesCNPJ to be queried (only numbers, 14 digits)

Implementation Reference

  • The handler function that executes the CNPJ search: logs the CNPJ, fetches data from Brasil API, handles errors, and formats a detailed text response with company information.
        async ({ cnpj }) => {
          console.error(`Consulting CNPJ: ${cnpj}`);
          
          const result = await getBrasilApiData(`/cnpj/v1/${cnpj}`);
          
          if (!result.success) {
            return formatErrorResponse(`Error querying CNPJ: ${result.message}`);
          }
          
          // Format the response data
          const company = result.data;
          return {
            content: [{ 
              type: "text" as const, 
              text: `
    Informações da Empresa:
    CNPJ: ${company.cnpj}
    Razão Social: ${company.razao_social}
    Nome Fantasia: ${company.nome_fantasia || "N/A"}
    Situação Cadastral: ${company.descricao_situacao_cadastral || "N/A"}
    Data de Abertura: ${company.data_inicio_atividade || "N/A"}
    CNAE Principal: ${company.cnae_fiscal} - ${company.cnae_fiscal_descricao || "N/A"}
    Natureza Jurídica: ${company.codigo_natureza_juridica} - ${company.natureza_juridica || "N/A"}
    
    Endereço:
    ${company.logradouro || ""} ${company.numero || ""} ${company.complemento || ""}
    ${company.bairro || ""}, ${company.municipio || ""} - ${company.uf || ""}
    CEP: ${company.cep || "N/A"}
    
    Contato:
    Telefone: ${company.ddd_telefone_1 || "N/A"}
    Email: ${company.email || "N/A"}
    ` 
            }]
          };
        }
  • Input schema using Zod: validates CNPJ as exactly 14 digits string.
    {
      cnpj: z.string()
        .regex(/^\d{14}$/, "CNPJ must contain exactly 14 numbers without any special characters")
        .describe("CNPJ to be queried (only numbers, 14 digits)")
    },
  • Registers the 'cnpj-search' tool on the MCP server, specifying name, description, input schema, and handler function.
      server.tool(
        "cnpj-search",
        "Query information about a Brazilian company by its CNPJ (National Registry of Legal Entities)",
        {
          cnpj: z.string()
            .regex(/^\d{14}$/, "CNPJ must contain exactly 14 numbers without any special characters")
            .describe("CNPJ to be queried (only numbers, 14 digits)")
        },
        async ({ cnpj }) => {
          console.error(`Consulting CNPJ: ${cnpj}`);
          
          const result = await getBrasilApiData(`/cnpj/v1/${cnpj}`);
          
          if (!result.success) {
            return formatErrorResponse(`Error querying CNPJ: ${result.message}`);
          }
          
          // Format the response data
          const company = result.data;
          return {
            content: [{ 
              type: "text" as const, 
              text: `
    Informações da Empresa:
    CNPJ: ${company.cnpj}
    Razão Social: ${company.razao_social}
    Nome Fantasia: ${company.nome_fantasia || "N/A"}
    Situação Cadastral: ${company.descricao_situacao_cadastral || "N/A"}
    Data de Abertura: ${company.data_inicio_atividade || "N/A"}
    CNAE Principal: ${company.cnae_fiscal} - ${company.cnae_fiscal_descricao || "N/A"}
    Natureza Jurídica: ${company.codigo_natureza_juridica} - ${company.natureza_juridica || "N/A"}
    
    Endereço:
    ${company.logradouro || ""} ${company.numero || ""} ${company.complemento || ""}
    ${company.bairro || ""}, ${company.municipio || ""} - ${company.uf || ""}
    CEP: ${company.cep || "N/A"}
    
    Contato:
    Telefone: ${company.ddd_telefone_1 || "N/A"}
    Email: ${company.email || "N/A"}
    ` 
            }]
          };
        }
      );
  • src/index.ts:26-26 (registration)
    Top-level call to register CNPJ tools (including 'cnpj-search') on the main MCP server instance.
    registerCnpjTools(server);
  • Helper function to fetch data from Brasil API, handling requests and errors, used by the CNPJ handler.
    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
        };
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions querying information but does not specify whether this is a read-only operation, requires authentication, has rate limits, or what the return format might be. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without any wasted words. It is appropriately sized for a simple query tool and earns its place by clearly stating the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (single parameter, no output schema, no annotations), the description is adequate but incomplete. It covers the purpose and parameter context but lacks behavioral details and usage guidelines, making it minimally viable but with clear gaps for an agent to understand full context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the parameter 'cnpj' fully documented in the input schema. The description adds minimal value beyond the schema by clarifying that CNPJ stands for 'National Registry of Legal Entities' and relates to Brazilian companies, but does not provide additional syntax or format details. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Query information') and target resource ('about a Brazilian company by its CNPJ'), distinguishing it from siblings like cep-search or bank-search that query different entities. It precisely defines what the tool does without being vague or tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like registrobr-domain-check or ibge-state-search, nor does it mention prerequisites or exclusions. It states the purpose but lacks context for tool selection among siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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