get_bank_by_code
Retrieve bank details using a bank code. Provide the numeric code to access information about a specific Brazilian financial institution.
Instructions
Get information from a specific bank given its code. The code from each bank is returned by get_all_banks tool.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Implementation Reference
- src/tools/banks.ts:38-52 (handler)Implements the core logic of the 'get_bank_by_code' tool: fetches bank details from Brasil API using the provided code, formats as JSON, and returns as text content. Handles errors by throwing descriptive messages.handler: async ({ code }) => { try { const result = await brasilApiClient.bank.getBy(code); const content: McpTextContent = { type: "text", text: prettifyJson(result.data), }; return { content: [content], }; } catch (error: any) { console.error(error); throw new Error(`Failed to fetch bank with code ${code}`); } },
- src/tools/banks.ts:27-29 (schema)Defines the input schema using Zod: requires a 'code' parameter as a number.const GetBankByCodeToolParams = { code: z.number(), };
- src/index.ts:30-41 (registration)Includes getBankByCodeTool in the list of tools and registers all tools with the MCP server using registerTool.const tools = [ getCepTool, getCepV2Tool, getBookByISBNTool, getCNPJTool, getAllBanksTool, getBankByCodeTool, ]; tools.forEach((tool) => { registerTool(server, tool); });
- src/index.ts:10-10 (registration)Imports the getBankByCodeTool from src/tools/banks.ts for registration.import { getAllBanksTool, getBankByCodeTool } from "./tools/banks.js";
- src/tools/banks.ts:34-37 (schema)Tool metadata including name, description, and reference to params schema.name: "get_bank_by_code", description: "Get information from a specific bank given its code. The code from each bank is returned by get_all_banks tool.", params: GetBankByCodeToolParams,