Skip to main content
Glama
kukapay

bsc-multisend-mcp

distributeToken

Send ERC20 tokens to multiple BSC addresses simultaneously using the C98MultiSend contract for efficient bulk distribution.

Instructions

Send ERC20 tokens to multiple addresses on BSC using the C98MultiSend contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that executes the distributeToken tool. It handles ERC20 token distribution to multiple receivers by validating inputs, fetching token decimals, converting amounts, managing approvals, calling the contract's transferMultiToken method, and returning the transaction result.
    async ({ tokenAddress, receivers, amounts }) => {
      try {
        // Validate inputs
        if (receivers.length !== amounts.length) {
          return {
            content: [{ type: 'text', text: 'Receivers and amounts arrays must have the same length' }],
            isError: true
          };
        }
    
        // Initialize token contract
        const tokenContract = new ethers.Contract(tokenAddress, ERC20_ABI, wallet);
    
        // Query token decimals
        let decimals;
        try {
          decimals = await tokenContract.decimals();
        } catch (error) {
          return {
            content: [{ type: 'text', text: `Invalid ERC20 token: Unable to fetch decimals (${error.message})` }],
            isError: true
          };
        }
    
        // Convert amounts to token units
        const amountsUnits = amounts.map(amount => ethers.parseUnits(amount.toString(), decimals));
    
        // Calculate total amount needed
        const totalAmount = amountsUnits.reduce((sum, amount) => sum + BigInt(amount), BigInt(0));
    
        // Check allowance
        const allowance = await tokenContract.allowance(WALLET_ADDRESS, CONTRACT_ADDRESS);
        if (BigInt(allowance) < totalAmount) {
          // Approve the contract to spend tokens
          try {
            const approveTx = await tokenContract.approve(CONTRACT_ADDRESS, totalAmount, {
              gasLimit: await tokenContract.approve.estimateGas(CONTRACT_ADDRESS, totalAmount)
            });
            await approveTx.wait();
          } catch (error) {
            return {
              content: [{ type: 'text', text: `Failed to approve token spending: ${error.message}` }],
              isError: true
            };
          }
        }
    
        // Prepare and send transaction
        const tx = await contract.transferMultiToken(tokenAddress, receivers, amountsUnits, {
          gasLimit: await contract.transferMultiToken.estimateGas(tokenAddress, receivers, amountsUnits)
        });
    
        // Wait for transaction confirmation
        const receipt = await tx.wait();
    
        return {
          content: [{
            type: 'text',
            text: `Token distribution successful. Tx Hash: ${receipt.hash}`
          }],
          isError: false
        };
      } catch (error) {
        return {
          content: [{ type: 'text', text: `Error executing token distribution: ${error.message}` }],
          isError: true
        };
      }
    }
  • Zod schema for validating inputs to the distributeToken tool: tokenAddress (ERC20 contract), receivers (array of addresses), amounts (array of positive numbers).
    z.object({
      tokenAddress: z.string().refine((val) => ethers.isAddress(val), {
        message: 'Invalid token address'
      }).describe('Address of the ERC20 token contract to distribute.'),
      receivers: z.array(z.string().refine((val) => ethers.isAddress(val), {
        message: 'Invalid BSC address'
      })).describe('Array of BSC addresses to receive tokens.'),
      amounts: z.array(z.number().positive('Amount must be positive')).describe('Array of token amounts (in tokens, e.g., 100.5) to send to each receiver.')
    }),
  • index.js:152-233 (registration)
    Registration of the distributeToken tool on the MCP server, specifying name, description, input schema, and handler function.
    server.tool(
      'distributeToken',
      'Send ERC20 tokens to multiple addresses on BSC using the C98MultiSend contract.',
      z.object({
        tokenAddress: z.string().refine((val) => ethers.isAddress(val), {
          message: 'Invalid token address'
        }).describe('Address of the ERC20 token contract to distribute.'),
        receivers: z.array(z.string().refine((val) => ethers.isAddress(val), {
          message: 'Invalid BSC address'
        })).describe('Array of BSC addresses to receive tokens.'),
        amounts: z.array(z.number().positive('Amount must be positive')).describe('Array of token amounts (in tokens, e.g., 100.5) to send to each receiver.')
      }),
      async ({ tokenAddress, receivers, amounts }) => {
        try {
          // Validate inputs
          if (receivers.length !== amounts.length) {
            return {
              content: [{ type: 'text', text: 'Receivers and amounts arrays must have the same length' }],
              isError: true
            };
          }
    
          // Initialize token contract
          const tokenContract = new ethers.Contract(tokenAddress, ERC20_ABI, wallet);
    
          // Query token decimals
          let decimals;
          try {
            decimals = await tokenContract.decimals();
          } catch (error) {
            return {
              content: [{ type: 'text', text: `Invalid ERC20 token: Unable to fetch decimals (${error.message})` }],
              isError: true
            };
          }
    
          // Convert amounts to token units
          const amountsUnits = amounts.map(amount => ethers.parseUnits(amount.toString(), decimals));
    
          // Calculate total amount needed
          const totalAmount = amountsUnits.reduce((sum, amount) => sum + BigInt(amount), BigInt(0));
    
          // Check allowance
          const allowance = await tokenContract.allowance(WALLET_ADDRESS, CONTRACT_ADDRESS);
          if (BigInt(allowance) < totalAmount) {
            // Approve the contract to spend tokens
            try {
              const approveTx = await tokenContract.approve(CONTRACT_ADDRESS, totalAmount, {
                gasLimit: await tokenContract.approve.estimateGas(CONTRACT_ADDRESS, totalAmount)
              });
              await approveTx.wait();
            } catch (error) {
              return {
                content: [{ type: 'text', text: `Failed to approve token spending: ${error.message}` }],
                isError: true
              };
            }
          }
    
          // Prepare and send transaction
          const tx = await contract.transferMultiToken(tokenAddress, receivers, amountsUnits, {
            gasLimit: await contract.transferMultiToken.estimateGas(tokenAddress, receivers, amountsUnits)
          });
    
          // Wait for transaction confirmation
          const receipt = await tx.wait();
    
          return {
            content: [{
              type: 'text',
              text: `Token distribution successful. Tx Hash: ${receipt.hash}`
            }],
            isError: false
          };
        } catch (error) {
          return {
            content: [{ type: 'text', text: `Error executing token distribution: ${error.message}` }],
            isError: true
          };
        }
      }
    );
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 mentions the action ('Send ERC20 tokens') and contract ('C98MultiSend'), but fails to disclose critical behavioral traits like required permissions, transaction costs, rate limits, error handling, or whether this is a read-only or mutative operation, leaving significant gaps in understanding the tool's behavior.

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 any wasted words. It is front-loaded with the core action and context, making it highly concise and well-structured for quick understanding.

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 token distribution on a blockchain, the lack of annotations, no output schema, and the description's minimal detail, this is incomplete. It doesn't cover return values, error cases, or practical usage nuances, making it insufficient for safe and effective tool invocation in a real-world context.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, meaning no parameters are defined. The description implies parameters related to token distribution (e.g., addresses, amounts) but doesn't specify them, which is acceptable since the schema indicates no parameters are needed. However, this could be confusing if parameters are actually required in practice, warranting a score just below perfect.

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 ('Send ERC20 tokens') and target ('to multiple addresses on BSC using the C98MultiSend contract'), which is specific and actionable. However, it doesn't explicitly differentiate from its sibling 'distributeNative', which likely distributes native BNB instead of ERC20 tokens, leaving some room for improvement in sibling distinction.

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, such as its sibling 'distributeNative'. It lacks explicit instructions on prerequisites, timing, or scenarios where this tool is preferred, offering only a basic functional statement without contextual usage advice.

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/kukapay/bsc-multisend-mcp'

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