Skip to main content
Glama

get_token_price

Retrieve the current price of a specific token on SailFish DEX by providing its token address, enabling accurate price tracking for EDUCHAIN interactions.

Instructions

Get the current price of a token on SailFish DEX

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tokenIdYesToken address

Implementation Reference

  • MCP tool handler for 'get_token_price': validates input, calls subgraph.getTokenPrice(tokenId), returns JSON with price or 'Unknown'.
    case 'get_token_price': {
      if (!args.tokenId || typeof args.tokenId !== 'string') {
        throw new McpError(ErrorCode.InvalidParams, 'Token ID is required');
      }
      
      const price = await subgraph.getTokenPrice(args.tokenId);
      
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({ price: price || 'Unknown' }, null, 2),
          },
        ],
      };
    }
  • Input schema definition for get_token_price tool: requires 'tokenId' string (token address).
    {
      name: 'get_token_price',
      description: 'Get the current price of a token on SailFish DEX',
      inputSchema: {
        type: 'object',
        properties: {
          tokenId: {
            type: 'string',
            description: 'Token address',
          },
        },
        required: ['tokenId'],
      },
    },
  • src/index.ts:173-712 (registration)
    Tool registration via setRequestHandler for ListToolsRequestSchema (lists tools with schemas) and CallToolRequestSchema (handles execution).
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'get_token_price',
          description: 'Get the current price of a token on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              tokenId: {
                type: 'string',
                description: 'Token address',
              },
            },
            required: ['tokenId'],
          },
        },
        {
          name: 'get_token_info',
          description: 'Get detailed information about a token on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              tokenId: {
                type: 'string',
                description: 'Token address',
              },
            },
            required: ['tokenId'],
          },
        },
        {
          name: 'get_pool_info',
          description: 'Get detailed information about a liquidity pool on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              poolId: {
                type: 'string',
                description: 'Pool address',
              },
            },
            required: ['poolId'],
          },
        },
        {
          name: 'get_top_tokens',
          description: 'Get a list of top tokens by TVL on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              count: {
                type: 'number',
                description: 'Number of tokens to return (default: 10)',
              },
            },
            required: [],
          },
        },
        {
          name: 'get_top_pools',
          description: 'Get a list of top liquidity pools by TVL on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              count: {
                type: 'number',
                description: 'Number of pools to return (default: 10)',
              },
            },
            required: [],
          },
        },
        {
          name: 'get_total_tvl',
          description: 'Get the total value locked (TVL) in SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {},
            required: [],
          },
        },
        {
          name: 'get_24h_volume',
          description: 'Get the 24-hour trading volume on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {},
            required: [],
          },
        },
        {
          name: 'get_token_historical_data',
          description: 'Get historical data for a token on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              tokenId: {
                type: 'string',
                description: 'Token address',
              },
              days: {
                type: 'number',
                description: 'Number of days of data to return (default: 7)',
              },
            },
            required: ['tokenId'],
          },
        },
        {
          name: 'get_pool_historical_data',
          description: 'Get historical data for a liquidity pool on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              poolId: {
                type: 'string',
                description: 'Pool address',
              },
              days: {
                type: 'number',
                description: 'Number of days of data to return (default: 7)',
              },
            },
            required: ['poolId'],
          },
        },
        {
          name: 'get_edu_balance',
          description: 'Get the EDU balance of a wallet address',
          inputSchema: {
            type: 'object',
            properties: {
              walletAddress: {
                type: 'string',
                description: 'Wallet address to check',
              },
            },
            required: ['walletAddress'],
          },
        },
        {
          name: 'get_token_balance',
          description: 'Get the token balance of a wallet address with USD value using SailFish as price oracle',
          inputSchema: {
            type: 'object',
            properties: {
              tokenAddress: {
                type: 'string',
                description: 'Token contract address',
              },
              walletAddress: {
                type: 'string',
                description: 'Wallet address to check',
              },
            },
            required: ['tokenAddress', 'walletAddress'],
          },
        },
        {
          name: 'get_multiple_token_balances',
          description: 'Get multiple token balances for a wallet address with USD values using SailFish as price oracle',
          inputSchema: {
            type: 'object',
            properties: {
              tokenAddresses: {
                type: 'array',
                items: {
                  type: 'string',
                },
                description: 'List of token contract addresses',
              },
              walletAddress: {
                type: 'string',
                description: 'Wallet address to check',
              },
            },
            required: ['tokenAddresses', 'walletAddress'],
          },
        },
        {
          name: 'get_nft_balance',
          description: 'Get the NFT balance of a wallet address for a specific NFT collection',
          inputSchema: {
            type: 'object',
            properties: {
              nftAddress: {
                type: 'string',
                description: 'NFT contract address',
              },
              walletAddress: {
                type: 'string',
                description: 'Wallet address to check',
              },
              fetchTokenIds: {
                type: 'boolean',
                description: 'Whether to fetch token IDs (default: true)',
              },
            },
            required: ['nftAddress', 'walletAddress'],
          },
        },
        {
          name: 'get_wallet_overview',
          description: 'Get an overview of a wallet including EDU, tokens, and NFTs',
          inputSchema: {
            type: 'object',
            properties: {
              walletAddress: {
                type: 'string',
                description: 'Wallet address to check',
              },
              tokenAddresses: {
                type: 'array',
                items: {
                  type: 'string',
                },
                description: 'List of token contract addresses to check',
              },
              nftAddresses: {
                type: 'array',
                items: {
                  type: 'string',
                },
                description: 'List of NFT contract addresses to check',
              },
            },
            required: ['walletAddress'],
          },
        },
        {
          name: 'set_rpc_url',
          description: 'Set the RPC URL for blockchain interactions',
          inputSchema: {
            type: 'object',
            properties: {
              url: {
                type: 'string',
                description: 'RPC URL to use for blockchain interactions',
              },
            },
            required: ['url'],
          },
        },
        {
          name: 'get_rpc_url',
          description: 'Get the current RPC URL used for blockchain interactions',
          inputSchema: {
            type: 'object',
            properties: {},
            required: [],
          },
        },
        {
          name: 'send_edu',
          description: 'Send EDU native token to another wallet address',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the sender wallet',
              },
              toAddress: {
                type: 'string',
                description: 'Recipient wallet address',
              },
              amount: {
                type: 'string',
                description: 'Amount of EDU to send',
              },
            },
            required: ['privateKey', 'toAddress', 'amount'],
          },
        },
        {
          name: 'get_wallet_address_from_private_key',
          description: 'Get wallet address from private key with proper checksum formatting',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the wallet',
              },
            },
            required: ['privateKey'],
          },
        },
        {
          name: 'send_erc20_token',
          description: 'Send ERC20 token to another wallet address',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the sender wallet',
              },
              tokenAddress: {
                type: 'string',
                description: 'Token contract address',
              },
              toAddress: {
                type: 'string',
                description: 'Recipient wallet address',
              },
              amount: {
                type: 'string',
                description: 'Amount of tokens to send',
              },
              confirm: {
                type: 'boolean',
                description: 'Confirm the transaction after verifying wallet address (default: true)',
              },
            },
            required: ['privateKey', 'tokenAddress', 'toAddress', 'amount'],
          },
        },
        {
          name: 'get_swap_quote',
          description: 'Get a quote for swapping tokens on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              tokenIn: {
                type: 'string',
                description: 'Address of the input token',
              },
              tokenOut: {
                type: 'string',
                description: 'Address of the output token',
              },
              amountIn: {
                type: 'string',
                description: 'Amount of input token to swap',
              },
              fee: {
                type: 'number',
                description: 'Fee tier (100=0.01%, 500=0.05%, 3000=0.3%, 10000=1%)',
              },
            },
            required: ['tokenIn', 'tokenOut', 'amountIn'],
          },
        },
        {
          name: 'swap_tokens',
          description: 'Swap tokens on SailFish DEX (token to token)',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the sender wallet',
              },
              tokenIn: {
                type: 'string',
                description: 'Address of the input token',
              },
              tokenOut: {
                type: 'string',
                description: 'Address of the output token',
              },
              amountIn: {
                type: 'string',
                description: 'Amount of input token to swap',
              },
              slippagePercentage: {
                type: 'number',
                description: 'Slippage tolerance percentage (default: 0.5)',
              },
              fee: {
                type: 'number',
                description: 'Fee tier (100=0.01%, 500=0.05%, 3000=0.3%, 10000=1%)',
              },
            },
            required: ['privateKey', 'tokenIn', 'tokenOut', 'amountIn'],
          },
        },
        {
          name: 'swap_edu_for_tokens',
          description: 'Swap EDU for tokens on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the sender wallet',
              },
              tokenOut: {
                type: 'string',
                description: 'Address of the output token',
              },
              amountIn: {
                type: 'string',
                description: 'Amount of EDU to swap',
              },
              slippagePercentage: {
                type: 'number',
                description: 'Slippage tolerance percentage (default: 0.5)',
              },
              fee: {
                type: 'number',
                description: 'Fee tier (100=0.01%, 500=0.05%, 3000=0.3%, 10000=1%)',
              },
            },
            required: ['privateKey', 'tokenOut', 'amountIn'],
          },
        },
        {
          name: 'swap_tokens_for_edu',
          description: 'Swap tokens for EDU on SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the sender wallet',
              },
              tokenIn: {
                type: 'string',
                description: 'Address of the input token',
              },
              amountIn: {
                type: 'string',
                description: 'Amount of tokens to swap',
              },
              slippagePercentage: {
                type: 'number',
                description: 'Slippage tolerance percentage (default: 0.5)',
              },
              fee: {
                type: 'number',
                description: 'Fee tier (100=0.01%, 500=0.05%, 3000=0.3%, 10000=1%)',
              },
            },
            required: ['privateKey', 'tokenIn', 'amountIn'],
          },
        },
        {
          name: 'get_external_market_data',
          description: 'Get external market data for EDU from centralized exchanges',
          inputSchema: {
            type: 'object',
            properties: {},
            required: [],
          },
        },
        {
          name: 'check_arbitrage_opportunities',
          description: 'Check for arbitrage opportunities between centralized exchanges and SailFish DEX',
          inputSchema: {
            type: 'object',
            properties: {
              threshold: {
                type: 'number',
                description: 'Minimum price difference percentage to consider as an arbitrage opportunity (default: 1.0)',
              },
            },
            required: [],
          },
        },
        {
          name: 'update_external_market_config',
          description: 'Update the configuration for external market data API',
          inputSchema: {
            type: 'object',
            properties: {
              apiUrl: {
                type: 'string',
                description: 'API URL for external market data',
              },
              apiKey: {
                type: 'string',
                description: 'API key for external market data (if required)',
              },
              symbols: {
                type: 'object',
                properties: {
                  EDU: {
                    type: 'string',
                    description: 'Symbol for EDU token on the external API',
                  },
                  USD: {
                    type: 'string',
                    description: 'Symbol for USD on the external API',
                  },
                },
                description: 'Symbol mappings for the external API',
              },
            },
            required: [],
          },
        },
        {
          name: 'get_external_market_config',
          description: 'Get the current configuration for external market data API',
          inputSchema: {
            type: 'object',
            properties: {},
            required: [],
          },
        },
        {
          name: 'wrap_edu',
          description: 'Wrap EDU to WEDU (Wrapped EDU)',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the wallet',
              },
              amount: {
                type: 'string',
                description: 'Amount of EDU to wrap',
              },
            },
            required: ['privateKey', 'amount'],
          },
        },
        {
          name: 'unwrap_wedu',
          description: 'Unwrap WEDU (Wrapped EDU) to EDU',
          inputSchema: {
            type: 'object',
            properties: {
              privateKey: {
                type: 'string',
                description: 'Private key of the wallet',
              },
              amount: {
                type: 'string',
                description: 'Amount of WEDU to unwrap',
              },
            },
            required: ['privateKey', 'amount'],
          },
        },
      ],
    }));
  • Core helper function getTokenPrice: fetches token data, ETH price from subgraph, computes USD price as derivedETH * ethPriceUSD.
    export async function getTokenPrice(tokenId: string): Promise<string | null> {
      try {
        const token = await getToken(tokenId);
        if (!token) {
          return null;
        }
        
        const ethPrice = await getEthPrice();
        if (!ethPrice) {
          return null;
        }
        
        // Calculate USD price from ETH price
        const priceUSD = parseFloat(token.derivedETH) * parseFloat(ethPrice);
        return priceUSD.toString();
      } catch (error) {
        console.error('Error calculating token price:', error);
        throw error;
      }
    }

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/SailFish-Finance/educhain-ai-agent-kit'

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