Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

get_token_price

Retrieve current token prices by contract address on supported networks, with optional market data like capitalization and volume for trading analysis.

Instructions

Get token prices by contract addresses using CoinGecko API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkYesNetwork ID (e.g., 'eth', 'bsc', 'polygon_pos')
addressesYesToken contract addresses, comma-separated for multiple tokens
include_market_capNoInclude market capitalization (optional)
mcap_fdv_fallbackNoReturn FDV if market cap is not available (optional)
include_24hr_volNoInclude 24hr volume (optional)
include_24hr_price_changeNoInclude 24hr price change (optional)
include_total_reserve_in_usdNoInclude total reserve in USD (optional)

Implementation Reference

  • Core handler function that fetches token prices from CoinGecko API by constructing the URL with network, addresses, and optional parameters, then makes HTTP request.
    async 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}`); } }
  • Input schema definition for the get_token_price tool, including properties for network, addresses, and various optional flags.
    name: 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)
    Registration and dispatch handler in the MCP CallToolRequestSchema switch case that calls toolService.getTokenPrice with parsed arguments.
    case 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;
  • ToolService wrapper handler that validates inputs, delegates to CoinGeckoApiService, and formats the response with message and summary.
    async 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`, }; }
  • Constant definition mapping the tool name constant to the string 'get_token_price' used throughout the codebase.
    GET_TOKEN_PRICE: "get_token_price",

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/edkdev/defi-trading-mcp'

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