Skip to main content
Glama

pancakeAddLiquidity

Enable liquidity provision on PancakeSwap by specifying token pairs and amounts through the BSC MCP Server for secure and structured Binance Smart Chain transactions.

Instructions

add liquidity to pancake

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
token0Yes
token0AmountYes
token1Yes
token1AmountYes

Implementation Reference

  • MCP tool handler logic for 'Add_PancakeSwap_Liquidity': fetches tokens and account, prepares CurrencyAmounts, calls addLiquidityV3, handles success/error with transaction URL.
    async ({ token0, token1, token0Amount, token1Amount }) => {
    
        let txHash = undefined;
        try {
        
            // Define tokens
            const tokenA = await getToken(token0);
            const tokenB = await getToken(token1);
        
            // Amounts to add
            const amountTokenA = CurrencyAmount.fromRawAmount(tokenA, parseUnits(token0Amount, tokenA.decimals).toString());
            const amountTokenB = CurrencyAmount.fromRawAmount(tokenB, parseUnits(token1Amount, tokenB.decimals).toString());
        
            const account = await getAccount();
    
            txHash = await addLiquidityV3(
                tokenA,
                tokenB,
                FeeAmount.MEDIUM, // 0.3%
                amountTokenA,
                amountTokenB,
                account,
            );
    
            const txUrl = await checkTransactionHash(txHash)
            return {
                content: [
                    {
                        type: "text",
                        text: `add liquidity to pancake successfully. ${txUrl}`,
                        url: txUrl,
                    },
                ],
            };
        } catch (error) {
            const errorMessage =
                error instanceof Error ? error.message : String(error);
            const txUrl = buildTxUrl(txHash);
            return {
                content: [
                    {
                        type: "text",
                        text: `transaction failed: ${errorMessage}`,
                        url: txUrl,
                    },
                ],
                isError: true,
            };
        }
  • Zod input schema defining the parameters for the pancakeAddLiquidity tool: token addresses and amounts as strings.
        token0: z.string(),
        token1: z.string(),
        token0Amount: z.string(),
        token1Amount: z.string(),
    },
  • Registration function for the pancakeAddLiquidity tool, called from main.ts, which sets up the tool name, description, schema, and handler on the McpServer.
    export function registerPancakeAddLiquidity(server: McpServer) {
    
        server.tool("Add_PancakeSwap_Liquidity", "💧Provide liquidity to PancakeSwap trading pairs", {
                token0: z.string(),
                token1: z.string(),
                token0Amount: z.string(),
                token1Amount: z.string(),
            },
            async ({ token0, token1, token0Amount, token1Amount }) => {
    
                let txHash = undefined;
                try {
                
                    // Define tokens
                    const tokenA = await getToken(token0);
                    const tokenB = await getToken(token1);
                
                    // Amounts to add
                    const amountTokenA = CurrencyAmount.fromRawAmount(tokenA, parseUnits(token0Amount, tokenA.decimals).toString());
                    const amountTokenB = CurrencyAmount.fromRawAmount(tokenB, parseUnits(token1Amount, tokenB.decimals).toString());
                
                    const account = await getAccount();
    
                    txHash = await addLiquidityV3(
                        tokenA,
                        tokenB,
                        FeeAmount.MEDIUM, // 0.3%
                        amountTokenA,
                        amountTokenB,
                        account,
                    );
    
                    const txUrl = await checkTransactionHash(txHash)
                    return {
                        content: [
                            {
                                type: "text",
                                text: `add liquidity to pancake successfully. ${txUrl}`,
                                url: txUrl,
                            },
                        ],
                    };
                } catch (error) {
                    const errorMessage =
                        error instanceof Error ? error.message : String(error);
                    const txUrl = buildTxUrl(txHash);
                    return {
                        content: [
                            {
                                type: "text",
                                text: `transaction failed: ${errorMessage}`,
                                url: txUrl,
                            },
                        ],
                        isError: true,
                    };
                }
            }
        );
    }
  • Core helper function addLiquidityV3 that executes the V3 liquidity provision: approves tokens, checks balances, sorts tokens, retrieves pool, computes ticks and position, mints LP position.
    export async function addLiquidityV3(
        tokenA: Currency,
        tokenB: Currency,
        fee: FeeAmount,
        amountA: CurrencyAmount<Currency>,
        amountB: CurrencyAmount<Currency>,
        account: PrivateKeyAccount,
        slippageTolerance: Percent = new Percent('50', '10000'), // default 0.5%
        deadline: number = Math.floor(Date.now() / 1000) + 20 * 60, // default 20 minutes
        priceLower: number = 0.8,
        priceUpper: number = 1.2
    ): Promise<Hex> {
        
    
        await Promise.all([
            approveTokensIfNeeded(account, tokenA, POSITION_MANAGER_ADDRESS, amountA.quotient.toString()),
            approveTokensIfNeeded(account, tokenB, POSITION_MANAGER_ADDRESS, amountB.quotient.toString()),
        ]);
    
        await checkBalance(account, tokenA, amountA)
        await checkBalance(account, tokenB, amountB)
    
        const [token0, token1, amount0, amount1] = sortTokens(tokenA, tokenB, amountA, amountB);
    
        const poolAddress = await publicClient.readContract({
            address: FACTORY_ADDRESS,
            abi: FACTORY_ABI,
            functionName: 'getPool',
            args: [
                token0.address as Address,
                token1.address as Address,
                fee
            ]
        }) as Address;
    
        if (!poolAddress || poolAddress === '0x0000000000000000000000000000000000000000') {
            throw new Error(`Pool for ${tokenA.symbol}/${tokenB.symbol} not found`);
        }
    
        const [liquidity, slot0] = await Promise.all([
            publicClient.readContract({
                address: poolAddress,
                abi: POOL_ABI,
                functionName: 'liquidity'
            }),
            publicClient.readContract({
                address: poolAddress,
                abi: POOL_ABI,
                functionName: 'slot0'
            })
        ]);
    
        const pool = new Pool(
            token0,
            token1,
            fee,
            (slot0 as any)[0].toString(), // sqrtPriceX96
            liquidity.toString(),
            (slot0 as any)[1] // tick
        );
        // Retrieve tickSpacing from the SDK constants
        const tickSpacing = TICK_SPACINGS[fee]; // fee should correspond to a valid
        // Convert prices to square root ratio and then to ticks
        const priceLowerRatio = encodeSqrtRatioX96(priceLower * 1e18, 1e18);
        const priceUpperRatio = encodeSqrtRatioX96(priceUpper * 1e18, 1e18);
        const lowerPriceTick = TickMath.getTickAtSqrtRatio(priceLowerRatio);
        const upperPriceTick = TickMath.getTickAtSqrtRatio(priceUpperRatio);
        // Round ticks to the nearest valid tick
        const tickLower = nearestUsableTick(lowerPriceTick, tickSpacing);
        const tickUpper = nearestUsableTick(upperPriceTick, tickSpacing);
    
    
        const position = Position.fromAmounts({
            pool,
            tickLower,
            tickUpper,
            amount0: amount0.quotient.toString(),
            amount1: amount1.quotient.toString(),
            useFullPrecision: true
        });
    
        const { amount0: amount0Min, amount1: amount1Min } = position.mintAmountsWithSlippage(slippageTolerance);
    
        const value = tokenA.isNative
            ? amountA.quotient.toString()
            : tokenB.isNative
                ? amountB.quotient.toString()
                : '0';
    
        const mintParams = {
            token0: token0.address as Address,
            token1: token1.address as Address,
            fee,
            tickLower,
            tickUpper,
            amount0Desired: BigInt(amount0.quotient.toString()),
            amount1Desired: BigInt(amount1.quotient.toString()),
            amount0Min: BigInt(amount0Min.toString()),
            amount1Min: BigInt(amount1Min.toString()),
            recipient: account.address,
            deadline: BigInt(deadline)
        };
    
        const hash = await walletClient(account).writeContract({
            address: POSITION_MANAGER_ADDRESS,
            abi: POSITION_MANAGER_ABI,
            functionName: 'mint',
            args: [mintParams],
            value: BigInt(value),
            account: account
        });
        return hash;
    }
  • src/main.ts:33-33 (registration)
    Top-level call to register the pancakeAddLiquidity tool in the main server setup.
    registerPancakeAddLiquidity(server);
  • src/main.ts:13-13 (registration)
    Import of the registerPancakeAddLiquidity function.
    import { registerPancakeAddLiquidity } from "./tools/pancakeAddLiquidity.js";
Behavior1/5

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

No annotations are provided, so the description must fully disclose behavioral traits. It only states the action without details on permissions, rate limits, side effects, or response format. For a financial tool like adding liquidity, this lack of transparency on risks or outcomes is inadequate.

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

Conciseness3/5

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

The description is concise with a single phrase, but it is under-specified rather than efficiently informative. It lacks front-loaded detail and wastes an opportunity to clarify purpose or usage, making it minimally structured but not helpful.

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

Completeness1/5

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

Given the complexity of a DeFi liquidity tool, no annotations, no output schema, and 0% schema coverage, the description is severely incomplete. It fails to address critical aspects like transaction behavior, error handling, or return values, making it inadequate for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, with 4 parameters undocumented in the schema. The description adds no meaning beyond the schema, failing to explain what token0, token1, token0Amount, and token1Amount represent or their expected formats, leaving parameters semantically unclear.

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

Purpose2/5

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

The description 'add liquidity to pancake' restates the tool name 'pancakeAddLiquidity' with minimal elaboration, making it tautological. It specifies the action ('add liquidity') and target ('pancake'), but lacks detail on what 'pancake' refers to (likely PancakeSwap) or what 'liquidity' entails, offering only basic purpose without distinguishing from siblings like pancakeSwap or pancakeRemovePosition.

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

Usage Guidelines1/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. It does not mention prerequisites, context, or exclusions, nor does it differentiate from sibling tools such as pancakeSwap or pancakeRemovePosition, leaving the agent with no usage instructions.

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

Related 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/TermiX-official/bsc-mcp'

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