Skip to main content
Glama

get-account-balance

Retrieve SOL and token balances for a specified account on the Pump.fun Solana platform to monitor cryptocurrency holdings.

Instructions

Get the SOL and token balances for an account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountNameNoName of the account to checkdefault
tokenAddressNoOptional token address to check balance for

Implementation Reference

  • Main handler function that loads the account keypair from .keys folder, fetches SOL balance, and optionally fetches SPL token balance using getSPLBalance helper.
    export async function getAccountBalance(
      accountName: string = "default",
      tokenAddress?: string
    ): Promise<string> {
      try {
        const { connection } = initializeSDK();
        const keysFolder = path.resolve(rootDir, ".keys");
        const accountFilePath = path.join(keysFolder, `${accountName}.json`);
    
        if (!fs.existsSync(accountFilePath)) {
          throw new Error(`Account file not found for ${accountName}`);
        }
    
        const keypairData = JSON.parse(fs.readFileSync(accountFilePath, "utf-8"));
        const keypair = Keypair.fromSecretKey(new Uint8Array(keypairData));
    
        const solBalance = await connection.getBalance(keypair.publicKey);
    
        let response = [
          `Account: ${accountName} (${keypair.publicKey.toString()})`,
          `SOL Balance: ${solBalance / LAMPORTS_PER_SOL} SOL`,
        ];
    
        if (tokenAddress) {
          const mintPublicKey = new PublicKey(tokenAddress);
          const tokenBalance = await getSPLBalance(
            connection,
            mintPublicKey,
            keypair.publicKey
          );
    
          response.push(
            `Token Balance (${tokenAddress}): ${
              tokenBalance !== null ? tokenBalance : "No token account found"
            }`
          );
        }
    
        return response.join("\n");
      } catch (error: any) {
        console.error("Error getting account balance:", error);
        return `Error getting account balance: ${
          error?.message || "Unknown error"
        }`;
      }
    }
  • src/index.ts:275-313 (registration)
    Tool registration with McpServer.tool(), including description, Zod input schema, and execution handler that calls the getAccountBalance function.
    server.tool(
      "get-account-balance",
      "Get the SOL and token balances for an account",
      {
        accountName: z
          .string()
          .default("default")
          .describe("Name of the account to check"),
        tokenAddress: z
          .string()
          .optional()
          .describe("Optional token address to check balance for"),
      },
      async ({ accountName, tokenAddress }) => {
        try {
          const result = await getAccountBalance(accountName, tokenAddress);
          return {
            content: [
              {
                type: "text",
                text: result,
              },
            ],
          };
        } catch (error: any) {
          console.error("Error getting account balance:", error);
          return {
            content: [
              {
                type: "text",
                text: `Error getting account balance: ${
                  error?.message || "Unknown error"
                }`,
              },
            ],
          };
        }
      }
    );
  • Zod input schema defining parameters: accountName (string, default 'default') and optional tokenAddress (string).
    {
      accountName: z
        .string()
        .default("default")
        .describe("Name of the account to check"),
      tokenAddress: z
        .string()
        .optional()
        .describe("Optional token address to check balance for"),
    },
  • Helper function to retrieve the SPL token balance for a specific mint and owner public key, used when tokenAddress is provided.
    async function getSPLBalance(
      connection: Connection,
      mint: PublicKey,
      owner: PublicKey
    ): Promise<number | null> {
      try {
        const tokenAccounts = await connection.getParsedTokenAccountsByOwner(
          owner,
          {
            mint,
          }
        );
    
        if (tokenAccounts.value.length === 0) {
          return null;
        }
    
        const tokenAccount = tokenAccounts.value[0];
        const parsedInfo = tokenAccount.account.data.parsed.info;
        const balance = parsedInfo.tokenAmount.uiAmount;
    
        return balance;
      } catch (error) {
        console.error("Error getting SPL balance:", error);
        return null;
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv1.0.0
    • addedInput schema / $schema
      Added value: +"http://json-schema.org/draft-07/schema#"
    • addedInput schema / additionalProperties
      Added value: +false
  2. First observed

TDQS

C2.9/5.0
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 states what the tool does but lacks critical behavioral details such as whether this is a read-only operation (implied but not explicit), potential rate limits, authentication requirements, or error conditions. This is a significant gap for a tool that likely interacts with financial data.

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 fluff. It is front-loaded and appropriately sized, making it easy for an agent to parse quickly.

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?

Given the complexity of financial balance retrieval, no annotations, and no output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., balance values, formats), potential side effects, or error handling. This leaves the agent with insufficient context for reliable tool invocation.

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 schema description coverage is 100%, so the schema already documents both parameters ('accountName' and 'tokenAddress') with clear descriptions. The description adds no additional semantic context beyond implying balance retrieval for SOL and tokens, which aligns with the schema but doesn't provide extra value like parameter interactions or examples.

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 ('Get') and resources ('SOL and token balances for an account'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'list-accounts' or 'get-token-info', which could provide related information, so it falls short of 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. For example, it doesn't clarify if this is for checking balances of a specific account versus listing all accounts (as 'list-accounts' might do), or how it differs from 'get-token-info' in terms of balance retrieval. This lack of context leaves the agent to infer usage.

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