Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

get_swap_quote

Generate executable token swap quotes with transaction data for DeFi trading across multiple blockchains.

Instructions

Get executable quote with transaction data for a token swap

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, uses USER_ADDRESS from env)
slippageBpsNoMaximum acceptable slippage in basis points (optional, default: 100)

Implementation Reference

  • Main handler function for get_swap_quote tool. Validates parameters, adds user address as taker if missing, delegates to AgService.getSwapQuote, enhances result with chainId, and returns formatted response with next steps.
    async getSwapQuote(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"
        );
      }
    
      // Add taker address if not provided
      const quoteParams = {
        ...params,
        taker: params.taker || this.userAddress,
      };
    
      const result = await this.agg.getSwapQuote(quoteParams);
    
      // Add chainId to the result for executeSwap to use
      result.chainId = chainId;
    
      return {
        message: "Swap quote retrieved successfully",
        data: result,
        nextSteps: [
          "1. Review the quote details including fees and gas estimates",
          "2. Use execute_swap tool to execute this swap",
          "3. The permit2 signature will be handled automatically",
        ],
      };
    }
  • Input schema definition for the get_swap_quote tool, specifying parameters like chainId, buyToken, sellToken, sellAmount, with optional taker and slippageBps.
    {
      name: TOOL_NAMES.GET_SWAP_QUOTE,
      description:
        "Get executable quote with transaction data for a token swap",
      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, uses USER_ADDRESS from env)",
          },
          slippageBps: {
            type: "integer",
            description:
              "Maximum acceptable slippage in basis points (optional, default: 100)",
          },
        },
        required: ["chainId", "buyToken", "sellToken", "sellAmount"],
      },
    },
  • src/index.js:988-990 (registration)
    Registration of the get_swap_quote tool in the MCP CallToolRequestSchema handler switch statement, dispatching to toolService.getSwapQuote.
    case TOOL_NAMES.GET_SWAP_QUOTE:
      result = await toolService.getSwapQuote(args);
      break;
  • Helper function in AgService that performs the actual HTTP request to the aggregator API endpoint /api/swap/quote to fetch the swap quote data.
    async getSwapQuote(params) {
      try {
        const queryParams = new URLSearchParams(params);
        const response = await fetch(`${this.baseUrl}/api/swap/quote?${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 quote: ${error.message}`);
      }
    }
  • src/constants.js:5-6 (registration)
    Constant definition mapping GET_SWAP_QUOTE to the tool name string 'get_swap_quote' used in schema and registration.
    GET_SWAP_QUOTE: "get_swap_quote",
    EXECUTE_SWAP: "execute_swap",
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'executable quote with transaction data,' which implies this is a read-only operation that prepares data for a swap, but it doesn't disclose critical behaviors like whether this requires authentication, rate limits, network dependencies, or what the output format looks like (e.g., JSON structure). This leaves significant gaps for a tool that likely interacts with blockchain networks.

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 front-loads the core purpose ('Get executable quote with transaction data for a token swap'). There is zero waste or redundancy, making it highly concise and well-structured for quick understanding.

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 of a token swap tool with 6 parameters, no annotations, and no output schema, the description is incomplete. It doesn't address behavioral aspects like authentication needs, error handling, or output format, which are crucial for an AI agent to use this tool effectively in a blockchain context. The schema covers parameters well, but overall context is lacking.

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?

The schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional meaning beyond what's in the schema (e.g., it doesn't explain relationships between parameters like how 'sellAmount' interacts with 'sellToken'). Baseline 3 is appropriate as the schema does the heavy lifting, but the description doesn't compensate with extra insights.

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 tool's purpose with a specific verb ('Get') and resource ('executable quote with transaction data for a token swap'). It distinguishes itself from siblings like 'get_swap_price' by emphasizing the executable nature of the quote, though it doesn't explicitly contrast with all similar tools like 'get_gasless_quote'.

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. It doesn't mention when to choose this over 'get_swap_price' (which might provide price estimates without transaction data) or 'get_gasless_quote' (which might be for gasless swaps), nor does it specify prerequisites or exclusions for usage.

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