finance_forex_rate
Retrieve current exchange rates between currencies to calculate conversion amounts for financial planning or transactions.
Instructions
Get current exchange rate between two currencies
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from | No | Source currency code | USD |
| to | No | Target currency code | BRL |
| amount | No | Amount to convert |
Implementation Reference
- src/modules/finance.ts:21-34 (handler)Implementation of the finance_forex_rate tool handler and schema.
server.tool("finance_forex_rate", "Get current exchange rate between two currencies", { from: z.string().default("USD").describe("Source currency code"), to: z.string().default("BRL").describe("Target currency code"), amount: z.number().default(1).describe("Amount to convert") }, async ({ from, to, amount }) => { try { const data = await safeFetch(`https://api.exchangerate-api.com/v4/latest/${from.toUpperCase()}`); const rate = data.rates[to.toUpperCase()]; if (!rate) return { content: [{ type: "text", text: `Currency "${to}" not found` }] }; return { content: [{ type: "text", text: `**${from.toUpperCase()} → ${to.toUpperCase()}**\nRate: 1 ${from} = ${rate.toFixed(4)} ${to}\nAmount: ${amount} ${from} = ${(amount * rate).toFixed(2)} ${to}\nUpdated: ${data.date}` }] }; } catch { return { content: [{ type: "text", text: `Could not fetch rate for ${from}/${to}` }] }; } });