Skip to main content
Glama
cuongpo

Rootstock MCP Server

by cuongpo

get_balance

Retrieve the balance of a wallet address for native or ERC20 tokens on the Rootstock blockchain using standardized APIs from the MCP Server.

Instructions

Get the balance of a wallet address (native tokens or ERC20 tokens)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesWallet address to check balance for
tokenAddressNoOptional ERC20 token contract address

Implementation Reference

  • MCP tool registration, input schema, and handler for 'get_balance'. Handles both native and ERC20 token balances by delegating to RootstockClient methods.
    server.tool(
      "get_balance",
      "Get the balance of a wallet address (native tokens or ERC20 tokens)",
      {
        address: z.string().describe("Wallet address to check balance for"),
        tokenAddress: z.string().optional().describe("Optional ERC20 token contract address"),
      },
      async ({ address, tokenAddress }) => {
        try {
          if (tokenAddress) {
            const tokenBalance = await rootstockClient.getTokenBalance(address, tokenAddress);
            return {
              content: [
                {
                  type: "text",
                  text: `Token Balance:\n\nAddress: ${address}\nToken: ${tokenBalance.name} (${tokenBalance.symbol})\nBalance: ${tokenBalance.balance} ${tokenBalance.symbol}`,
                },
              ],
            };
          } else {
            const balance = await rootstockClient.getBalance(address);
            return {
              content: [
                {
                  type: "text",
                  text: `Native Balance:\n\nAddress: ${address}\nBalance: ${balance} ${rootstockClient.getCurrencySymbol()}`,
                },
              ],
            };
          }
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error getting balance: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • Core helper function to fetch native token (tRBTC) balance using ethers.JsonRpcProvider.getBalance and format to ether units.
    async getBalance(address: string): Promise<string> {
      try {
        const balance = await this.getProvider().getBalance(address);
        return ethers.formatEther(balance);
      } catch (error) {
        throw new Error(`Failed to get balance: ${error}`);
      }
    }
  • Core helper function to fetch ERC20 token balance, including token metadata (name, symbol, decimals), using direct contract calls.
    async getTokenBalance(address: string, tokenAddress: string): Promise<TokenBalance> {
      try {
        const tokenContract = new ethers.Contract(
          tokenAddress,
          [
            'function balanceOf(address) view returns (uint256)',
            'function decimals() view returns (uint8)',
            'function symbol() view returns (string)',
            'function name() view returns (string)',
          ],
          this.getProvider()
        );
    
        const [balance, decimals, symbol, name] = await Promise.all([
          tokenContract.balanceOf(address),
          tokenContract.decimals(),
          tokenContract.symbol(),
          tokenContract.name(),
        ]);
    
        return {
          tokenAddress,
          balance: ethers.formatUnits(balance, decimals),
          decimals,
          symbol,
          name,
        };
      } catch (error) {
        throw new Error(`Failed to get token balance: ${error}`);
      }
    }
  • Registration of the 'get_balance' tool in the MCP server.
    server.tool(
      "get_balance",
      "Get the balance of a wallet address (native tokens or ERC20 tokens)",
      {
        address: z.string().describe("Wallet address to check balance for"),
        tokenAddress: z.string().optional().describe("Optional ERC20 token contract address"),
      },
      async ({ address, tokenAddress }) => {
        try {
          if (tokenAddress) {
            const tokenBalance = await rootstockClient.getTokenBalance(address, tokenAddress);
            return {
              content: [
                {
                  type: "text",
                  text: `Token Balance:\n\nAddress: ${address}\nToken: ${tokenBalance.name} (${tokenBalance.symbol})\nBalance: ${tokenBalance.balance} ${tokenBalance.symbol}`,
                },
              ],
            };
          } else {
            const balance = await rootstockClient.getBalance(address);
            return {
              content: [
                {
                  type: "text",
                  text: `Native Balance:\n\nAddress: ${address}\nBalance: ${balance} ${rootstockClient.getCurrencySymbol()}`,
                },
              ],
            };
          }
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error getting balance: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • Input schema for the get_balance tool using Zod validation.
      address: z.string().describe("Wallet address to check balance for"),
      tokenAddress: z.string().optional().describe("Optional ERC20 token contract address"),
    },
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 tool reads balances but doesn't specify whether it requires authentication, network connectivity, rate limits, error conditions, or what the return format looks like. This is inadequate 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 directly states the tool's purpose without any wasted words. It's appropriately sized and front-loaded with the essential information.

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?

For a tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the balance return value looks like (e.g., numeric, formatted), units, or error handling. Given the complexity of blockchain interactions, more behavioral context is needed.

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 adds minimal value beyond the input schema, which already has 100% coverage with clear parameter descriptions. It mentions 'native tokens or ERC20 tokens' which hints at the tokenAddress parameter's purpose, but doesn't provide additional context like format requirements or examples.

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 specific action ('Get the balance') and resource ('wallet address'), and distinguishes between native tokens and ERC20 tokens. It precisely communicates what the tool does without being vague or tautological.

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 like 'get_token_info' or 'list_wallets', nor does it mention any prerequisites or exclusions. It only states what the tool does, not when it should be selected.

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

Related 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/cuongpo/rootstock-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server