Skip to main content
Glama
guilhermelirio

Brasil API MCP

cep-search

Find Brazilian address details by entering an 8-digit postal code (CEP). This tool retrieves location information from Brazil's public data services.

Instructions

Query address information from a Brazilian postal code (CEP)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cepYesPostal code to be queried (only numbers, 8 digits)

Implementation Reference

  • Handler function that queries BrasilAPI CEP endpoint, formats the address information, and returns it as MCP content or error response.
        async ({ cep }) => {
          console.error(`Consulting postal code: ${cep}`);
          
          const result = await getBrasilApiData(`/cep/v2/${cep}`);
          
          if (!result.success) {
            return formatErrorResponse(`Error querying postal code: ${result.message}`);
          }
          
          // Format the response data
          const address = result.data;
          return {
            content: [{ 
              type: "text" as const, 
              text: `
    Endereço encontrado:
    CEP: ${address.cep}
    Logradouro: ${address.street || "N/A"}
    Bairro: ${address.neighborhood || "N/A"}
    Cidade: ${address.city}
    Estado: ${address.state}
    Latitude: ${address.location?.coordinates?.latitude || "N/A"}
    Longitude: ${address.location?.coordinates?.longitude || "N/A"}
    Código IBGE: ${address.city_ibge_code || "N/A"}
    ` 
            }]
          };
        }
  • Zod input schema validating the 'cep' parameter as exactly 8 digits.
    {
      cep: z.string()
        .length(8, "Postal code must have exactly 8 digits")
        .regex(/^\d+$/, "Postal code must contain only numbers")
        .describe("Postal code to be queried (only numbers, 8 digits)")
    },
  • Registers the cep-search tool on the MCP server, defining name, description, input schema, and handler.
    export function registerCepTools(server: McpServer) {
      // Tool to query address information from a Brazilian postal code
      server.tool(
        "cep-search",
        "Query address information from a Brazilian postal code (CEP)",
        {
          cep: z.string()
            .length(8, "Postal code must have exactly 8 digits")
            .regex(/^\d+$/, "Postal code must contain only numbers")
            .describe("Postal code to be queried (only numbers, 8 digits)")
        },
        async ({ cep }) => {
          console.error(`Consulting postal code: ${cep}`);
          
          const result = await getBrasilApiData(`/cep/v2/${cep}`);
          
          if (!result.success) {
            return formatErrorResponse(`Error querying postal code: ${result.message}`);
          }
          
          // Format the response data
          const address = result.data;
          return {
            content: [{ 
              type: "text" as const, 
              text: `
    Endereço encontrado:
    CEP: ${address.cep}
    Logradouro: ${address.street || "N/A"}
    Bairro: ${address.neighborhood || "N/A"}
    Cidade: ${address.city}
    Estado: ${address.state}
    Latitude: ${address.location?.coordinates?.latitude || "N/A"}
    Longitude: ${address.location?.coordinates?.longitude || "N/A"}
    Código IBGE: ${address.city_ibge_code || "N/A"}
    ` 
            }]
          };
        }
      );
    }
  • src/index.ts:25-25 (registration)
    Top-level call to register the CEP tools during server initialization.
    registerCepTools(server);
  • Helper utility to fetch data from BrasilAPI endpoints, handling requests and errors, used in cep-search 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 full burden for behavioral disclosure but only states the basic function. It doesn't mention whether this is a read-only operation, if it requires authentication, rate limits, error conditions, or what format the address information returns. For a query tool with zero annotation coverage, this is insufficient.

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 with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a simple query tool, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete for contextual understanding. It doesn't explain what 'address information' includes (e.g., street, city, state), response format, or error handling. For a tool with rich potential output but no structured documentation, the description should provide more 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 description adds no parameter semantics beyond what the schema provides (100% coverage). The schema already documents 'cep' as an 8-digit numeric string for postal code querying. The description doesn't explain Brazilian CEP format, validation rules, or examples, so it meets the baseline for high schema coverage.

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') and resource ('address information from a Brazilian postal code (CEP)'), distinguishing it from sibling tools like cnpj-search or ibge-state-search which query different types of Brazilian data. It precisely communicates what the tool does without ambiguity.

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. While it mentions 'address information from a Brazilian postal code', it doesn't specify use cases, prerequisites, or contrast with similar tools like ibge-municipalities-list for location data. This leaves the agent without contextual usage instructions.

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