Skip to main content
Glama

buscar_cep

Retrieve Brazilian postal code information including street, neighborhood, city, and state using the ViaCEP API. Enter a CEP in formats like 01001000 or 01001-000 to get address details.

Instructions

Consulta informações de um CEP brasileiro usando a API ViaCEP.

Args:
    cep: Código de Endereçamento Postal no formato 01001000 ou 01001-000.

Returns:
    Um dicionário com informações de endereço como rua, bairro, cidade e estado.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cepYes

Implementation Reference

  • cep.py:11-31 (handler)
    The handler function for the 'buscar_cep' MCP tool. It uses the ViaCEP API to retrieve address details for a given Brazilian CEP code. Includes type hints for input/output schema and comprehensive error handling.
    @mcp.tool()
    async def buscar_cep(cep: str) -> dict:
        """Consulta informações de um CEP brasileiro usando a API ViaCEP.
    
        Args:
            cep: Código de Endereçamento Postal no formato 01001000 ou 01001-000.
    
        Returns:
            Um dicionário com informações de endereço como rua, bairro, cidade e estado.
        """
        url = f"https://viacep.com.br/ws/{cep.replace('-', '')}/json/"
        try:
            async with httpx.AsyncClient(timeout=10.0) as client:
                response = await client.get(url)
                response.raise_for_status()
                data = response.json()
                if "erro" in data:
                    return {"erro": "CEP não encontrado."}
                return data
        except Exception as e:
            return {"erro": f"Falha ao consultar o CEP: {str(e)}"}
  • cep.py:11-11 (registration)
    Registration of the 'buscar_cep' tool via the @mcp.tool() decorator on the FastMCP instance.
    @mcp.tool()
  • cep.py:12-20 (schema)
    Input/output schema defined by type annotations (cep: str -> dict) and docstring describing parameters and return value.
    async def buscar_cep(cep: str) -> dict:
        """Consulta informações de um CEP brasileiro usando a API ViaCEP.
    
        Args:
            cep: Código de Endereçamento Postal no formato 01001000 ou 01001-000.
    
        Returns:
            Um dicionário com informações de endereço como rua, bairro, cidade e estado.
        """
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 the external API (ViaCEP) which adds some context, but doesn't describe error handling, rate limits, authentication requirements, or what happens with invalid CEP formats beyond the two examples given. For a tool that queries external data, this is a significant gap.

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 efficiently structured with clear sections: purpose statement, Args with parameter details, and Returns with output information. Every sentence adds value without redundancy, making it easy to parse and understand quickly.

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?

For a single-parameter lookup tool with no output schema, the description provides adequate coverage of the basic functionality. It explains what the tool does, parameter format, and return structure. However, it lacks important contextual details like error conditions, API limitations, or performance characteristics that would be helpful for an AI agent.

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

Parameters4/5

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

The description provides valuable parameter semantics that aren't in the schema. While the schema only indicates 'cep' is a required string, the description specifies it must be a Brazilian postal code and shows two valid formats (01001000 or 01001-000). With 0% schema description coverage, this description compensates well for the single parameter.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Consulta informações de um CEP brasileiro' (consult information about a Brazilian postal code). It specifies the action (consult) and resource (CEP information), though it doesn't explicitly differentiate from its sibling 'buscar_ceps_por_logradouro' beyond the different input method.

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 the API (ViaCEP), it doesn't indicate when to choose this over 'buscar_ceps_por_logradouro' or other potential methods for obtaining Brazilian address information.

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/wendellbigato/mcp-cep'

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