Skip to main content
Glama

get_msol_balance

Check the mSOL token balance for any Solana wallet address or the environment wallet to monitor liquid staking holdings.

Instructions

Check the mSOL token balance of the environment wallet or any specified Solana wallet address.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
walletAddressNoOptional: The Solana wallet address to check. If not provided, checks the environment wallet balance.

Implementation Reference

  • The main execution logic for the get_msol_balance tool. Fetches Marinade state to get mSolMint, checks or creates associated token account, retrieves and formats the mSOL balance.
    callback: async ({ walletAddress }: { walletAddress?: string }) => { try { const { wallet, connection } = createSolanaConfig() const config = new MarinadeConfig({ connection, publicKey: wallet.publicKey, }) const marinade = new Marinade(config) const marinadeState = await marinade.getMarinadeState(); const mSolMint = marinadeState.mSolMintAddress; let targetPublicKey: PublicKey; let isOwnWallet = true; if (walletAddress) { try { targetPublicKey = new PublicKey(walletAddress); isOwnWallet = targetPublicKey.toString() === wallet.publicKey.toString(); } catch (err) { return { content: [ { type: "text", text: JSON.stringify({ error: "Invalid wallet address", reason: "The provided wallet address is not a valid Solana public key" }, null, 2), }, ], }; } } else { targetPublicKey = wallet.publicKey; } try { const tokenAccount = await getOrCreateAssociatedTokenAccount( connection, wallet, mSolMint, targetPublicKey, false ); const balance = Number(tokenAccount.amount); const balanceInMSol = balance / LAMPORTS_PER_SOL; return { content: [ { type: "text", text: JSON.stringify({ success: true, wallet: targetPublicKey.toString(), tokenAccount: tokenAccount.address.toString(), balance: balanceInMSol, balanceLamports: balance.toString(), mSolMint: mSolMint.toString(), explorerUrl: `https://solscan.io/account/${tokenAccount.address.toString()}${process.env.ENVIRONMENT === 'MAINNET' ? '' : '?cluster=devnet'}` }, null, 2), }, ], }; } catch (err) { if ((err as Error)?.message?.includes("could not find") || (err as Error)?.message?.includes("Invalid account")) { return { content: [ { type: "text", text: JSON.stringify({ success: true, wallet: targetPublicKey.toString(), balance: 0, balanceLamports: "0", mSolMint: mSolMint.toString(), note: "No mSOL token account found for this wallet (balance is 0)" }, null, 2), }, ], }; } throw err; } } catch (err) { const isAbort = (err as Error)?.name === "AbortError"; const isTimeout = (err as Error)?.message?.includes("timeout"); McpLogger.error("Error in get_msol_balance tool:", String(err)); return { content: [ { type: "text", text: JSON.stringify( { error: isAbort || isTimeout ? "Request timed out" : "Failed to get mSOL balance", reason: String((err as Error)?.message ?? err), suggestion: isAbort || isTimeout ? "Try again with a different RPC endpoint." : "Please check the wallet address and network connection." }, null, 2 ), }, ], }; } }
  • Input schema using Zod for validating the optional walletAddress parameter.
    inputSchema: { walletAddress: z.string().optional().describe("Optional: The Solana wallet address to check. If not provided, checks the environment wallet balance."), },
  • src/tools.ts:178-298 (registration)
    The complete tool definition object in the onChainTools array, which is conditionally exported as part of marinadeFinanceTools for MCP server registration.
    { name: "get_msol_balance", title: "Get mSOL Balance", description: "Check the mSOL token balance of the environment wallet or any specified Solana wallet address.", inputSchema: { walletAddress: z.string().optional().describe("Optional: The Solana wallet address to check. If not provided, checks the environment wallet balance."), }, callback: async ({ walletAddress }: { walletAddress?: string }) => { try { const { wallet, connection } = createSolanaConfig() const config = new MarinadeConfig({ connection, publicKey: wallet.publicKey, }) const marinade = new Marinade(config) const marinadeState = await marinade.getMarinadeState(); const mSolMint = marinadeState.mSolMintAddress; let targetPublicKey: PublicKey; let isOwnWallet = true; if (walletAddress) { try { targetPublicKey = new PublicKey(walletAddress); isOwnWallet = targetPublicKey.toString() === wallet.publicKey.toString(); } catch (err) { return { content: [ { type: "text", text: JSON.stringify({ error: "Invalid wallet address", reason: "The provided wallet address is not a valid Solana public key" }, null, 2), }, ], }; } } else { targetPublicKey = wallet.publicKey; } try { const tokenAccount = await getOrCreateAssociatedTokenAccount( connection, wallet, mSolMint, targetPublicKey, false ); const balance = Number(tokenAccount.amount); const balanceInMSol = balance / LAMPORTS_PER_SOL; return { content: [ { type: "text", text: JSON.stringify({ success: true, wallet: targetPublicKey.toString(), tokenAccount: tokenAccount.address.toString(), balance: balanceInMSol, balanceLamports: balance.toString(), mSolMint: mSolMint.toString(), explorerUrl: `https://solscan.io/account/${tokenAccount.address.toString()}${process.env.ENVIRONMENT === 'MAINNET' ? '' : '?cluster=devnet'}` }, null, 2), }, ], }; } catch (err) { if ((err as Error)?.message?.includes("could not find") || (err as Error)?.message?.includes("Invalid account")) { return { content: [ { type: "text", text: JSON.stringify({ success: true, wallet: targetPublicKey.toString(), balance: 0, balanceLamports: "0", mSolMint: mSolMint.toString(), note: "No mSOL token account found for this wallet (balance is 0)" }, null, 2), }, ], }; } throw err; } } catch (err) { const isAbort = (err as Error)?.name === "AbortError"; const isTimeout = (err as Error)?.message?.includes("timeout"); McpLogger.error("Error in get_msol_balance tool:", String(err)); return { content: [ { type: "text", text: JSON.stringify( { error: isAbort || isTimeout ? "Request timed out" : "Failed to get mSOL balance", reason: String((err as Error)?.message ?? err), suggestion: isAbort || isTimeout ? "Try again with a different RPC endpoint." : "Please check the wallet address and network connection." }, null, 2 ), }, ], }; } } },
  • Utility function to create Solana wallet and connection configuration from environment variables, used by the get_msol_balance handler.
    function createSolanaConfig() { const isMainnet = process.env.ENVIRONMENT === "MAINNET"; const privateKey = process.env.PRIVATE_KEY || ''; const rpcUrlMainnet = process.env.SOLANA_RPC_URL const rpcUrlDevnet = process.env.SOLANA_RPC_URL_DEVNET; const rpcUrl = isMainnet ? rpcUrlMainnet : rpcUrlDevnet; if (!privateKey || !rpcUrlMainnet || !rpcUrlDevnet || !rpcUrl) { throw new Error("PRIVATE_KEY, SOLANA_RPC_URL, SOLANA_RPC_URL_DEVNET environment variables are required"); } const wallet = Keypair.fromSecretKey(bs58.decode(privateKey)); const connection = new Connection(rpcUrl, { commitment: "confirmed", }); return { wallet, connection }; }

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/leandrogavidia/marinade-finance-mcp-server'

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