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.
        """

Tool Definition Quality

Score is being calculated. Check back soon.

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