get_currency_conversion
Convert currencies using MercadoLibre exchange rates for ARS, BRL, MXN, USD, and other currencies. Input source, target, and optional amount to get the converted value.
Instructions
Convert between currencies using MercadoLibre exchange rates (ARS, BRL, MXN, USD, etc.).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from | Yes | Source currency code (e.g. USD) | |
| to | Yes | Target currency code (e.g. ARS) | |
| amount | No | Amount to convert (default: 1) |
Implementation Reference
- src/actions.ts:71-87 (handler)The actual handler function `getCurrencyConversion` that executes the currency conversion logic. It calls the MercadoLibre API at `/currency_conversions/search` with `from` and `to` parameters, then returns the conversion result including the rate, original amount, and converted amount.
export async function getCurrencyConversion( client: MercadoLibreClient, params: GetCurrencyConversionParams ): Promise<unknown> { const result = await client.get<{ ratio: number }>( `/currency_conversions/search`, { from: params.from, to: params.to } ); const amount = params.amount ?? 1; return { from: params.from, to: params.to, rate: result.ratio, amount, converted: Number((amount * result.ratio).toFixed(4)), }; } - src/schemas.ts:35-39 (schema)TypeScript interface `GetCurrencyConversionParams` defining the input parameters: `from` (source currency), `to` (target currency), and optional `amount`.
export interface GetCurrencyConversionParams { from: string; to: string; amount?: number; } - src/mcp-server.ts:138-155 (registration)Registration of the `get_currency_conversion` tool in the MCP server using `server.tool()`. It defines the Zod schema for params (from, to, amount) and the handler that delegates to `tools.get_currency_conversion`.
server.tool( "get_currency_conversion", "Convert between currencies using MercadoLibre exchange rates (ARS, BRL, MXN, USD, etc.).", { from: z.string().describe("Source currency code (e.g. USD)"), to: z.string().describe("Target currency code (e.g. ARS)"), amount: z.number().optional().describe("Amount to convert (default: 1)"), }, async (params) => { try { const result = await tools.get_currency_conversion(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:35-36 (registration)Tool registration in `createMercadoLibreTools`: maps the string key `get_currency_conversion` to a lambda that calls `getCurrencyConversion(client, params)`.
get_currency_conversion: (params: GetCurrencyConversionParams) => getCurrencyConversion(client, params), },