Skip to main content
Glama

get_exchange_rate

Retrieve current CHF exchange rates from the Swiss National Bank for any currency using ISO 4217 codes. Provides monthly average rates and currency details.

Instructions

Get the current CHF exchange rate for a currency from the Swiss National Bank (SNB). Returns the latest monthly average rate and currency details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
currencyYesISO 4217 currency code (e.g. 'EUR', 'USD', 'GBP', 'JPY'). Use list_currencies to see all available codes.

Implementation Reference

  • The `handleGetExchangeRate` function performs the core logic for fetching and formatting exchange rate data from the SNB.
    async function handleGetExchangeRate(currency: string): Promise<string> {
      if (!currency?.trim()) {
        throw new Error("currency is required (e.g. 'EUR', 'USD', 'GBP')");
      }
    
      const [currencies, ratesMap] = await Promise.all([fetchDimensions(), fetchRatesMap()]);
    
      const info = findSeriesId(currency, currencies);
      if (!info) {
        const availableCodes = currencies.map((c) => c.code).join(", ");
        throw new Error(
          `Currency '${currency.toUpperCase()}' not found. Available currencies: ${availableCodes}`
        );
      }
    
      const entries = ratesMap.get(info.seriesId);
      if (!entries || entries.length === 0) {
        return JSON.stringify(
          {
            error: "No exchange rate data available",
            currency: currency.toUpperCase(),
            hint: "The SNB may not publish rates for this currency for recent periods.",
            source: "https://data.snb.ch",
          },
          null,
          2
        );
      }
    
      // Latest entry (CSV is in chronological order, last = most recent)
      const latest = entries[entries.length - 1];
    
      return JSON.stringify(
        {
          currency: info.code,
          currencyName: info.name,
          date: latest.date,
          rate: latest.rate,
          units: info.units,
          description:
            info.units === 100
              ? `1 CHF = ${(info.units / latest.rate).toFixed(4)} ${info.code} | 100 ${info.code} = ${latest.rate} CHF`
              : `1 ${info.code} = ${latest.rate} CHF`,
          note:
            info.units === 100
              ? `Rate is CHF per 100 ${info.code} (monthly average)`
              : `Rate is CHF per 1 ${info.code} (monthly average)`,
          source: "https://data.snb.ch",
        },
        null,
        2
      );
    }
  • Definition of the `get_exchange_rate` tool, including its input schema and description for MCP.
    {
      name: "get_exchange_rate",
      description:
        "Get the current CHF exchange rate for a currency from the Swiss National Bank (SNB). Returns the latest monthly average rate and currency details.",
      inputSchema: {
        type: "object" as const,
        required: ["currency"],
        properties: {
          currency: {
            type: "string",
            description: "ISO 4217 currency code (e.g. 'EUR', 'USD', 'GBP', 'JPY'). Use list_currencies to see all available codes.",
          },
        },
  • The switch case in the MCP tool handler routes the `get_exchange_rate` request to `handleGetExchangeRate`.
    case "get_exchange_rate":
      return handleGetExchangeRate(args.currency as string);
    case "get_exchange_rate_history":
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the data source (SNB) and return type ('latest monthly average rate and currency details'), but lacks details on rate limits, error handling, authentication needs, or whether it's a read-only operation. This is a significant gap for a tool with no annotation support.

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?

The description is front-loaded and concise, consisting of two efficient sentences that directly state the tool's function and return value. There is no wasted verbiage, making it easy to parse quickly.

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

Completeness3/5

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

Given the tool's low complexity (one parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose and return type but lacks behavioral details like error cases or performance characteristics. Without annotations or output schema, more context would improve completeness.

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

Parameters3/5

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

The input schema has 100% description coverage, with the 'currency' parameter well-documented in the schema. The description adds no additional parameter semantics beyond what the schema provides, such as format examples or constraints. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Get the current CHF exchange rate for a currency from the Swiss National Bank (SNB).' It specifies the verb ('Get'), resource ('CHF exchange rate'), and data source (SNB). However, it doesn't explicitly differentiate from its sibling 'get_exchange_rate_history', which handles historical rates versus current rates.

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

Usage Guidelines3/5

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

The description implies usage by specifying 'current' exchange rate and 'latest monthly average,' suggesting this is for real-time or recent data. It doesn't explicitly state when to use this versus 'get_exchange_rate_history' or other alternatives, nor does it mention prerequisites or exclusions, leaving some ambiguity.

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/vikramgorla/mcp-swiss'

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