get_postal_code_v2
Retrieve location details in Brazil using a CEP (postal code). Input a valid CEP to access accurate address information, enhancing applications with precise Brazilian geographical data.
Instructions
Version 2 of 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-v2.ts:20-34 (handler)The asynchronous handler function that fetches location data for the given CEP using BrasilAPI client and returns a formatted text response or throws an error.handler: async ({ cep }): Promise<McpResponse> => { try { const result = await brasilApiClient.cep.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-v2.ts:10-12 (schema)Zod schema defining the input parameters for the tool: a required 'cep' string.const getCepV2ToolParams = { cep: z.string().describe("The CEP to query"), };
- src/index.ts:30-41 (registration)The tool is included in the array of tools and registered on the MCP server instance via the registerTool utility.const tools = [ getCepTool, getCepV2Tool, getBookByISBNTool, getCNPJTool, getAllBanksTool, getBankByCodeTool, ]; tools.forEach((tool) => { registerTool(server, tool); });