Skip to main content
Glama
leandrogavidia

Marinade Finance MCP Server

Unstake mSOL

unstake_msol

Convert mSOL tokens back to SOL tokens through Marinade Finance's liquid staking protocol. Specify the amount to unstake.

Instructions

Unstake your mSOL tokens with Marinade Finance to receive SOL tokens.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe amount of mSOL to unstake

Implementation Reference

  • The handler callback for the 'unstake_msol' tool. It performs liquid unstaking of mSOL to SOL using the Marinade SDK: creates config and connection, calls liquidUnstake, sends and confirms the transaction, returns success details or error.
    callback: async ({ amount }: { amount: number }) => {
        try {
            const amountLamports = MarinadeUtils.solToLamports(amount);
    
            const { wallet, connection } = createSolanaConfig()
    
            const config = new MarinadeConfig({
                connection,
                publicKey: wallet.publicKey,
            })
    
            const marinade = new Marinade(config)
    
            const {
                associatedMSolTokenAccountAddress,
                transaction,
            } = await marinade.liquidUnstake(amountLamports)
    
            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,
                            amountUnstaked: amount,
                            amountUnstakedLamports: 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 input schema for 'unstake_msol' tool defining the required 'amount' parameter as a positive number.
    inputSchema: {
        amount: z.number().min(0).describe("The amount of mSOL to unstake"),
    },
  • src/server.ts:25-43 (registration)
    Generic registration loop that registers the 'unstake_msol' tool (and others) with the MCP server using the name, schema, and wrapped callback from tools.ts.
    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 configuration from environment variables, used in the unstake_msol 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 };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the action and outcome but lacks details on behavioral traits such as transaction costs, time delays, irreversible nature, or error conditions. This is a significant gap for a financial transaction tool with no annotation coverage.

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 directly states the tool's purpose without unnecessary words. It is front-loaded and appropriately sized for the tool's complexity.

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 financial unstaking operation, no annotations, and no output schema, the description is incomplete. It lacks critical context such as return values, error handling, or operational constraints, which are essential for safe usage.

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 single parameter 'amount' documented as 'The amount of mSOL to unstake'. The description adds no additional parameter semantics beyond what the schema provides, so the baseline score of 3 is appropriate.

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 ('Unstake') and resource ('mSOL tokens') with the specific service provider ('Marinade Finance') and outcome ('receive SOL tokens'). It distinguishes from siblings like 'stake_msol' by indicating the reverse operation, though it doesn't explicitly contrast with 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 Guidelines3/5

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

The description implies usage when you want to convert mSOL back to SOL, but it doesn't provide explicit guidance on when to use this tool versus alternatives (e.g., 'send_msol' for transferring mSOL, 'stake_msol' for staking SOL). No prerequisites or exclusions are mentioned.

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