market_cap
Retrieve top cryptocurrencies by market cap, including current prices, trading volumes, and 24-hour percentage changes.
Instructions
Get top cryptocurrencies ranked by market cap with prices, volumes, and 24h changes.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "market_cap"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of coins to return (default: 20, max: 100) |
Implementation Reference
- index.js:122-135 (handler)The main handler function `getMarketCap(limit)` that fetches top coins by market cap from CoinGecko API and returns an array of ranked coin data (rank, symbol, name, price, market_cap, volume_24h, change_24h).
async function getMarketCap(limit = 20) { const data = await fetch( `https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=${limit}&page=1&sparkline=false` ); return data.map((c, i) => ({ rank: i + 1, symbol: c.symbol.toUpperCase(), name: c.name, price: c.current_price, market_cap: c.market_cap, volume_24h: c.total_volume, change_24h: c.price_change_percentage_24h, })); } - index.js:272-281 (schema)Tool definition for 'market_cap' including its name, description, and inputSchema (accepts optional 'limit' parameter, default 20, max 100).
{ name: 'market_cap', description: 'Get top cryptocurrencies ranked by market cap with prices, volumes, and 24h changes.', inputSchema: { type: 'object', properties: { limit: { type: 'number', description: 'Number of coins to return (default: 20, max: 100)' } } } }, - index.js:329-330 (registration)Handler dispatch in `handleToolCall` — routes the 'market_cap' case to `getMarketCap`, clamping limit to max 100.
case 'market_cap': return await getMarketCap(Math.min(args.limit || 20, 100)); - index.js:31-44 (helper)The `fetch(url)` helper function used by `getMarketCap` to make HTTPS requests to the CoinGecko API.
function fetch(url) { return new Promise((resolve, reject) => { const req = https.get(url, { headers: { 'User-Agent': 'mcp-market-data/0.1' } }, (res) => { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => { try { resolve(JSON.parse(data)); } catch (e) { reject(new Error(`Parse error: ${data.slice(0, 200)}`)); } }); }); req.on('error', reject); req.setTimeout(15000, () => { req.destroy(); reject(new Error('Timeout')); }); }); }