Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

convert_formatted_to_wei

Convert human-readable cryptocurrency amounts to wei units for blockchain transactions. Specify token decimals to ensure accurate conversions in DeFi trading operations.

Instructions

Convert formatted amounts to wei using ethers.js

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesFormatted amount (e.g., '1.5' for 1.5 ETH)
decimalsYesNumber of decimal places for the token (e.g., 18 for ETH, 6 for USDC)

Implementation Reference

  • The main handler function that implements the convert_formatted_to_wei tool logic using ethers.parseUnits to convert formatted amounts to wei.
    async convertFormattedToWei(params) {
      const { amount, decimals } = params;
    
      if (!amount) {
        throw new Error("amount is required");
      }
    
      if (decimals === undefined || decimals === null) {
        throw new Error("decimals is required");
      }
    
      try {
        // Convert the formatted amount to wei (BigNumber)
        const weiAmount = ethers.parseUnits(amount.toString(), decimals);
    
        return {
          message: "Formatted to wei conversion completed successfully",
          data: {
            originalAmount: amount.toString(),
            decimals: decimals,
            weiAmount: weiAmount.toString(),
            unit: decimals === 18 ? "ETH" : `${decimals} decimals`,
          },
          summary: `Converted ${amount} (${decimals} decimals) to ${weiAmount.toString()} wei`,
        };
      } catch (error) {
        throw new Error(`Formatted to wei conversion failed: ${error.message}`);
      }
    }
  • MCP tool schema definition including inputSchema, properties for amount and decimals, and required fields.
      name: TOOL_NAMES.CONVERT_FORMATTED_TO_WEI,
      description: "Convert formatted amounts to wei using ethers.js",
      inputSchema: {
        type: "object",
        properties: {
          amount: {
            type: "string",
            description: "Formatted amount (e.g., '1.5' for 1.5 ETH)",
          },
          decimals: {
            type: "integer",
            description:
              "Number of decimal places for the token (e.g., 18 for ETH, 6 for USDC)",
          },
        },
        required: ["amount", "decimals"],
      },
    },
  • src/index.js:1178-1180 (registration)
    Tool registration and dispatch in the CallToolRequestSchema handler switch statement, calling toolService.convertFormattedToWei.
    case TOOL_NAMES.CONVERT_FORMATTED_TO_WEI:
      result = await toolService.convertFormattedToWei(args);
      break;
  • Constant definition for the tool name used in registration and dispatch.
    CONVERT_FORMATTED_TO_WEI: "convert_formatted_to_wei",
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 use of 'ethers.js' but doesn't describe error handling, input validation, or output format. For a conversion tool with no annotation coverage, this leaves significant gaps in understanding how it behaves in practice.

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 function. It's front-loaded with the core purpose and uses no unnecessary words, making it easy to parse and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (2 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavioral aspects and usage context. For a simple conversion tool, this is acceptable but not comprehensive.

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 description doesn't add meaning beyond what the input schema provides, as schema description coverage is 100%. The schema already documents 'amount' and 'decimals' with examples. Since the description doesn't explain parameter interactions or additional context, it meets the baseline score for high schema coverage.

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: converting formatted amounts to wei using ethers.js. It specifies the verb ('convert'), resource ('formatted amounts'), and technology ('ethers.js'), making it easy to understand. However, it doesn't explicitly differentiate from its sibling 'convert_wei_to_formatted' beyond the directional implication, which keeps it from 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 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 the sibling tool 'convert_wei_to_formatted' for reverse conversions, nor does it explain scenarios where this conversion is needed (e.g., for blockchain transactions or calculations). Usage is implied only by the tool's name and description.

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