Skip to main content
Glama

Brasil API MCP

index.ts2.69 kB
import { z } from "zod"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { getBrasilApiData, formatErrorResponse } from "../../utils/api.js"; /** * Register currency exchange (cambio) related tools to the MCP server * @param server MCP Server instance */ export function registerCambioTools(server: McpServer) { // Tool to list all available currencies server.tool( "cambio-currencies-list", "List all available currencies for exchange rates", {}, async () => { console.error("Listing all available currencies"); const result = await getBrasilApiData(`/cambio/v1/moedas`); if (!result.success) { return formatErrorResponse(`Error listing currencies: ${result.message}`); } // Format the response data const currencies = result.data; const formattedCurrencies = currencies.map((currency: any) => `${currency.simbolo} - ${currency.nome} (Type: ${currency.tipo_moeda})` ).join("\n"); return { content: [{ type: "text" as const, text: `Available Currencies:\n${formattedCurrencies}` }] }; } ); // Tool to get exchange rates for a specific currency on a specific date server.tool( "cambio-rate", "Get exchange rates for a specific currency on a specific date", { currency: z.string() .describe("Currency symbol (e.g., USD, EUR, GBP)"), date: z.string() .describe("Date in YYYY-MM-DD format. For weekends and holidays, the returned date will be the last available business day.") }, async ({ currency, date }) => { console.error(`Getting exchange rates for ${currency} on ${date}`); const result = await getBrasilApiData(`/cambio/v1/cotacao/${currency}/${date}`); if (!result.success) { return formatErrorResponse(`Error getting exchange rates: ${result.message}`); } // Format the response data const exchangeData = result.data; // Format the quotations const formattedQuotations = exchangeData.cotacoes.map((quotation: any) => `Time: ${quotation.data_hora_cotacao} - Type: ${quotation.tipo_boletim} Buy Rate: ${quotation.cotacao_compra} Sell Rate: ${quotation.cotacao_venda} Buy Parity: ${quotation.paridade_compra} Sell Parity: ${quotation.paridade_venda}` ).join("\n\n"); return { content: [{ type: "text" as const, text: ` Exchange Rate Information: Currency: ${exchangeData.moeda} Date: ${exchangeData.data} Quotations: ${formattedQuotations} ` }] }; } ); }

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