Skip to main content
Glama

cambio-rate

Retrieve precise currency exchange rates for a specific date using a currency symbol and date input, ensuring accurate financial data from the last available business day for weekends and holidays.

Instructions

Get exchange rates for a specific currency on a specific date

Input Schema

NameRequiredDescriptionDefault
currencyYesCurrency symbol (e.g., USD, EUR, GBP)
dateYesDate in YYYY-MM-DD format. For weekends and holidays, the returned date will be the last available business day.

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "currency": { "description": "Currency symbol (e.g., USD, EUR, GBP)", "type": "string" }, "date": { "description": "Date in YYYY-MM-DD format. For weekends and holidays, the returned date will be the last available business day.", "type": "string" } }, "required": [ "currency", "date" ], "type": "object" }

Implementation Reference

  • Handler function that fetches exchange rate data for a given currency and date from BrasilAPI, formats the quotations, and returns a formatted text response.
    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} ` }] }; }
  • Zod input schema for the tool, validating 'currency' and 'date' parameters.
    { 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.") },
  • MCP server tool registration for 'cambio-rate', including name, description, schema, and handler.
    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} ` }] }; } );
  • Helper function to make GET requests to BrasilAPI, returning structured data or error objects. Used by cambio-rate handler.
    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 }; } }
  • Helper function to format error messages into MCP-compatible responses. Used by cambio-rate handler.
    export function formatErrorResponse(message: string) { return { content: [{ type: "text" as const, text: message }], isError: true }; }

Latest Blog Posts

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