Skip to main content
Glama

get_token_accounts

Retrieve all token accounts associated with a specific Solana wallet to view holdings and manage assets.

Instructions

Get all token accounts for a wallet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletNameYesName of the wallet

Implementation Reference

  • The handler function that implements the core logic of the 'get_token_accounts' tool. It retrieves all SPL token accounts owned by the specified wallet using Solana's RPC connection.getTokenAccountsByOwner method, parses the results, and returns a list of token accounts with their addresses, mints, balances, and decimals.
    async function handleGetTokenAccounts(args: any) {
      const { walletName } = args;
      
      const wallet = wallets.get(walletName);
      if (!wallet) {
        throw new Error(`Wallet '${walletName}' not found`);
      }
    
      ensureConnection();
      const tokenAccounts = await connection.getTokenAccountsByOwner(wallet.keypair.publicKey, {
        programId: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
      });
    
      const accounts = tokenAccounts.value.map(account => {
        const data = account.account.data as any;
        return {
          address: account.pubkey.toString(),
          mint: data.parsed?.info?.mint || 'unknown',
          amount: data.parsed?.info?.tokenAmount?.uiAmount || 0,
          decimals: data.parsed?.info?.tokenAmount?.decimals || 0
        };
      });
    
      return {
        wallet: walletName,
        tokenAccounts: accounts,
        count: accounts.length
      };
    }
  • src/index.ts:289-302 (registration)
    The tool registration entry in the tools array, which defines the name, description, and input schema for 'get_token_accounts'. This is returned by the ListToolsRequestHandler.
    {
      name: "get_token_accounts",
      description: "Get all token accounts for a wallet",
      inputSchema: {
        type: "object",
        properties: {
          walletName: {
            type: "string",
            description: "Name of the wallet"
          }
        },
        required: ["walletName"]
      }
    },
  • The input schema for the 'get_token_accounts' tool, defining that it requires a 'walletName' string parameter.
    inputSchema: {
      type: "object",
      properties: {
        walletName: {
          type: "string",
          description: "Name of the wallet"
        }
      },
      required: ["walletName"]
    }
  • src/index.ts:1327-1329 (registration)
    The dispatch case in the main CallToolRequestSchema handler that routes calls to the 'get_token_accounts' tool to its handler function.
    case "get_token_accounts":
      result = await handleGetTokenAccounts(args);
      break;

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