Skip to main content
Glama

Brasil API MCP

index.ts1.56 kB
import { z } from "zod"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { getBrasilApiData, formatErrorResponse } from "../../utils/api.js"; /** * Register CEP (Postal Code) related tools to the MCP server * @param server MCP Server instance */ 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"} ` }] }; } ); }

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