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, optionally filtering by specific token mint or network type.

Instructions

Get SPL token balance(s) for a Solana wallet

Input Schema

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

Implementation Reference

  • Tool registration definition including name, description, and input schema for get_solana_token_balance
    {
      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'],
      },
  • Handler logic for the tool: extracts parameters and delegates to 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 of token balance retrieval: calls Solana RPC getTokenAccountsByOwner, parses single or all token accounts, computes balances with decimals
    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',
        };
      }
    }
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 permissions, rate limits, error conditions, or return format. For a read operation with no annotations, this leaves significant gaps in understanding how the tool behaves beyond its basic function.

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, clear sentence with zero wasted words. It's front-loaded with the core purpose and efficiently conveys the essential information without unnecessary elaboration, making it easy to parse quickly.

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?

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is minimally complete. It states the purpose but lacks behavioral details, usage context, and output information. While concise, it doesn't fully compensate for the absence of annotations or output schema, leaving gaps in understanding the tool's full context.

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?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no additional parameter semantics beyond what's in the schema, such as format examples or edge cases. The baseline score of 3 reflects adequate coverage by the schema alone, with no extra value from the description.

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 resource ('SPL token balance(s) for a Solana wallet'), making the purpose immediately understandable. It doesn't explicitly distinguish from siblings like 'get_solana_balance' (which likely gets native SOL balance) or 'get_token_balance' (which might be generic), but the specificity to 'SPL token' and 'Solana wallet' provides some implicit differentiation.

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?

No explicit guidance on when to use this tool versus alternatives is provided. The description doesn't mention sibling tools like 'get_solana_balance' or 'get_token_balance', nor does it explain prerequisites or appropriate contexts. Usage is implied through the tool name and description but not explicitly stated.

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

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