Skip to main content
Glama

DeFi Trading Agent MCP Server

by edkdev

get_swap_price

Retrieve indicative token swap prices using Aggregator Protocol for efficient DeFi trading. Specify chain ID, buy/sell tokens, and sell amount to analyze trade opportunities across multiple blockchains.

Instructions

Get indicative price for a token swap using Aggregator Protocol

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "buyToken": { "description": "Contract address of token to buy", "type": "string" }, "chainId": { "description": "Blockchain ID (e.g., 1 for Ethereum)", "type": "integer" }, "sellAmount": { "description": "Amount of sellToken in base units", "type": "string" }, "sellToken": { "description": "Contract address of token to sell", "type": "string" }, "taker": { "description": "Address executing the trade (optional)", "type": "string" } }, "required": [ "chainId", "buyToken", "sellToken", "sellAmount" ], "type": "object" }

Implementation Reference

  • Core handler function that executes the tool logic: constructs query params and fetches indicative swap price from Aggregator Protocol API endpoint /api/swap/price
    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}`); } }
  • ToolService wrapper handler: validates input parameters and delegates to AgService.getSwapPrice, formats response for MCP
    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, }; }
  • Input/output schema definition for the get_swap_price tool in MCP ListToolsRequestHandler
    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/index.js:984-986 (registration)
    MCP CallToolRequestHandler registration: switch case dispatching get_swap_price tool calls to ToolService.getSwapPrice
    case TOOL_NAMES.GET_SWAP_PRICE: result = await toolService.getSwapPrice(args); break;
  • src/constants.js:4-4 (registration)
    Tool name constant definition used in registration and schema
    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