Skip to main content
Glama
anirbanbasu

FrankfurterMCP

get_historical_exchange_rates

Read-only

Retrieve historical currency exchange rates for a specific date or date range. Filters by target currencies and falls back to nearest available date if exact date is unavailable.

Instructions

Returns historical exchange rates for a specific date or date range.

If the exchange rates for a specified date is not available, the rates available for the closest date before the specified date will be provided. Either a specific date, a start date, or a date range must be provided. The symbols can be used to filter the results to specific currencies. If symbols are not provided, all supported currencies will be returned.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_currencyYesA base currency ISO4217 code for which rates are to be requested.
symbolsNoA list of target currency ISO4217 codes for which rates against the base currency will be provided. If not provided, all supported currencies will be shown.
specific_dateNoThe specific date for which the historical rates are requested in the YYYY-MM-DD format.
start_dateNoThe start date, of a date range, for which the historical rates are requested in the YYYY-MM-DD format.
end_dateNoThe end date, of a date range, for which the historical rates are requested in the YYYY-MM-DD format.

Implementation Reference

  • Main async handler for the get_historical_exchange_rates tool. Accepts base_currency, optional symbols, and either specific_date, start_date, or a date range (start_date + end_date). Calls the cached internal helper _get_historical_exchange_rates and wraps the result with response metadata.
    async def get_historical_exchange_rates(
        self,
        ctx: Context,
        base_currency: Annotated[
            ISO4217,
            Field(description="A base currency ISO4217 code for which rates are to be requested."),
        ],
        symbols: Annotated[
            list[ISO4217] | ISO4217 | None,
            Field(
                description="A list of target currency ISO4217 codes for which rates against the base currency will be provided. If not provided, all supported currencies will be shown."
            ),
        ] = None,
        specific_date: Annotated[
            date | None,
            Field(
                default=None,
                description="The specific date for which the historical rates are requested in the YYYY-MM-DD format.",
            ),
        ] = None,
        start_date: Annotated[
            date | None,
            Field(
                default=None,
                description="The start date, of a date range, for which the historical rates are requested in the YYYY-MM-DD format.",
            ),
        ] = None,
        end_date: Annotated[
            date | None,
            Field(
                default=None,
                description="The end date, of a date range, for which the historical rates are requested in the YYYY-MM-DD format.",
            ),
        ] = None,
    ):
        """Returns historical exchange rates for a specific date or date range.
    
        If the exchange rates for a specified date is not available, the rates available for
        the closest date before the specified date will be provided.
        Either a specific date, a start date, or a date range must be provided.
        The symbols can be used to filter the results to specific currencies.
        If symbols are not provided, all supported currencies will be returned.
        """
        await ctx.info(f"Fetching historical exchange rates from Frankfurter API at {self.frankfurter_api_url}")
        # Some LLMs make this mistake of passing just one currency but not as a list!
        if type(symbols) is str:
            symbols = [symbols]
        cache_key = hashkey(
            self,
            specific_date=specific_date.isoformat() if specific_date else None,
            start_date=start_date.isoformat() if start_date else None,
            end_date=end_date.isoformat() if end_date else None,
            base_currency=base_currency,
            symbols=tuple(symbols) if symbols else None,
        )
        cache_hit = cache_key in lru_cache
        result, http_response = self._get_historical_exchange_rates(
            specific_date=specific_date.isoformat() if specific_date else None,
            start_date=start_date.isoformat() if start_date else None,
            end_date=end_date.isoformat() if end_date else None,
            base_currency=base_currency,
            symbols=tuple(symbols) if symbols else None,
        )
        if cache_hit:
            await ctx.info(
                f"Historical exchange rates fetched for {len(result.get('rates', []))} dates from least-recently used (LRU) cache."
            )
        else:
            await ctx.info(f"Historical exchange rates fetched for {len(result.get('rates', []))} dates.")
        return self.get_response_content(response=result, http_response=http_response, cached_response=cache_hit)
  • Internal cached helper that builds the Frankfurter API URL with date range (start_date..end_date, start_date.., or /specific_date), adds optional base_currency and symbols query params, performs the HTTP GET request, and returns the JSON result along with the HTTP response.
    @cached(cache=lru_cache, lock=threading.Lock(), key=hashkey)
    def _get_historical_exchange_rates(
        self,
        specific_date: str | None = None,
        start_date: str | None = None,
        end_date: str | None = None,
        base_currency: str | None = None,
        symbols: tuple[str, ...] | None = None,
    ):
        """Internal function to get historical exchange rates. This is a helper function for the main tool."""
        try:
            params = {}
            if base_currency:
                params["base"] = base_currency
            if symbols:
                params["symbols"] = ",".join(symbols)
    
            frankfurter_url = self.frankfurter_api_url
            if start_date and end_date:
                frankfurter_url += f"/{start_date}..{end_date}"
            elif start_date:
                # If only start_date is provided, we assume the end date is the latest available date
                frankfurter_url += f"/{start_date}.."
            elif specific_date:
                # If only specific_date is provided, we assume it is the date for which we want the rates
                frankfurter_url += f"/{specific_date}"
            else:
                raise ValueError("You must provide either a specific date, a start date, or a date range.")
    
            with self.get_httpx_client() as client:
                http_response = client.get(
                    frankfurter_url,
                    params=params,
                )
                http_response.raise_for_status()
                result = http_response.json()
                return result, http_response
        except httpx.RequestError as e:
            raise ValueError(f"Failed to fetch historical exchange rates from {self.frankfurter_api_url}. {e}")
  • Registration metadata for the get_historical_exchange_rates tool in the FrankfurterMCP.tools class variable. The MCPMixin.register_features method uses this list to dynamically register each tool with the FastMCP instance.
    {
        "fn": "get_historical_exchange_rates",
        "tags": ["currency-rates", "historical-exchange-rates"],
        "annotations": {
            "readOnlyHint": True,
            "openWorldHint": True,
        },
    },
Behavior5/5

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

Description adds value beyond readOnlyHint annotation by detailing the fallback behavior (closest date before specified date) and the optional filtering via symbols. No contradictions with annotations.

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?

Three sentences covering purpose, fallback, and parameter requirements. No redundancy, efficiently organized.

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?

Account for 5 parameters and no output schema; description explains behavior but lacks details on return format or structure. Still adequate for selecting and invoking the tool.

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?

Schema description coverage is 100%, so the schema already documents each parameter. The description adds high-level context but does not introduce new semantics beyond reiterating filtering and date constraints.

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 it returns historical exchange rates for a specific date or date range, using a specific verb and resource. It distinguishes from sibling tools like get_latest_exchange_rates and convert_* functions.

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?

It explains when the tool provides fallback rates and the required parameter combinations (specific date, start date, or date range). However, it does not explicitly contrast with sibling tools or state when not to use it.

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/anirbanbasu/frankfurtermcp'

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