get_token_price
Retrieve token prices by contract addresses using the CoinGecko API, with options for market cap, 24hr volume, price change, and total reserve in USD.
Instructions
Get token prices by contract addresses using CoinGecko API
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| addresses | Yes | Token contract addresses, comma-separated for multiple tokens | |
| include_24hr_price_change | No | Include 24hr price change (optional) | |
| include_24hr_vol | No | Include 24hr volume (optional) | |
| include_market_cap | No | Include market capitalization (optional) | |
| include_total_reserve_in_usd | No | Include total reserve in USD (optional) | |
| mcap_fdv_fallback | No | Return FDV if market cap is not available (optional) | |
| network | Yes | Network ID (e.g., 'eth', 'bsc', 'polygon_pos') |
Input Schema (JSON Schema)
{
"properties": {
"addresses": {
"description": "Token contract addresses, comma-separated for multiple tokens",
"type": "string"
},
"include_24hr_price_change": {
"description": "Include 24hr price change (optional)",
"type": "boolean"
},
"include_24hr_vol": {
"description": "Include 24hr volume (optional)",
"type": "boolean"
},
"include_market_cap": {
"description": "Include market capitalization (optional)",
"type": "boolean"
},
"include_total_reserve_in_usd": {
"description": "Include total reserve in USD (optional)",
"type": "boolean"
},
"mcap_fdv_fallback": {
"description": "Return FDV if market cap is not available (optional)",
"type": "boolean"
},
"network": {
"description": "Network ID (e.g., 'eth', 'bsc', 'polygon_pos')",
"type": "string"
}
},
"required": [
"network",
"addresses"
],
"type": "object"
}
Implementation Reference
- src/index.js:197-236 (schema)MCP tool schema definition including input validation for get_token_pricename: TOOL_NAMES.GET_TOKEN_PRICE, description: "Get token prices by contract addresses using CoinGecko API", inputSchema: { type: "object", properties: { network: { type: "string", description: "Network ID (e.g., 'eth', 'bsc', 'polygon_pos')", }, addresses: { type: "string", description: "Token contract addresses, comma-separated for multiple tokens", }, include_market_cap: { type: "boolean", description: "Include market capitalization (optional)", }, mcap_fdv_fallback: { type: "boolean", description: "Return FDV if market cap is not available (optional)", }, include_24hr_vol: { type: "boolean", description: "Include 24hr volume (optional)", }, include_24hr_price_change: { type: "boolean", description: "Include 24hr price change (optional)", }, include_total_reserve_in_usd: { type: "boolean", description: "Include total reserve in USD (optional)", }, }, required: ["network", "addresses"], }, },
- src/index.js:1004-1012 (registration)Tool registration in MCP CallToolRequestHandler switch statement dispatching to toolService.getTokenPricecase TOOL_NAMES.GET_TOKEN_PRICE: result = await toolService.getTokenPrice(args.network, args.addresses, { include_market_cap: args.include_market_cap, mcap_fdv_fallback: args.mcap_fdv_fallback, include_24hr_vol: args.include_24hr_vol, include_24hr_price_change: args.include_24hr_price_change, include_total_reserve_in_usd: args.include_total_reserve_in_usd, }); break;
- src/toolService.js:136-154 (handler)Primary handler in ToolService that validates input, calls CoinGecko service, and formats MCP responseasync getTokenPrice(network, addresses, options = {}) { if (!network || !addresses) { throw new Error("Missing required parameters: network, addresses"); } const result = await this.coinGeckoApi.getTokenPrice( network, addresses, options ); return { message: "Token prices retrieved successfully", data: result, summary: `Retrieved prices for ${ addresses.split(",").length } token(s) on ${network} network`, }; }
- Core implementation handler performing HTTP fetch to CoinGecko API for token pricesasync getTokenPrice(network, addresses, options = {}) { try { const queryParams = new URLSearchParams(); // Add optional parameters if (options.include_market_cap) queryParams.append('include_market_cap', options.include_market_cap); if (options.mcap_fdv_fallback) queryParams.append('mcap_fdv_fallback', options.mcap_fdv_fallback); if (options.include_24hr_vol) queryParams.append('include_24hr_vol', options.include_24hr_vol); if (options.include_24hr_price_change) queryParams.append('include_24hr_price_change', options.include_24hr_price_change); if (options.include_total_reserve_in_usd) queryParams.append('include_total_reserve_in_usd', options.include_total_reserve_in_usd); const url = `${this.baseUrl}/simple/networks/${network}/token_price/${addresses}${queryParams.toString() ? '?' + queryParams.toString() : ''}`; const response = await fetch(url, { headers: { 'x-cg-demo-api-key': this.apiKey } }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return await response.json(); } catch (error) { throw new Error(`Failed to get token price: ${error.message}`); } }
- src/constants.js:19-19 (registration)Tool name constant definition used across the codebaseGET_TOKEN_PRICE: "get_token_price",