Skip to main content
Glama
mauricio-cantu

brasil-api-mcp-server

get_postal_code_v2

Retrieve location data for Brazilian addresses using CEP postal codes. Query street names, neighborhoods, cities, and states to enhance applications with accurate Brazilian address information.

Instructions

Version 2 of get a location data given a CEP (postal code).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cepYesThe CEP to query

Implementation Reference

  • The handler function that implements the core logic of the tool: fetches postal code (CEP) data from Brasil API using the provided CEP and returns 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}`);
      }
    },
  • Zod-based input schema defining the required 'cep' parameter as a string.
    const getCepV2ToolParams = {
      cep: z.string().describe("The CEP to query"),
    };
  • The tool definition object exported from the file, specifying name, description, params schema, and handler.
    export const getCepV2Tool: McpToolDefinition<GetCepV2ToolParams> = {
      name: "get_postal_code_v2",
      description: "Version 2 of get a location data given a CEP (postal code).",
      params: getCepV2ToolParams,
      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/index.ts:30-41 (registration)
    The tool is imported and included in the central tools array, then registered to the MCP server.
    const tools = [
      getCepTool,
      getCepV2Tool,
      getBookByISBNTool,
      getCNPJTool,
      getAllBanksTool,
      getBankByCodeTool,
    ];
    
    tools.forEach((tool) => {
      registerTool(server, tool);
    });

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/mauricio-cantu/brasil-api-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server