Skip to main content
Glama
buildwithgrove

Grove's MCP Server for Pocket Network

get_solana_token_balance

Retrieve SPL token balances for a Solana wallet address. Specify a mint address for a single token or get all token balances across mainnet or testnet networks.

Instructions

Get SPL token balance(s) for a Solana wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mintAddressNoOptional: SPL token mint address (if not provided, returns all token balances)
networkNoNetwork type (defaults to mainnet)
walletAddressYesSolana wallet address

Implementation Reference

  • Tool registration definition including name, description, and input schema.
    { name: 'get_solana_token_balance', description: 'Get SPL token balance(s) for a Solana wallet', inputSchema: { type: 'object', properties: { walletAddress: { type: 'string', description: 'Solana wallet address', }, mintAddress: { type: 'string', description: 'Optional: SPL token mint address (if not provided, returns all token balances)', }, network: { type: 'string', enum: ['mainnet', 'testnet'], description: 'Network type (defaults to mainnet)', }, }, required: ['walletAddress'], }, },
  • MCP tool handler logic: extracts parameters from args and calls SolanaService.getTokenBalance, formats response.
    case 'get_solana_token_balance': { const walletAddress = args?.walletAddress as string; const mintAddress = args?.mintAddress as string | undefined; const network = (args?.network as 'mainnet' | 'testnet') || 'mainnet'; const result = await solanaService.getTokenBalance(walletAddress, mintAddress, network); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], isError: !result.success, }; }
  • Core implementation: fetches token accounts via RPC 'getTokenAccountsByOwner', parses balances for specific mint or all tokens owned by wallet.
    async getTokenBalance( walletAddress: string, mintAddress?: string, network: 'mainnet' | 'testnet' = 'mainnet' ): Promise<EndpointResponse> { const service = this.blockchainService.getServiceByBlockchain('solana', network); if (!service) { return { success: false, error: `Solana service not found for ${network}`, }; } try { // Get all token accounts for the wallet const params = mintAddress ? [ walletAddress, { mint: mintAddress, }, { encoding: 'jsonParsed', }, ] : [ walletAddress, { programId: SolanaService.TOKEN_PROGRAM_ID, }, { encoding: 'jsonParsed', }, ]; const result = await this.blockchainService.callRPCMethod( service.id, 'getTokenAccountsByOwner', params ); if (!result.success) { return result; } const accounts = result.data?.value || []; if (mintAddress) { // Return specific token balance if (accounts.length === 0) { return { success: true, data: { mint: mintAddress, owner: walletAddress, balance: '0', decimals: 0, }, metadata: result.metadata, }; } const account = accounts[0]; const tokenAmount = account.account?.data?.parsed?.info?.tokenAmount; return { success: true, data: { mint: mintAddress, owner: walletAddress, balance: tokenAmount?.amount || '0', uiAmount: tokenAmount?.uiAmount || 0, decimals: tokenAmount?.decimals || 0, }, metadata: result.metadata, }; } else { // Return all token balances const balances = accounts.map((account: any) => { const info = account.account?.data?.parsed?.info; const tokenAmount = info?.tokenAmount; return { mint: info?.mint, balance: tokenAmount?.amount || '0', uiAmount: tokenAmount?.uiAmount || 0, decimals: tokenAmount?.decimals || 0, }; }); return { success: true, data: { owner: walletAddress, tokens: balances, count: balances.length, }, metadata: result.metadata, }; } } catch (error) { return { success: false, error: error instanceof Error ? error.message : 'Failed to get Solana token balance', }; } }

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/buildwithgrove/mcp-pocket'

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