Skip to main content
Glama
Kishore-MK

AI42-MCP X402 Payment Server

by Kishore-MK

Get Wallet Balance

get-balance

Check your current SOL wallet balance to monitor funds and manage payments within the AI42-MCP X402 Payment Server.

Instructions

Check the current SOL balance in your wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get-balance' tool. It creates a signer, connects to Solana devnet RPC, derives the public key from the private key in SOLANA_PRIVATE_KEY env var, fetches the balance, converts lamports to SOL, and returns formatted JSON or error.
    async () => {
      try {
        const signer = await createSigner("solana-devnet", process.env.SOLANA_PRIVATE_KEY || " ");
        const connection = new Connection("https://api.devnet.solana.com", "confirmed");
    
        const privateKeyBytes = bs58.decode(process.env.SOLANA_PRIVATE_KEY || "");
    
    
        const keypair = Keypair.fromSecretKey(privateKeyBytes);
        const publicKey = keypair.publicKey;
    
        const balance = await connection.getBalance(publicKey);
        const solBalance = balance / LAMPORTS_PER_SOL;
    
        return {
          content: [{
            type: "text",
            text: JSON.stringify({
              balance: solBalance,
              unit: "SOL",
              network: "devnet",
              address: publicKey
            }, null, 2)
          }]
        };
      } catch (err: any) {
        return {
          content: [{
            type: "text",
            text: `Error: ${err.message || "Failed to get balance"}`
          }],
          isError: true
        };
      }
    }
  • Schema definition for the 'get-balance' tool, including title, description, and empty input schema (no parameters required).
    {
      title: "Get Wallet Balance",
      description: "Check the current SOL balance in your wallet",
      inputSchema: {},
    },
  • src/index.ts:30-72 (registration)
    Full registration of the 'get-balance' tool via server.registerTool, including name, schema, and inline handler function.
    server.registerTool(
      "get-balance",
      {
        title: "Get Wallet Balance",
        description: "Check the current SOL balance in your wallet",
        inputSchema: {},
      },
      async () => {
        try {
          const signer = await createSigner("solana-devnet", process.env.SOLANA_PRIVATE_KEY || " ");
          const connection = new Connection("https://api.devnet.solana.com", "confirmed");
    
          const privateKeyBytes = bs58.decode(process.env.SOLANA_PRIVATE_KEY || "");
     
    
          const keypair = Keypair.fromSecretKey(privateKeyBytes);
          const publicKey = keypair.publicKey;
    
          const balance = await connection.getBalance(publicKey);
          const solBalance = balance / LAMPORTS_PER_SOL;
    
          return {
            content: [{
              type: "text",
              text: JSON.stringify({
                balance: solBalance,
                unit: "SOL",
                network: "devnet",
                address: publicKey
              }, null, 2)
            }]
          };
        } catch (err: any) {
          return {
            content: [{
              type: "text",
              text: `Error: ${err.message || "Failed to get balance"}`
            }],
            isError: true
          };
        }
      }
    );
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Check' implies a read-only operation, it doesn't specify whether this requires authentication, network connectivity, rate limits, or what happens if the wallet doesn't exist. For a financial tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

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 communicates the essential purpose without any wasted words. It's front-loaded with the core functionality and appropriately sized for a simple read operation with no parameters.

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?

For a simple balance-checking tool with no parameters and no output schema, the description is minimally adequate. However, without annotations covering authentication requirements, network behavior, or error conditions, and with sibling tools that suggest a payment/wallet context, more contextual information would be helpful for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters with 100% schema description coverage, so the schema already fully documents the empty parameter set. The description appropriately doesn't waste space discussing non-existent parameters, maintaining focus on the tool's purpose. Baseline for zero parameters is 4.

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 ('Check') and resource ('current SOL balance in your wallet'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'get-payment-history', but the focus on current balance rather than historical data provides implicit distinction.

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-payment-history' or 'fetch-with-payment'. There's no mention of prerequisites, timing considerations, or comparative use cases with sibling tools.

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/Kishore-MK/ai42-mcp'

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