Skip to main content
Glama
edkdev

DeFi Trading Agent MCP Server

by edkdev

convert_wei_to_formatted

Convert wei amounts to human-readable format using token decimals for DeFi trading operations.

Instructions

Convert wei amounts to human-readable format using ethers.js

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesAmount in wei (as string to handle large numbers)
decimalsYesNumber of decimal places for the token (e.g., 18 for ETH, 6 for USDC)

Implementation Reference

  • The main handler function that executes the wei to formatted conversion logic using ethers.formatUnits, including input validation and formatted response.
    async convertWeiToFormatted(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 amount to a BigNumber and format it
        const formattedAmount = ethers.formatUnits(amount.toString(), decimals);
    
        return {
          message: "Wei to formatted conversion completed successfully",
          data: {
            originalAmount: amount.toString(),
            decimals: decimals,
            formattedAmount: formattedAmount,
            unit: decimals === 18 ? "ETH" : `${decimals} decimals`,
          },
          summary: `Converted ${amount} wei to ${formattedAmount} (${decimals} decimals)`,
        };
      } catch (error) {
        throw new Error(`Wei to formatted conversion failed: ${error.message}`);
      }
    }
  • src/index.js:934-952 (registration)
    MCP tool registration including name, description, and input schema definition.
      name: TOOL_NAMES.CONVERT_WEI_TO_FORMATTED,
      description:
        "Convert wei amounts to human-readable format using ethers.js",
      inputSchema: {
        type: "object",
        properties: {
          amount: {
            type: "string",
            description: "Amount in wei (as string to handle large numbers)",
          },
          decimals: {
            type: "integer",
            description:
              "Number of decimal places for the token (e.g., 18 for ETH, 6 for USDC)",
          },
        },
        required: ["amount", "decimals"],
      },
    },
  • Input schema for the tool defining parameters amount (string) and decimals (integer).
    inputSchema: {
      type: "object",
      properties: {
        amount: {
          type: "string",
          description: "Amount in wei (as string to handle large numbers)",
        },
        decimals: {
          type: "integer",
          description:
            "Number of decimal places for the token (e.g., 18 for ETH, 6 for USDC)",
        },
      },
      required: ["amount", "decimals"],
    },
  • Constant defining the tool name string for use in registration and dispatch.
    CONVERT_WEI_TO_FORMATTED: "convert_wei_to_formatted",
  • src/index.js:1174-1176 (registration)
    Dispatch case in the main tool request handler that routes execution to the toolService handler.
    case TOOL_NAMES.CONVERT_WEI_TO_FORMATTED:
      result = await toolService.convertWeiToFormatted(args);
      break;
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions 'using ethers.js' which hints at library behavior, but doesn't disclose critical traits: error handling (e.g., invalid inputs), output format (string/number), rounding behavior, or performance considerations. For a conversion tool with no annotation coverage, this leaves significant behavioral gaps.

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 with zero waste. It's front-loaded with the core purpose and includes implementation detail without redundancy. Every word earns its place.

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 2 parameters with full schema coverage and no output schema, the description is minimally complete for a simple conversion tool. However, without annotations or output schema, it should ideally explain the return format (e.g., string in ether units) and error cases to be fully helpful.

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 schema already documents both parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., no examples of typical 'amount' values or 'decimals' usage). Baseline 3 is appropriate when schema does the heavy lifting.

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 verb 'convert' and the resource 'wei amounts to human-readable format', specifying the implementation method 'using ethers.js'. It distinguishes from its sibling 'convert_formatted_to_wei' by indicating the opposite direction of conversion. However, it doesn't explicitly mention what 'human-readable format' means (e.g., ether units).

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 implies usage when converting from wei to formatted amounts, with the sibling tool suggesting the alternative for reverse conversion. However, it lacks explicit guidance on when to use this versus other tools for similar purposes (e.g., formatting in different contexts) or prerequisites like valid wei strings.

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