convert
Convert Argentine pesos to any currency or dollar type, or vice versa, using real-time exchange rates. Choose between buy or sell rates for accurate conversion.
Instructions
Convert an amount between ARS and any currency or dollar type. At least one side must be ARS.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount to convert | |
| from | Yes | Source currency/dollar type (e.g. USD, blue, EUR, ARS) | |
| to | No | Target currency (default: ARS) | |
| use_buy | No | Use buy rate instead of sell rate (default: false) |
Implementation Reference
- src/actions.ts:44-93 (handler)The main convert function that handles currency conversion logic between ARS and any dollar type or foreign currency. It fetches the appropriate rate from the DolarApi API, then either divides (ARS -> other) or multiplies (other -> ARS) the amount.
export async function convert( client: DolarApiClient, params: ConvertParams ): Promise<unknown> { const fromUpper = params.from.toUpperCase(); const toUpper = (params.to ?? "ARS").toUpperCase(); // Determine which rate to fetch let rate: number; if (fromUpper === "ARS" || toUpper === "ARS") { // One side is ARS — fetch the other side's rate const nonArs = fromUpper === "ARS" ? toUpper : fromUpper; // Check if it's a dollar type (blue, oficial, etc.) or a currency (EUR, BRL) const dollarTypes = ["blue", "oficial", "bolsa", "contadoconliqui", "cripto", "mayorista", "tarjeta"]; const isDollarType = dollarTypes.includes(nonArs.toLowerCase()); if (isDollarType) { const data = await client.get<DollarRate>(`/v1/dolares/${nonArs.toLowerCase()}`); rate = params.use_buy ? data.compra : data.venta; } else { const data = await client.get<CurrencyRate>(`/v1/cotizaciones/${nonArs}`); rate = params.use_buy ? data.compra : data.venta; } // Convert if (fromUpper === "ARS") { // ARS → other: divide by rate return { from: fromUpper, to: nonArs, rate, amount: params.amount, converted: Number((params.amount / rate).toFixed(2)), }; } else { // other → ARS: multiply by rate return { from: nonArs, to: "ARS", rate, amount: params.amount, converted: Number((params.amount * rate).toFixed(2)), }; } } throw new Error("At least one side of the conversion must be ARS. Use 'from' or 'to' as ARS."); } - src/schemas.ts:9-14 (schema)TypeScript interface ConvertParams defining the input shape: amount (number), from (string), optional to (string, default ARS), and optional use_buy (boolean).
export interface ConvertParams { amount: number; from: string; to?: string; use_buy?: boolean; } - src/mcp-server.ts:77-95 (registration)MCP server tool registration for 'convert' using server.tool(), with Zod schema definitions for parameters and a handler that calls tools.convert().
server.tool( "convert", "Convert an amount between ARS and any currency or dollar type. At least one side must be ARS.", { amount: z.number().describe("Amount to convert"), from: z.string().describe("Source currency/dollar type (e.g. USD, blue, EUR, ARS)"), to: z.string().optional().describe("Target currency (default: ARS)"), use_buy: z.boolean().optional().describe("Use buy rate instead of sell rate (default: false)"), }, async (params) => { try { const result = await tools.convert(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: message }], isError: true }; } }, ); - src/index.ts:26-26 (helper)The 'convert' tool is wired up in the createDolarTools() factory function, wrapping the action with the client instance.
convert: (params: ConvertParams) => convert(client, params),