get_postal_code_v1
Retrieve location data for any Brazilian address using its CEP postal code. This tool provides detailed address information including street, neighborhood, city, and state from the BrasilAPI database.
Instructions
Get a location data given a CEP (postal code).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cep | Yes | The CEP to query |
Implementation Reference
- src/tools/cep-v1.ts:16-30 (handler)The asynchronous handler function that queries the Brasil API for CEP data, formats the result using prettifyJson, and returns it as McpTextContent, or throws an error on failure.handler: async ({ cep }) => { try { const result = await brasilApiClient.cepV1.getBy(cep); const content: McpTextContent = { type: "text", text: `CEP found:\n${prettifyJson(result.data)}`, }; return { content: [content], }; } catch (error: any) { console.error(error); throw new Error(`Failed to fetch cep ${cep}`); } },
- src/tools/cep-v1.ts:6-8 (schema)Zod schema defining the input parameter 'cep' as a string.const getCepToolParams = { cep: z.string().describe("The CEP to query"), };
- src/index.ts:30-41 (registration)The tool getCepTool ("get_postal_code_v1") is included in the tools array and registered to the MCP server via registerTool.const tools = [ getCepTool, getCepV2Tool, getBookByISBNTool, getCNPJTool, getAllBanksTool, getBankByCodeTool, ]; tools.forEach((tool) => { registerTool(server, tool); });