get_crypto_price
Retrieve current cryptocurrency prices using CoinGecko IDs to monitor market values and support trading decisions.
Instructions
Gets the current price of a cryptocurrency.
Args:
coin_id: CoinGecko ID (e.g., 'bitcoin', 'ethereum', 'solana')
vs_currency: Currency to compare against (default: 'usd')
Returns:
Dictionary with price information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coin_id | Yes | ||
| vs_currency | No | usd |
Implementation Reference
- tools/crypto_data.py:15-49 (handler)The handler function that implements the get_crypto_price tool. It queries the CoinGecko API for the current price, market cap, 24h volume, and change percentage for a given cryptocurrency ID against a specified currency.def get_crypto_price(coin_id: str, vs_currency: str = "usd") -> Dict[str, Any]: """ Gets the current price of a cryptocurrency. Args: coin_id: CoinGecko ID (e.g., 'bitcoin', 'ethereum', 'solana') vs_currency: Currency to compare against (default: 'usd') Returns: Dictionary with price information """ try: data = cg.get_price( ids=coin_id, vs_currencies=vs_currency, include_24hr_change=True, include_market_cap=True, include_24hr_vol=True ) if not data or coin_id not in data: return {"error": f"Coin '{coin_id}' not found"} coin_data = data[coin_id] return { "coin": coin_id, "price": coin_data.get(vs_currency, 0), "market_cap": coin_data.get(f"{vs_currency}_market_cap", 0), "24h_volume": coin_data.get(f"{vs_currency}_24h_vol", 0), "24h_change": coin_data.get(f"{vs_currency}_24h_change", 0), "currency": vs_currency.upper() } except Exception as e: logger.error(f"CoinGecko error for {coin_id}: {e}") return {"error": str(e)}
- server.py:415-418 (registration)Registration of the get_crypto_price tool (along with related crypto tools) to the MCP server using the register_tools helper, which applies the @mcp.tool() decorator.register_tools( [get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto], "Cryptocurrency" )
- app.py:295-302 (registration)Listing of get_crypto_price in the tools_map for the Gradio UI toolbox, importing from tools.crypto_data."Crypto": [ get_crypto_price, get_crypto_market_data, get_trending_crypto, search_crypto, get_crypto_resource, crypto_market_update, ],