Skip to main content
Glama
julie-berlin

Tavily Web Search MCP Server

by julie-berlin

get_exchange_rate

Retrieve current exchange rates from a specified base currency to all supported currencies using ISO 4217 currency codes.

Instructions

Get the latest exchange rates from provided base currency code (ISO 4217) to all other supported currencies

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
currency_codeYes

Implementation Reference

  • server.py:29-33 (handler)
    The tool handler for 'get_exchange_rate', decorated with @mcp.tool() for automatic registration, including input schema via type hints and docstring, and core logic delegating to the ExchangeRateClient helper.
    @mcp.tool() async def get_exchange_rate(currency_code: str) -> str: """Get the latest exchange rates from provided base currency code (ISO 4217) to all other supported currencies""" exchange_rates = exchange_rate_client.get_rates(code=currency_code) return exchange_rates
  • Supporting ExchangeRateClient class with get_rates method that performs the actual API call, error handling, and JSON formatting for exchange rates.
    class ExchangeRateClient: def __init__(self, api_key: str): self.api_key = api_key self.base_url = "https://v6.exchangerate-api.com/v6" def get_rates(self, code: str) -> str: """Get latest exchange rates for the specified base currency code""" if not self.api_key: raise ValueError("API key is required") url = f"{self.base_url}/{self.api_key}/latest/{code.upper()}" try: response = requests.get(url) response.raise_for_status() data = response.json() if data.get("result") == "success": rates = data.get("conversion_rates", {}) base_code = data.get("base_code") last_update = data.get("time_last_update_utc") result = { "base_currency": base_code, "last_updated": last_update, "exchange_rates": rates } return json.dumps(result, indent=2) else: error_type = data.get("error-type", "unknown") return f"Error: {error_type}" except requests.exceptions.RequestException as e: return f"Network error: {str(e)}" except json.JSONDecodeError: return "Error: Invalid response format" except Exception as e: return f"Unexpected error: {str(e)}"
  • Global instantiation of the ExchangeRateClient helper instance used by the tool handler.
    exchange_rate_client = ExchangeRateClient(os.getenv("EXCHANGERATE_API_KEY"))
  • server.py:6-6 (helper)
    Import of the ExchangeRateClient helper module.
    from exchange_rates import ExchangeRateClient

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/julie-berlin/pub-aie7-mcp-session'

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