bank-list
Retrieve a comprehensive list of Brazilian banks through the Brasil API MCP server, enabling access to banking institution data for integration and reference purposes.
Instructions
List all Brazilian banks
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/bank/index.ts:49-70 (handler)The handler function for the bank-list tool. Fetches the list of Brazilian banks from BrasilAPI, formats as a list, handles errors, and returns text content.
async () => { console.error("Listing all banks"); const result = await getBrasilApiData(`/banks/v1`); if (!result.success) { return formatErrorResponse(`Error listing banks: ${result.message}`); } // Format the response data const banks = result.data; const formattedBanks = banks.map((bank: any) => `${bank.code} - ${bank.name} (${bank.ispb})` ).join("\n"); return { content: [{ type: "text" as const, text: `Banks in Brazil:\n${formattedBanks}` }] }; } - src/tools/bank/index.ts:45-71 (registration)Registers the 'bank-list' tool to the MCP server with description, empty input schema {}, and handler function.
server.tool( "bank-list", "List all Brazilian banks", {}, async () => { console.error("Listing all banks"); const result = await getBrasilApiData(`/banks/v1`); if (!result.success) { return formatErrorResponse(`Error listing banks: ${result.message}`); } // Format the response data const banks = result.data; const formattedBanks = banks.map((bank: any) => `${bank.code} - ${bank.name} (${bank.ispb})` ).join("\n"); return { content: [{ type: "text" as const, text: `Banks in Brazil:\n${formattedBanks}` }] }; } ); - src/index.ts:27-27 (registration)Invokes registerBankTools to add bank tools (incl. bank-list) to the main MCP server instance.
registerBankTools(server); - src/utils/api.ts:11-40 (helper)API client helper function used to fetch bank list data from BrasilAPI.
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 }; } } - src/utils/api.ts:47-55 (helper)Utility to format error responses consistently in MCP format.
export function formatErrorResponse(message: string) { return { content: [{ type: "text" as const, text: message }], isError: true }; }