Skip to main content
Glama
anirbanbasu

FrankfurterMCP

get_latest_exchange_rates

Retrieve current exchange rates for a base currency, with optional filtering for specific target currencies to support financial calculations and currency conversions.

Instructions

Returns the latest exchange rates for specific currencies.

The symbols can be used to filter the results to specific currencies. If symbols is 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.

Implementation Reference

  • Main async handler for the get_latest_exchange_rates tool. Includes input schema via Pydantic Annotated types and Field descriptions. Calls the helper function and wraps the response.
    async def get_latest_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, ): """Returns the latest exchange rates for specific currencies. The symbols can be used to filter the results to specific currencies. If symbols is not provided, all supported currencies will be returned. """ # Some LLMs make this mistake of passing just one currency but not as a list! if type(symbols) is str: symbols = [symbols] await ctx.info(f"Fetching latest exchange rates from Frankfurter API at {self.frankfurter_api_url}") cache_key = hashkey( self, base_currency=base_currency, symbols=tuple(symbols) if symbols else None, ) cache_hit = cache_key in ttl_cache result, http_response = self._get_latest_exchange_rates( base_currency=base_currency, symbols=tuple(symbols) if symbols else None, ) if cache_hit: await ctx.info("Latest exchange rates fetched from TTL cache.") return self.get_response_content(response=result, http_response=http_response, cached_response=cache_hit)
  • Registration of the tool in the FrankfurterMCP class tools list, specifying name, tags, and annotations.
    { "fn": "get_latest_exchange_rates", "tags": ["currency-rates", "exchange-rates"], "annotations": { "readOnlyHint": True, "openWorldHint": True, }, },
  • Internal cached helper function that fetches the latest exchange rates from the Frankfurter API using httpx.
    @cached( cache=ttl_cache, lock=threading.Lock(), key=hashkey, ) def _get_latest_exchange_rates( self, base_currency: str | None = None, symbols: tuple[str, ...] | None = None, ): """Internal function to get the latest 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) with self.get_httpx_client() as client: http_response = client.get( f"{self.frankfurter_api_url}/latest", 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 latest exchange rates from {self.frankfurter_api_url}. {e}")

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