get_btc_price
Retrieve current Bitcoin price in USD to calculate transaction fees in dollar amounts. Provides price, 24-hour change, and market cap data from CoinGecko without requiring an API key.
Instructions
Get current BTC/USD price from CoinGecko (free, no API key). Returns price, 24h change, and market cap. Use this to convert sat/vB fees into dollar amounts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/bitcoin_mcp/server.py:940-956 (handler)The implementation of the get_btc_price tool, which fetches the current BTC/USD price from CoinGecko.
def get_btc_price() -> str: """Get current BTC/USD price from CoinGecko (free, no API key). Returns price, 24h change, and market cap. Use this to convert sat/vB fees into dollar amounts.""" try: url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd&include_24hr_change=true&include_market_cap=true" req = urllib.request.Request(url, headers={"User-Agent": "bitcoin-mcp"}) with urllib.request.urlopen(req, timeout=10) as resp: data = json.loads(resp.read(1_000_000)) btc = data.get("bitcoin", {}) return json.dumps({ "usd": btc.get("usd"), "usd_24h_change_pct": round(btc.get("usd_24h_change", 0), 2), "usd_market_cap": btc.get("usd_market_cap"), "source": "coingecko", }) except Exception as e: return json.dumps({"error": f"Price fetch failed: {e}", "hint": "CoinGecko may be rate-limiting. Try again in 30 seconds."})