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

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'indicative price' which implies a read-only, non-destructive operation, but doesn't clarify if this is a simulation, requires authentication, has rate limits, or what the output format might be. For a tool with 5 parameters and no output schema, this leaves significant gaps in understanding how the tool behaves.

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 that directly states the tool's purpose without any wasted words. It's appropriately sized for a straightforward tool and front-loaded with the key action, making it easy to parse quickly.

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 complexity (5 parameters, financial/blockchain context), lack of annotations, and absence of an output schema, the description is incomplete. It doesn't address what the tool returns, error conditions, or behavioral constraints. For a price calculation tool in a DeFi context where precision and reliability matter, this leaves too much unspecified for confident agent use.

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 the input schema already documents all parameters thoroughly. The description adds no additional meaning about parameters beyond what's in the schema (e.g., it doesn't explain relationships between buyToken/sellToken or format of sellAmount). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.

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 indicative price') and resource ('for a token swap using Aggregator Protocol'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'get_swap_quote' or 'get_gasless_price', which appear to serve similar price/quote functions, leaving some ambiguity about when to choose this tool over those alternatives.

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 siblings like 'get_swap_quote' and 'get_gasless_price' that likely serve related purposes, there's no indication of context, prerequisites, or exclusions to help an agent select appropriately. Usage is implied only by the tool name and description, not explicitly stated.

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