Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

execute_swap

Execute cryptocurrency swap transactions using pre-quoted data to complete trades across multiple blockchains.

Instructions

Execute a swap transaction (requires quote data)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
quoteDataYesQuote data from get_swap_quote

Implementation Reference

  • The primary handler function for the 'execute_swap' tool. It validates the quoteData and user private key, extracts the chainId, signs the transaction, broadcasts it via BlockchainService, and returns success details with transaction hash.
    async executeSwap(quoteData) {
      if (!quoteData) {
        throw new Error("Quote data is required for swap execution");
      }
    
      if (!this.userPrivateKey) {
        throw new Error("User private key is required for swap execution");
      }
    
      try {
        // Extract chain ID from quote data
        const chainId = quoteData.chainId || quoteData.transaction?.chainId;
        if (!chainId) {
          throw new Error("Chain ID not found in quote data");
        }
    
        console.log("🚀 Executing swap transaction...");
    
        // Sign and broadcast the transaction using blockchain service
        const result = await this.blockchain.signAndBroadcastTransaction(
          chainId,
          quoteData
        );
    
        return {
          message: "Swap executed successfully",
          data: result,
          nextSteps: [
            "1. Transaction has been broadcasted to the blockchain",
            "2. Wait for confirmation (usually 1-3 minutes)",
            "3. Check transaction status on block explorer",
            `4. Transaction hash: ${result.hash}`,
          ],
        };
      } catch (error) {
        throw new Error(`Swap execution failed: ${error.message}`);
      }
    }
  • The input schema definition for the 'execute_swap' tool, specifying that it requires an object 'quoteData' from the prior get_swap_quote tool.
    {
      name: TOOL_NAMES.EXECUTE_SWAP,
      description: "Execute a swap transaction (requires quote data)",
      inputSchema: {
        type: "object",
        properties: {
          quoteData: {
            type: "object",
            description: "Quote data from get_swap_quote",
          },
        },
        required: ["quoteData"],
      },
    },
  • src/index.js:992-994 (registration)
    The dispatch/registration case in the main tool handler switch statement that routes calls to 'execute_swap' to the ToolService.executeSwap method.
    case TOOL_NAMES.EXECUTE_SWAP:
      result = await toolService.executeSwap(args.quoteData);
      break;
  • src/constants.js:6-6 (registration)
    Constant definition mapping EXECUTE_SWAP to the tool name string 'execute_swap' used throughout the codebase.
    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 the requirement for quote data but doesn't describe critical traits like whether this is a read/write operation, authentication needs, potential side effects (e.g., funds movement), rate limits, or error handling. This is inadequate for a transaction execution tool.

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 extremely concise with a single, front-loaded sentence that directly states the purpose and key requirement. There is no wasted language, and every word earns its place.

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 swap transaction tool with no annotations and no output schema, the description is insufficient. It lacks details on behavioral traits, return values, error conditions, and differentiation from siblings, making it incomplete for safe and effective use by an AI agent.

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%, with the parameter 'quoteData' fully documented in the schema as 'Quote data from get_swap_quote'. The description adds no additional meaning beyond this, so it meets the baseline for high schema coverage without compensating further.

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 ('Execute a swap transaction') and the resource ('swap transaction'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'submit_gasless_swap' or 'get_swap_quote', which would be needed for a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage guidance by mentioning 'requires quote data' and referencing 'get_swap_quote', suggesting this tool should be used after obtaining a quote. However, it doesn't explicitly state when to use this vs. alternatives like 'submit_gasless_swap' or provide clear exclusions.

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