Skip to main content
Glama

get_token_balance

Retrieve SPL token balance for a specified wallet and token mint address on the Solana blockchain.

Instructions

Get SPL token balance for a wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletNameYesName of the wallet
tokenMintYesToken mint address

Implementation Reference

  • The handler function that implements the get_token_balance tool logic. It retrieves the SPL token balance from the associated token account for the given wallet and token mint, handling errors if the account does not exist.
    async function handleGetTokenBalance(args: any) { const { walletName, tokenMint } = args; const wallet = wallets.get(walletName); if (!wallet) { throw new Error(`Wallet '${walletName}' not found`); } ensureConnection(); try { const tokenMintPubkey = new PublicKey(tokenMint); const tokenAccount = await getAssociatedTokenAddress(tokenMintPubkey, wallet.keypair.publicKey); const accountInfo = await getAccount(connection, tokenAccount); return { wallet: walletName, tokenMint: tokenMint, balance: accountInfo.amount.toString(), decimals: accountInfo.mint.toString() }; } catch (error) { return { wallet: walletName, tokenMint: tokenMint, balance: "0", error: "Token account not found or error retrieving balance" }; } }
  • The input schema defining the parameters for the get_token_balance tool: walletName and tokenMint.
    inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" }, tokenMint: { type: "string", description: "Token mint address" } }, required: ["walletName", "tokenMint"] }
  • src/index.ts:128-145 (registration)
    The tool registration in the tools array, used by ListToolsRequestSchema, including name, description, and input schema.
    { name: "get_token_balance", description: "Get SPL token balance for a wallet", inputSchema: { type: "object", properties: { walletName: { type: "string", description: "Name of the wallet" }, tokenMint: { type: "string", description: "Token mint address" } }, required: ["walletName", "tokenMint"] } },
  • src/index.ts:1297-1298 (registration)
    The dispatch case in the CallToolRequestSchema handler that routes calls to the get_token_balance handler function.
    case "get_token_balance": result = await handleGetTokenBalance(args);

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/ExpertVagabond/solana-mcp-server'

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