Skip to main content
Glama
UniRate-API

UniRate MCP

Official
by UniRate-API

Get latest exchange rate(s)

latest_rate
Read-only

Get the current exchange rate for a base currency. Optionally specify a target currency to return a single rate, or omit to receive rates for all supported currencies.

Instructions

Fetch the latest exchange rate for a base currency. If 'to' is provided, returns a single rate; otherwise returns rates for all supported currencies relative to the base.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromYesBase currency code, e.g. 'USD'
toNoOptional target currency. Omit to get rates for all currencies.

Implementation Reference

  • The handler function for the 'latest_rate' tool. Accepts 'from' (base currency) and optional 'to' (target currency). If 'to' is provided, calls client.getRate(from, to) for a single rate. Otherwise, calls client.getRates(from) for all rates and returns a preview of the first 10.
    async ({ from, to }) => {
      try {
        if (to) {
          const rate = await client.getRate(from, to);
          return ok(
            `1 ${from.toUpperCase()} = ${rate} ${to.toUpperCase()}`,
            { from: from.toUpperCase(), to: to.toUpperCase(), rate },
          );
        }
        const rates = await client.getRates(from);
        const preview = Object.entries(rates)
          .slice(0, 10)
          .map(([k, v]) => `${k}: ${v}`)
          .join(", ");
        const total = Object.keys(rates).length;
        return ok(
          `${total} rates for base ${from.toUpperCase()}. First 10: ${preview}.`,
          { base: from.toUpperCase(), rates },
        );
      } catch (err) {
        return fail(err);
      }
    },
  • Input schema for the 'latest_rate' tool. Defines 'from' (required, ISO 4217 currency code) and 'to' (optional target currency). Uses Zod for validation.
    {
      title: "Get latest exchange rate(s)",
      description:
        "Fetch the latest exchange rate for a base currency. If 'to' is provided, returns a single rate; " +
        "otherwise returns rates for all supported currencies relative to the base.",
      inputSchema: {
        from: z.string().min(3).max(10).describe("Base currency code, e.g. 'USD'"),
        to: z
          .string()
          .min(3)
          .max(10)
          .optional()
          .describe("Optional target currency. Omit to get rates for all currencies."),
      },
      annotations: { readOnlyHint: true, openWorldHint: true },
  • src/index.ts:73-114 (registration)
    Registration of the 'latest_rate' tool via server.registerTool() on the McpServer instance, binding the name, schema, annotations, and handler together.
    server.registerTool(
      "latest_rate",
      {
        title: "Get latest exchange rate(s)",
        description:
          "Fetch the latest exchange rate for a base currency. If 'to' is provided, returns a single rate; " +
          "otherwise returns rates for all supported currencies relative to the base.",
        inputSchema: {
          from: z.string().min(3).max(10).describe("Base currency code, e.g. 'USD'"),
          to: z
            .string()
            .min(3)
            .max(10)
            .optional()
            .describe("Optional target currency. Omit to get rates for all currencies."),
        },
        annotations: { readOnlyHint: true, openWorldHint: true },
      },
      async ({ from, to }) => {
        try {
          if (to) {
            const rate = await client.getRate(from, to);
            return ok(
              `1 ${from.toUpperCase()} = ${rate} ${to.toUpperCase()}`,
              { from: from.toUpperCase(), to: to.toUpperCase(), rate },
            );
          }
          const rates = await client.getRates(from);
          const preview = Object.entries(rates)
            .slice(0, 10)
            .map(([k, v]) => `${k}: ${v}`)
            .join(", ");
          const total = Object.keys(rates).length;
          return ok(
            `${total} rates for base ${from.toUpperCase()}. First 10: ${preview}.`,
            { base: from.toUpperCase(), rates },
          );
        } catch (err) {
          return fail(err);
        }
      },
    );
  • Client helper methods used by the latest_rate handler: getRate(from, to) returns a single rate, and getRates(from) returns all rates. Both call the /api/rates endpoint.
    async getRate(from: string, to: string): Promise<number> {
      const data = await this.request<{ rate: string }>("/api/rates", {
        from: from.toUpperCase(),
        to: to.toUpperCase(),
      });
      return parseFloat(data.rate);
    }
    
    async getRates(from: string): Promise<Record<string, number>> {
      const data = await this.request<{ rates: Record<string, string> }>("/api/rates", {
        from: from.toUpperCase(),
      });
      const out: Record<string, number> = {};
      for (const [k, v] of Object.entries(data.rates)) out[k] = parseFloat(v);
      return out;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already indicate readOnlyHint and openWorldHint. Description adds scoping (base currency, single/all rates) but doesn't elaborate on data freshness, caching, or external dependencies. Adequate given annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, front-loads the main action, no unnecessary words. Perfectly concise while conveying the two use cases.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given low complexity (2 params, no output schema), description is mostly complete. Could briefly mention return format (e.g., object with rates) but not essential. Agent can infer from typical usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema already describes both params clearly (100% coverage). Description adds value by explaining the behavioral switch when 'to' is omitted, which is not in the schema descriptions. Enhances understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'Fetch the latest exchange rate' with distinct behaviors: single rate if 'to' provided, all rates if omitted. Differentiates from siblings through scope (latest vs. historical, conversion, currency list).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Describes when to provide 'to' vs omit, but does not explicitly compare to sibling tools like convert or historical_rate. Agent can infer from sibling names, but no direct usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/UniRate-API/unirate-mcp'

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