Skip to main content
Glama
leandrogavidia

Marinade Finance MCP Server

Stake SOL for mSOL

stake_msol

Stake SOL tokens to receive mSOL and earn staking rewards through Marinade Finance's liquid staking protocol on Solana.

Instructions

Stake your SOL tokens with Marinade Finance to receive mSOL tokens and earn rewards.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe amount of SOL to stake

Implementation Reference

  • The callback function that implements the stake_msol tool logic: validates balance, creates Marinade instance, calls deposit, sends transaction, and handles errors.
    callback: async ({ amount }: { amount: number }) => {
        try {
            const amountLamports = MarinadeUtils.solToLamports(amount);
    
            const { wallet, connection } = createSolanaConfig()
    
            const balance = await connection.getBalance(wallet.publicKey);
            if (balance < amountLamports) {
                return {
                    content: [
                        {
                            type: "text",
                            text: JSON.stringify({
                                error: "Insufficient balance",
                                reason: `Required: ${amount} SOL (${amountLamports} lamports), Available: ${balance / LAMPORTS_PER_SOL} SOL (${balance} lamports)`
                            }, null, 2),
                        },
                    ],
                };
            }
    
            const config = new MarinadeConfig({
                connection,
                publicKey: wallet.publicKey,
            })
    
            const marinade = new Marinade(config)
    
            const {
                associatedMSolTokenAccountAddress,
                transaction,
            } = await marinade.deposit(amountLamports, {
                mintToOwnerAddress: wallet.publicKey,
            })
    
            const signature = await sendAndConfirmTransaction(connection, transaction, [wallet], {
                commitment: "confirmed",
                preflightCommitment: "processed",
                skipPreflight: false,
                maxRetries: 3,
            })
    
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify({
                            success: true,
                            signature,
                            mSolTokenAccount: associatedMSolTokenAccountAddress,
                            amountStaked: amount,
                            amountStakedLamports: amountLamports.toString(),
                            explorerUrl: `https://solscan.io/tx/${signature}${process.env.ENVIRONMENT === 'MAINNET' ? '' : '?cluster=devnet'}`
                        }, null, 2),
                    },
                ],
            };
    
        } catch (err) {
            const isAbort = (err as Error)?.name === "AbortError";
            const isTimeout = (err as Error)?.message?.includes("timeout");
    
            McpLogger.error("Error in stake_msol tool:", String(err));
    
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify(
                            {
                                error: isAbort || isTimeout ? "Request timed out" : "Failed to stake SOL",
                                reason: String((err as Error)?.message ?? err),
                                suggestion: isAbort || isTimeout ?
                                    "The transaction may still be processing. Check your wallet or try again with a different RPC endpoint." :
                                    "Please check your wallet balance and network connection."
                            },
                            null,
                            2
                        ),
                    },
                ],
            };
        }
    }
  • Zod schema for the input parameter 'amount' of SOL to stake.
    inputSchema: {
        amount: z.number().min(0).describe("The amount of SOL to stake"),
    },
  • src/tools.ts:302-392 (registration)
    The stake_msol tool object definition and registration within the onChainTools array.
        name: "stake_msol",
        title: "Stake SOL for mSOL",
        description: "Stake your SOL tokens with Marinade Finance to receive mSOL tokens and earn rewards.",
        inputSchema: {
            amount: z.number().min(0).describe("The amount of SOL to stake"),
        },
        callback: async ({ amount }: { amount: number }) => {
            try {
                const amountLamports = MarinadeUtils.solToLamports(amount);
    
                const { wallet, connection } = createSolanaConfig()
    
                const balance = await connection.getBalance(wallet.publicKey);
                if (balance < amountLamports) {
                    return {
                        content: [
                            {
                                type: "text",
                                text: JSON.stringify({
                                    error: "Insufficient balance",
                                    reason: `Required: ${amount} SOL (${amountLamports} lamports), Available: ${balance / LAMPORTS_PER_SOL} SOL (${balance} lamports)`
                                }, null, 2),
                            },
                        ],
                    };
                }
    
                const config = new MarinadeConfig({
                    connection,
                    publicKey: wallet.publicKey,
                })
    
                const marinade = new Marinade(config)
    
                const {
                    associatedMSolTokenAccountAddress,
                    transaction,
                } = await marinade.deposit(amountLamports, {
                    mintToOwnerAddress: wallet.publicKey,
                })
    
                const signature = await sendAndConfirmTransaction(connection, transaction, [wallet], {
                    commitment: "confirmed",
                    preflightCommitment: "processed",
                    skipPreflight: false,
                    maxRetries: 3,
                })
    
                return {
                    content: [
                        {
                            type: "text",
                            text: JSON.stringify({
                                success: true,
                                signature,
                                mSolTokenAccount: associatedMSolTokenAccountAddress,
                                amountStaked: amount,
                                amountStakedLamports: amountLamports.toString(),
                                explorerUrl: `https://solscan.io/tx/${signature}${process.env.ENVIRONMENT === 'MAINNET' ? '' : '?cluster=devnet'}`
                            }, null, 2),
                        },
                    ],
                };
    
            } catch (err) {
                const isAbort = (err as Error)?.name === "AbortError";
                const isTimeout = (err as Error)?.message?.includes("timeout");
    
                McpLogger.error("Error in stake_msol tool:", String(err));
    
                return {
                    content: [
                        {
                            type: "text",
                            text: JSON.stringify(
                                {
                                    error: isAbort || isTimeout ? "Request timed out" : "Failed to stake SOL",
                                    reason: String((err as Error)?.message ?? err),
                                    suggestion: isAbort || isTimeout ?
                                        "The transaction may still be processing. Check your wallet or try again with a different RPC endpoint." :
                                        "Please check your wallet balance and network connection."
                                },
                                null,
                                2
                            ),
                        },
                    ],
                };
            }
        }
    },
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 the action and outcome but lacks details on permissions required, transaction costs, time to process, or potential risks (e.g., slashing). This leaves gaps in understanding the tool's behavior beyond the basic operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly explains the tool's purpose without unnecessary words. It is front-loaded with the core action, making it easy to understand quickly, though it could be slightly more structured for complex tools.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a staking operation with no annotations and no output schema, the description is incomplete. It lacks information on return values (e.g., transaction ID, mSOL received), error conditions, or integration details, which are crucial for effective tool use in this 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%, with the 'amount' parameter fully documented in the schema. The description does not add any additional meaning beyond what the schema provides, such as minimum viable amounts or unit clarifications, so it meets the baseline for high schema coverage.

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 ('Stake your SOL tokens') and the resource ('with Marinade Finance'), specifying the outcome ('to receive mSOL tokens and earn rewards'). It distinguishes from siblings like 'unstake_msol' by focusing on staking rather than unstaking, though it doesn't explicitly differentiate from other tools like 'send_msol'.

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?

The description provides no guidance on when to use this tool versus alternatives like 'unstake_msol' or 'send_msol'. It mentions earning rewards, which implies a use case, but lacks explicit when-to-use or when-not-to-use instructions, such as prerequisites or timing considerations.

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