get_currency_conversion
Convert currency amounts between ARS, BRL, MXN, USD and other currencies using MercadoLibre exchange rates for financial calculations.
Instructions
Convert between currencies using MercadoLibre exchange rates (ARS, BRL, MXN, USD, etc.).
Input Schema
TableJSON 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 getCurrencyConversion function that executes the currency conversion logic by calling the MercadoLibre API and calculating the 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 defining the input parameters for currency conversion (from, to, and optional amount)
export interface GetCurrencyConversionParams { from: string; to: string; amount?: number; } - src/mcp-server.ts:138-155 (registration)MCP server tool registration for get_currency_conversion with Zod schema validation and error handling
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-35 (registration)Tool export mapping get_currency_conversion to the getCurrencyConversion handler function
get_currency_conversion: (params: GetCurrencyConversionParams) => getCurrencyConversion(client, params),