get_latest_exchange_rates
Retrieve current exchange rates for a base currency, optionally filtering specific target currencies using ISO codes.
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
| Name | Required | Description | Default |
|---|---|---|---|
| base_currency | Yes | A base currency ISO4217 code for which rates are to be requested. | |
| symbols | No | 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. |
Implementation Reference
- src/frankfurtermcp/server.py:168-203 (handler)The main async handler function for 'get_latest_exchange_rates' tool. Takes base_currency (ISO4217) and optional symbols parameters, handles cache lookups, calls the internal helper to fetch rates from Frankfurter API, and returns the response with metadata.
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) - src/frankfurtermcp/server.py:105-126 (helper)Internal helper function '_get_latest_exchange_rates' decorated with TTL cache. Makes HTTP GET request to Frankfurter API's /latest endpoint with optional base currency and symbols parameters.
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}") - src/frankfurtermcp/server.py:39-46 (registration)Tool registration metadata in the 'tools' class variable. Defines 'get_latest_exchange_rates' with tags ['currency-rates', 'exchange-rates'] and annotations for readOnlyHint and openWorldHint.
{ "fn": "get_latest_exchange_rates", "tags": ["currency-rates", "exchange-rates"], "annotations": { "readOnlyHint": True, "openWorldHint": True, }, }, - src/frankfurtermcp/mixin.py:46-53 (registration)The 'register_features' method in MCPMixin that iterates through tool metadata and registers each tool with FastMCP using mcp.tool() decorator.
# Register tools for tool in self.tools: assert "fn" in tool, "Tool metadata must include the 'fn' key." tool_copy = copy.deepcopy(tool) fn_name = tool_copy.pop("fn") fn = getattr(self, fn_name) mcp.tool(**tool_copy)(fn) logger.debug(f"Registered MCP tool: {fn_name}") - src/frankfurtermcp/server.py:171-180 (schema)Input schema definition for 'get_latest_exchange_rates' using Pydantic's Annotated with ISO4217 type and Field descriptions for base_currency (required) and symbols (optional list of target currencies).
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,