Skip to main content
Glama

close_token_account

Close a Solana token account to reclaim rent lamports by transferring remaining funds to a specified destination address.

Instructions

Close a token account and reclaim rent

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletNameYesName of the wallet that owns the account
tokenMintYesToken mint address
destinationAddressYesAddress to send remaining lamports to

Implementation Reference

  • The handler function that executes the close_token_account tool, using Solana SPL closeAccount to close the associated token account and send lamports to destination.
    async function handleCloseTokenAccount(args: any) {
      const { walletName, tokenMint, destinationAddress } = args;
    
      const wallet = wallets.get(walletName);
      if (!wallet) {
        throw new Error(`Wallet '${walletName}' not found`);
      }
    
      ensureConnection();
      const tokenMintPubkey = new PublicKey(tokenMint);
      const destinationPubkey = new PublicKey(destinationAddress);
    
      const tokenAccount = await getAssociatedTokenAddress(
        tokenMintPubkey,
        wallet.keypair.publicKey
      );
    
      const signature = await closeAccount(
        connection,
        wallet.keypair,
        tokenAccount,
        destinationPubkey,
        wallet.keypair
      );
    
      return {
        success: true,
        signature,
        closedAccount: tokenAccount.toString(),
        destination: destinationAddress,
        explorerUrl: `https://explorer.solana.com/tx/${signature}?cluster=${currentNetwork}`
      };
    }
  • Input schema defining parameters for the close_token_account tool: walletName, tokenMint, destinationAddress.
    inputSchema: {
      type: "object",
      properties: {
        walletName: {
          type: "string",
          description: "Name of the wallet that owns the account"
        },
        tokenMint: {
          type: "string",
          description: "Token mint address"
        },
        destinationAddress: {
          type: "string",
          description: "Address to send remaining lamports to"
        }
      },
      required: ["walletName", "tokenMint", "destinationAddress"]
    }
  • src/index.ts:458-479 (registration)
    Tool registration in the tools array, including name, description, and input schema. Used by ListToolsRequestSchema handler.
    {
      name: "close_token_account",
      description: "Close a token account and reclaim rent",
      inputSchema: {
        type: "object",
        properties: {
          walletName: {
            type: "string",
            description: "Name of the wallet that owns the account"
          },
          tokenMint: {
            type: "string",
            description: "Token mint address"
          },
          destinationAddress: {
            type: "string",
            description: "Address to send remaining lamports to"
          }
        },
        required: ["walletName", "tokenMint", "destinationAddress"]
      }
    },
  • src/index.ts:1351-1352 (registration)
    Registration in the main CallToolRequestSchema switch dispatcher that calls the handler.
    case "close_token_account":
      result = await handleCloseTokenAccount(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