Skip to main content
Glama
guilhermelirio

Brasil API MCP

bank-search

Search for Brazilian bank details using official bank codes to identify financial institutions and access their information.

Instructions

Find information about a Brazilian bank by its code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesBank code to search for

Implementation Reference

  • The handler function for the "bank-search" tool. It takes a bank code, fetches data from the Brasil API, handles errors, and formats the response with bank details including code, name, full name, and ISPB.
        async ({ code }) => {
          console.error(`Finding bank by code: ${code}`);
          
          const result = await getBrasilApiData(`/banks/v1/${code}`);
          
          if (!result.success) {
            return formatErrorResponse(`Error finding bank: ${result.message}`);
          }
          
          // Format the response data
          const bank = result.data;
          return {
            content: [{ 
              type: "text" as const, 
              text: `
    Bank Information:
    Code: ${bank.code}
    Name: ${bank.name}
    Full Name: ${bank.fullName}
    ISPB: ${bank.ispb}
    ` 
            }]
          };
        }
  • Zod input schema defining the 'code' parameter as a string for the bank-search tool.
      code: z.string()
        .describe("Bank code to search for")
    },
  • Registers the "bank-search" tool on the MCP server inside the registerBankTools function, specifying name, description, schema, and handler.
      server.tool(
        "bank-search",  
        "Find information about a Brazilian bank by its code",
        {
          code: z.string()
            .describe("Bank code to search for")
        },
        async ({ code }) => {
          console.error(`Finding bank by code: ${code}`);
          
          const result = await getBrasilApiData(`/banks/v1/${code}`);
          
          if (!result.success) {
            return formatErrorResponse(`Error finding bank: ${result.message}`);
          }
          
          // Format the response data
          const bank = result.data;
          return {
            content: [{ 
              type: "text" as const, 
              text: `
    Bank Information:
    Code: ${bank.code}
    Name: ${bank.name}
    Full Name: ${bank.fullName}
    ISPB: ${bank.ispb}
    ` 
            }]
          };
        }
      );
  • Helper function used by bank-search to fetch bank data from https://brasilapi.com.br/api/banks/v1/{code}, returning structured success or error response.
    export async function getBrasilApiData(endpoint: string, params: Record<string, any> = {}) {
      try {
        const url = `${BASE_URL}${endpoint}`;
        console.error(`Making request to: ${url}`);
        
        const response = await axios.get(url, { params });
        return { 
          data: response.data,
          success: true
        };
      } catch (error: any) {
        console.error(`Error in API request: ${error.message}`);
        
        // Handle API errors in a structured format
        if (error.response) {
          return {
            success: false,
            statusCode: error.response.status,
            message: error.response.data?.message || error.message,
            error: error.response.data
          };
        }
        
        return {
          success: false,
          message: error.message,
          error
        };
      }
    }
  • Helper function used by bank-search to format error responses in MCP-compatible format.
    export function formatErrorResponse(message: string) {
      return {
        content: [{ 
          type: "text" as const, 
          text: message 
        }],
        isError: true
      };
    }

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/guilhermelirio/brasil-api-mcp'

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