Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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."})

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/Bortlesboat/bitcoin-mcp'

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