Skip to main content
Glama
dan1d

dolar-mcp

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
NameRequiredDescriptionDefault
type_aYesFirst dollar type (e.g. oficial)
type_bYesSecond dollar type (e.g. blue)

Implementation Reference

  • 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)),
      };
    }
  • 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),
        },
      };
    }
  • 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 };
        }
      },
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dan1d/dolar-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server