bank-search
Retrieve details about Brazilian banks using their unique code. The tool provides accurate bank information through the Brasil API MCP server, streamlining access to essential financial data.
Instructions
Find information about a Brazilian bank by its code
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Bank code to search for |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"code": {
"description": "Bank code to search for",
"type": "string"
}
},
"required": [
"code"
],
"type": "object"
}
Implementation Reference
- src/tools/bank/index.ts:18-41 (handler)The handler function that implements the core logic of the 'bank-search' tool: fetches Brazilian bank information by code from BrasilAPI, handles errors, and formats a text response.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} ` }] }; }
- src/tools/bank/index.ts:14-17 (schema)Zod input schema for the 'bank-search' tool, defining the required 'code' parameter as a string.{ code: z.string() .describe("Bank code to search for") },
- src/tools/bank/index.ts:11-42 (registration)Registers the 'bank-search' tool with the MCP server, specifying name, description, input schema, and handler function.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} ` }] }; } );
- src/index.ts:27-27 (registration)Calls registerBankTools on the main MCP server instance to register bank-related tools including 'bank-search'.registerBankTools(server);
- src/utils/api.ts:11-39 (helper)Utility function getBrasilApiData used by the 'bank-search' handler to fetch data from the BrasilAPI and handle API responses and errors.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 }; }