buscar_cep
Retrieve Brazilian postal code (CEP) details like street, neighborhood, city, and state using the ViaCEP API via the MCP-CEP server. Input a CEP to get instant address information.
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
| Name | Required | Description | Default |
|---|---|---|---|
| cep | Yes |
Implementation Reference
- cep.py:11-11 (registration)Registration of the buscar_cep tool using the @mcp.tool() decorator from FastMCP.@mcp.tool()
- cep.py:12-20 (schema)Type hints and docstring defining the input schema (cep: str) and output (dict) for the 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. """
- cep.py:12-31 (handler)The core handler function that implements the logic to query the ViaCEP API for Brazilian CEP information, handling errors and formatting.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)}"}