Skip to main content
Glama
leandrogavidia

Marinade Finance MCP Server

Get mSOL Balance

get_msol_balance

Check mSOL token balance for any Solana wallet address or the environment wallet to monitor liquid staking positions in Marinade Finance.

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 callback handler that executes the get_msol_balance tool logic: creates Solana config, initializes Marinade instance, gets mSolMint, resolves target wallet, fetches or notes absence of associated token account, computes and returns balance in mSOL and lamports.
    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
                        ),
                    },
                ],
            };
        }
    }
  • Zod input schema defining the optional 'walletAddress' parameter for the tool.
    inputSchema: {
        walletAddress: z.string().optional().describe("Optional: The Solana wallet address to check. If not provided, checks the environment wallet balance."),
    },
  • src/server.ts:25-43 (registration)
    Registers all tools from marinadeFinanceTools array (including get_msol_balance) to the MCP server using server.registerTool, passing name, metadata/schema, and wrapped callback.
    for (const t of marinadeFinanceTools) {
        server.registerTool(
            t.name,
            {
                title: t.title,
                description: t.description,
                inputSchema: t.inputSchema
            },
            async (args) => {
                const result = await t.callback(args);
                return {
                    content: result.content.map(item => ({
                        ...item,
                        type: "text" as const
                    }))
                };
            }
        );
    }
  • Helper function to create Solana wallet and connection based on environment variables, used by get_msol_balance and other on-chain tools.
    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 };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does without disclosing behavioral traits like rate limits, authentication requirements, error conditions, or what 'environment wallet' means. It's a basic functional description lacking operational context.

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, efficient sentence that front-loads the core purpose and includes all necessary information without any wasted words. Every element earns its place.

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?

For a simple read-only tool with 100% schema coverage but no annotations or output schema, the description is adequate but incomplete. It explains what the tool does but lacks context about the return format, error handling, or what 'environment wallet' entails, leaving gaps for an AI agent.

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 already fully documents the single optional parameter. The description adds minimal value by restating the parameter's purpose but doesn't provide additional syntax, format details, or constraints beyond what's in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Check'), resource ('mSOL token balance'), and scope ('environment wallet or any specified Solana wallet address'), distinguishing it from siblings like send_msol (transfer) or stake_msol (staking operation).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool (checking mSOL balances) and implicitly distinguishes it from siblings by focusing on balance queries rather than transactions or staking. However, it doesn't explicitly mention when NOT to use it or name specific alternatives.

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

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