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",
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden for behavioral disclosure. While it mentions the API source (CoinGecko), it doesn't describe rate limits, authentication requirements, error conditions, response format, or whether this is a read-only operation. For a tool with 7 parameters and no annotations, this is a significant gap in behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a straightforward data retrieval tool and front-loads the core purpose immediately. Every word earns its place by specifying what, how, and the data source.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (7 parameters, no output schema, no annotations), the description is insufficient. It doesn't explain what the tool returns, how results are formatted, error handling, rate limits, or when to use this versus other price-related tools. For a tool interacting with an external API and having multiple configuration options, more contextual information is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all parameters are documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema descriptions. The baseline score of 3 reflects that the schema does the heavy lifting for parameter documentation, though the description doesn't enhance understanding of parameter relationships or usage patterns.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get token prices') and the resource ('by contract addresses'), with the specific data source ('using CoinGecko API') mentioned. It distinguishes this from siblings like 'get_token_data' or 'get_token_info' by focusing specifically on price retrieval rather than broader token information. However, it doesn't explicitly differentiate from 'get_swap_price' which might also retrieve prices.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With many sibling tools like 'get_token_data', 'get_token_info', 'get_swap_price', and 'get_gasless_price', there's no indication of when this specific CoinGecko-based price tool is preferred. No context about prerequisites, limitations, or appropriate use cases is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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