Skip to main content
Glama
5ajaki

MCP Etherscan Server

by 5ajaki

check-balance

Check the ETH balance of an Ethereum address using the MCP Etherscan Server. Enter a valid 0x format address to retrieve current balance information.

Instructions

Check the ETH balance of an Ethereum address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesEthereum address (0x format)

Implementation Reference

  • Executes the "check-balance" tool: validates input address, fetches balance from EtherscanService, formats and returns the response.
    if (name === "check-balance") {
      try {
        const { address } = AddressSchema.parse(args);
        const balance = await etherscanService.getAddressBalance(address);
        const response = `Address: ${balance.address}\nBalance: ${balance.balanceInEth} ETH`;
        return {
          content: [{ type: "text", text: response }],
        };
      } catch (error) {
        if (error instanceof z.ZodError) {
          throw new Error(
            `Invalid input: ${error.errors.map((e) => e.message).join(", ")}`
          );
        }
        throw error;
      }
    }
  • Core implementation fetching ETH balance using ethers.EtherscanProvider.getBalance and formatting to ETH.
    async getAddressBalance(address: string): Promise<{
      address: string;
      balanceInWei: bigint;
      balanceInEth: string;
    }> {
      try {
        // Validate the address
        const validAddress = ethers.getAddress(address);
        
        // Get balance in Wei
        const balanceInWei = await this.provider.getBalance(validAddress);
        
        // Convert to ETH
        const balanceInEth = ethers.formatEther(balanceInWei);
    
        return {
          address: validAddress,
          balanceInWei,
          balanceInEth
        };
      } catch (error) {
        if (error instanceof Error) {
          throw new Error(`Failed to get balance: ${error.message}`);
        }
        throw error;
      }
    }
  • src/server.ts:66-80 (registration)
    Registers the "check-balance" tool in the listTools response with name, description, and input schema.
    {
      name: "check-balance",
      description: "Check the ETH balance of an Ethereum address",
      inputSchema: {
        type: "object",
        properties: {
          address: {
            type: "string",
            description: "Ethereum address (0x format)",
            pattern: "^0x[a-fA-F0-9]{40}$",
          },
        },
        required: ["address"],
      },
    },
  • Zod schema for validating the Ethereum address input used in the check-balance handler.
    const AddressSchema = z.object({
      address: z
        .string()
        .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format"),
    });

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.2/5.0
Behavior2/5

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

No annotations are provided, so the description bears full responsibility. It only states a read operation, but fails to disclose return format, units, rate limits, or other behavioral traits.

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 concise sentence with no waste. It is front-loaded and efficient.

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?

Despite the tool's simplicity, the description lacks information about return values (e.g., unit of balance), error cases, or any operational context. It is minimally complete.

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 coverage is 100%, and the description adds no meaning beyond what the schema already provides for the address parameter. Baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool checks the ETH balance of an Ethereum address, with a specific verb and resource. It distinguishes from siblings like get-contract-abi or get-ens-name.

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, nor any when-not-to-use scenarios. A single sentence lacks context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.