get_spread
Calculate the spread between two Argentine dollar types like blue and oficial to compare exchange rates.
Instructions
Calculate the spread (difference) between two dollar types. E.g. blue vs oficial.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type_a | Yes | First dollar type (e.g. oficial) | |
| type_b | Yes | Second dollar type (e.g. blue) |
Implementation Reference
- src/actions.ts:95-113 (handler)The main handler function getSpread that implements the get_spread tool logic. It fetches two dollar rates in parallel, calculates the spread (difference in venta prices), and returns the spread in both absolute value and percentage.
export async function getSpread( client: DolarApiClient, params: GetSpreadParams ): Promise<unknown> { const [a, b] = await Promise.all([ client.get<DollarRate>(`/v1/dolares/${encodeURIComponent(params.type_a)}`), client.get<DollarRate>(`/v1/dolares/${encodeURIComponent(params.type_b)}`), ]); const spreadVenta = b.venta - a.venta; const spreadPercent = ((spreadVenta / a.venta) * 100); return { type_a: { name: a.nombre, venta: a.venta, compra: a.compra }, type_b: { name: b.nombre, venta: b.venta, compra: b.compra }, spread_venta: Number(spreadVenta.toFixed(2)), spread_percent: Number(spreadPercent.toFixed(2)), }; } - src/schemas.ts:16-19 (schema)TypeScript interface defining the input parameters for getSpread, requiring two dollar type names (type_a and type_b).
export interface GetSpreadParams { type_a: string; type_b: string; } - src/index.ts:17-30 (registration)Registration of get_spread tool in the createDolarTools function, which wraps the handler with the API client instance.
export function createDolarTools() { const client = new DolarApiClient(); return { tools: { get_all_dollars: () => getAllDollars(client), get_dollar: (params: GetDollarParams) => getDollar(client, params), get_all_currencies: () => getAllCurrencies(client), get_currency: (params: GetCurrencyParams) => getCurrency(client, params), convert: (params: ConvertParams) => convert(client, params), get_spread: (params: GetSpreadParams) => getSpread(client, params), }, }; } - src/mcp-server.ts:97-113 (registration)MCP server registration of get_spread tool with Zod schema validation, description, and error handling wrapper.
server.tool( "get_spread", "Calculate the spread (difference) between two dollar types. E.g. blue vs oficial.", { type_a: z.string().describe("First dollar type (e.g. oficial)"), type_b: z.string().describe("Second dollar type (e.g. blue)"), }, async (params) => { try { const result = await tools.get_spread(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 }; } }, );