Skip to main content
Glama
anirbanbasu

FrankfurterMCP

get_latest_exchange_rates

Retrieve current exchange rates for a base currency against target currencies. Filter results to specific currencies or get all supported currency rates.

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

  • The main asynchronous handler function for the 'get_latest_exchange_rates' tool. It handles input validation via Pydantic annotations, caching checks, calls the internal helper to fetch data from the Frankfurter API, and returns the response content.
    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)
  • The registration entry for the 'get_latest_exchange_rates' tool in the FastMCP class's tools list, including tags and annotations.
    { "fn": "get_latest_exchange_rates", "tags": ["currency-rates", "exchange-rates"], "annotations": { "readOnlyHint": True, "openWorldHint": True, }, },
  • The internal cached helper function that performs the actual HTTP request to the Frankfurter API to retrieve the latest exchange rates based on base currency and symbols.
    @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