index.ts•1.82 kB
import { z } from "zod";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { getBrasilApiData, formatErrorResponse } from "../../utils/api.js";
/**
* Register bank related tools to the MCP server
* @param server MCP Server instance
*/
export function registerBankTools(server: McpServer) {
// Tool to find a bank by its code
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}
`
}]
};
}
);
// Tool to list all banks
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}`
}]
};
}
);
}