Skip to main content
Glama

get_exchange_rate_history

Retrieve historical CHF exchange rate data from the Swiss National Bank for analysis, tracking, or reporting purposes. Access monthly average rates with optional date filtering capabilities.

Instructions

Get historical CHF exchange rates for a currency from the Swiss National Bank (SNB). Returns monthly average rates with optional date filtering. Without date range, returns the most recent 90 months.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
currencyYesISO 4217 currency code (e.g. 'EUR', 'USD', 'GBP'). Use list_currencies to see all available codes.
fromNoStart date in YYYY-MM format (e.g. '2020-01'). Optional.
toNoEnd date in YYYY-MM format (e.g. '2026-02'). Optional.

Implementation Reference

  • The handler function `handleGetExchangeRateHistory` that fetches and processes the SNB exchange rate history.
    async function handleGetExchangeRateHistory(
      currency: string,
      from?: string,
      to?: 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}`
        );
      }
    
      let entries = ratesMap.get(info.seriesId) ?? [];
    
      if (entries.length === 0) {
        return JSON.stringify(
          {
            error: "No historical data available",
            currency: currency.toUpperCase(),
            source: "https://data.snb.ch",
          },
          null,
          2
        );
      }
    
      // Filter by date range if provided (dates are "YYYY-MM" format)
      if (from) {
        entries = entries.filter((e) => e.date >= from);
      }
      if (to) {
        entries = entries.filter((e) => e.date <= to);
      }
    
      // If no date range provided, limit to most recent 90 entries
      if (!from && !to && entries.length > 90) {
        entries = entries.slice(-90);
      }
    
      if (entries.length === 0) {
        return JSON.stringify(
          {
            error: "No data in the specified date range",
            currency: currency.toUpperCase(),
            from: from ?? null,
            to: to ?? null,
            source: "https://data.snb.ch",
          },
          null,
          2
        );
      }
    
      // Compute simple stats
      const rates = entries.map((e) => e.rate);
      const minRate = Math.min(...rates);
      const maxRate = Math.max(...rates);
  • The tool schema definition for `get_exchange_rate_history` including name, description, and input parameters.
    {
      name: "get_exchange_rate_history",
      description:
        "Get historical CHF exchange rates for a currency from the Swiss National Bank (SNB). Returns monthly average rates with optional date filtering. Without date range, returns the most recent 90 months.",
      inputSchema: {
        type: "object" as const,
        required: ["currency"],
        properties: {
          currency: {
            type: "string",
            description: "ISO 4217 currency code (e.g. 'EUR', 'USD', 'GBP'). Use list_currencies to see all available codes.",
          },
          from: {
            type: "string",
            description: "Start date in YYYY-MM format (e.g. '2020-01'). Optional.",
          },
          to: {
            type: "string",
            description: "End date in YYYY-MM format (e.g. '2026-02'). Optional.",
          },
        },
      },
    },
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key traits: the tool returns monthly average rates, supports optional date filtering, and defaults to the most recent 90 months if no date range is given. This covers output format, default behavior, and optionality, though it lacks details on rate limits, error handling, or authentication needs.

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, with two sentences that efficiently convey the tool's purpose, output, and default behavior. Every sentence adds essential information without redundancy, making it easy to parse and understand quickly.

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 the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is largely complete. It covers purpose, usage context, and behavioral traits adequately. However, without an output schema, it could benefit from more details on return values (e.g., data structure or examples), slightly limiting completeness for an agent's invocation.

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, providing full details on parameters (currency, from, to). The description adds minimal value beyond the schema, only implying date filtering without specifying format or constraints. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description does not significantly enhance parameter 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?

The description clearly states the tool's purpose with specific verbs ('Get historical CHF exchange rates') and resources ('from the Swiss National Bank (SNB)'), distinguishing it from sibling tools like 'get_exchange_rate' (likely current rates) and 'list_currencies' (currency listing). It specifies the scope (monthly average rates) and data source, making the purpose unambiguous.

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?

The description provides clear context for usage: it mentions using 'list_currencies' to see available currency codes, which is an explicit prerequisite. However, it does not specify when to use this tool versus alternatives like 'get_exchange_rate' (e.g., for historical vs. current rates), nor does it outline any exclusions or constraints beyond date filtering.

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