Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

get_swap_price

Calculate token swap prices using aggregated DeFi liquidity across multiple blockchains for informed trading decisions.

Instructions

Get indicative price for a token swap using Aggregator Protocol

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chainIdYesBlockchain ID (e.g., 1 for Ethereum)
buyTokenYesContract address of token to buy
sellTokenYesContract address of token to sell
sellAmountYesAmount of sellToken in base units
takerNoAddress executing the trade (optional)

Implementation Reference

  • Primary MCP tool handler for 'get_swap_price': validates input parameters and delegates to AgService.getSwapPrice
    async getSwapPrice(params) { // Validate required parameters const { chainId, buyToken, sellToken, sellAmount } = params; if (!chainId || !buyToken || !sellToken || !sellAmount) { throw new Error( "Missing required parameters: chainId, buyToken, sellToken, sellAmount" ); } const result = await this.agg.getSwapPrice(params); return { message: "Swap price retrieved successfully", data: result, }; }
  • Core implementation of getSwapPrice: makes HTTP GET request to aggregator API endpoint /api/swap/price with query parameters
    async getSwapPrice(params) { try { const queryParams = new URLSearchParams(params); const response = await fetch(`${this.baseUrl}/api/swap/price?${queryParams}`); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); if (!data.success) { throw new Error(data.error || 'API request failed'); } return data.data; } catch (error) { throw new Error(`Failed to get swap price: ${error.message}`); }
  • src/index.js:984-985 (registration)
    MCP server registration: routes 'get_swap_price' tool calls to ToolService.getSwapPrice method
    case TOOL_NAMES.GET_SWAP_PRICE: result = await toolService.getSwapPrice(args);
  • Tool specification including name, description, and input schema validation for 'get_swap_price' in MCP ListTools response
    name: TOOL_NAMES.GET_SWAP_PRICE, description: "Get indicative price for a token swap using Aggregator Protocol", inputSchema: { type: "object", properties: { chainId: { type: "integer", description: "Blockchain ID (e.g., 1 for Ethereum)", }, buyToken: { type: "string", description: "Contract address of token to buy", }, sellToken: { type: "string", description: "Contract address of token to sell", }, sellAmount: { type: "string", description: "Amount of sellToken in base units", }, taker: { type: "string", description: "Address executing the trade (optional)", }, }, required: ["chainId", "buyToken", "sellToken", "sellAmount"], }, },
  • src/constants.js:4-4 (registration)
    Constant definition mapping TOOL_NAMES.GET_SWAP_PRICE to the tool name string 'get_swap_price' used throughout the codebase
    GET_SWAP_PRICE: "get_swap_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