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;
      }
    }
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 details on traits like whether it's read-only, requires authentication, has rate limits, or what the return format looks like. This is a significant gap for a tool that retrieves 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 wasted words. It is appropriately sized and front-loaded, making it easy to understand at a glance.

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 retrieving account balances (which may involve sensitive financial data), the lack of annotations and output schema means the description should do more to explain behavioral aspects. It doesn't cover return values, error conditions, or usage context, leaving gaps that could hinder an AI agent's ability to use the tool effectively.

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 descriptions. The description adds no additional meaning beyond implying balances are retrieved, which is redundant with the tool name. Baseline 3 is appropriate as the 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 'Get' and the resources 'SOL and token balances for an account', making the purpose specific and understandable. However, it doesn't explicitly distinguish this tool from sibling tools like 'list-accounts' or 'get-token-info', which might also involve account or token information, so it doesn't fully differentiate from alternatives.

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. It doesn't mention when to choose 'get-account-balance' over 'list-accounts' for account-related queries or 'get-token-info' for token details, nor does it specify any prerequisites or exclusions for usage.

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/dexoryn/pumpfun-mcp-server'

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