Skip to main content
Glama
thomasfevre

LayerZero OFT MCP Server

by thomasfevre

bridge-oft

Transfer OFT tokens across blockchain networks using LayerZero protocol. Specify token address, amount, source and destination chains, and receiver address to execute cross-chain bridging.

Instructions

Bridges OFT tokens from one chain to another using LayerZero.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe amount of tokens to bridge (e.g., '100').
extraOptionsNoExtra options for LayerZero message execution (default: '0x').0x
fromChainYesThe source chain name.
receiverAddressYesThe address to receive tokens on the destination chain.
toChainYesThe destination chain name.
tokenAddressYesThe address of the OFT contract on the source chain.

Implementation Reference

  • The core handler function for the 'bridge-oft' tool. It loads the OFT ABI, validates inputs, gets signers and network configs from utils, creates the contract instance, prepares LayerZero send parameters, quotes the fee, executes the send transaction, and returns the transaction details.
    async (params: z.infer<typeof bridgeOftParams>) => {
      try {
        const MyOFT = JSON.parse(await readFile(oftPath, "utf8"));
        const OFT_ABI = MyOFT.abi;
        if (
          OFT_ABI === "ABI_PLACEHOLDER" ||
          OFT_ABI === undefined ||
          OFT_ABI.length === 0
        ) {
          return {
            content: [
              {
                type: "text",
                text: "Error: Placeholder ABI detected. Please replace OFT_ABI in layerzero-mcp.ts with your actual contract ABI to interact with existing contracts.",
              },
            ],
            isError: true,
          };
        }
        if (params.fromChain === params.toChain) {
          return {
            content: [
              {
                type: "text",
                text: "Error: Source and destination chains cannot be the same.",
              },
            ],
            isError: true,
          };
        }
    
        const signer = await getSigner(params.fromChain);
        const fromNetworkConfig = getNetworkConfig(params.fromChain);
        const toNetworkConfig = getNetworkConfig(params.toChain);
    
        // Assuming 18 decimals for OFT amounts. Make this configurable if needed.
        const amountDecimals = 18;
        const amountBigInt = parseUnits(params.amount, amountDecimals);
    
        const contract = new Contract(params.tokenAddress, OFT_ABI, signer);
    
        const formattedReceiverAddress = formatAddressForLayerZero(
          params.receiverAddress
        );
    
        const sendParam = {
          dstEid: toNetworkConfig.lzEid,
          to: formattedReceiverAddress,
          amountLD: amountBigInt,
          minAmountLD: amountBigInt,
          extraOptions: params.extraOptions || "0x",
          composeMsg: "0x",
          oftCmd: "0x",
        };
    
        const [nativeFee, lzFee] = await contract.quoteSend(sendParam, false);
    
        const messagingFee = {
          nativeFee: nativeFee,
          lzTokenFee: 0n,
        };
    
        const tx = await contract.send(
          sendParam,
          messagingFee,
          await signer.getAddress(),
          { value: nativeFee }
        );
    
        await tx.wait();
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  transactionHash: tx.hash,
                  fromChain: params.fromChain,
                  toChain: params.toChain,
                  amountSent: params.amount,
                  sender: await signer.getAddress(),
                  receiver: params.receiverAddress,
                  estimatedNativeFee: formatUnits(nativeFee),
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error: any) {
        console.error("Error bridging OFT:", error);
        return {
          content: [
            {
              type: "text",
              text: `Error: Failed to bridge OFT: ${
                error.message || error.toString()
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • Zod input schema defining parameters for the 'bridge-oft' tool: tokenAddress, amount, fromChain, toChain, receiverAddress, and optional extraOptions.
    const bridgeOftParams = z.object({
      tokenAddress: z
        .string()
        .describe("The address of the OFT contract on the source chain."),
      amount: z.string().describe("The amount of tokens to bridge (e.g., '100')."),
      fromChain: networkEnum.describe("The source chain name."),
      toChain: networkEnum.describe("The destination chain name."),
      receiverAddress: z
        .string()
        .describe("The address to receive tokens on the destination chain."),
      extraOptions: z
        .string()
        .optional()
        .default("0x")
        .describe("Extra options for LayerZero message execution (default: '0x')."),
    });
  • src/index.ts:488-598 (registration)
    Registration of the 'bridge-oft' tool on the MCP server using server.tool(), specifying name, description, input schema, and handler function.
    server.tool(
      "bridge-oft",
      "Bridges OFT tokens from one chain to another using LayerZero.",
      bridgeOftParams.shape,
      async (params: z.infer<typeof bridgeOftParams>) => {
        try {
          const MyOFT = JSON.parse(await readFile(oftPath, "utf8"));
          const OFT_ABI = MyOFT.abi;
          if (
            OFT_ABI === "ABI_PLACEHOLDER" ||
            OFT_ABI === undefined ||
            OFT_ABI.length === 0
          ) {
            return {
              content: [
                {
                  type: "text",
                  text: "Error: Placeholder ABI detected. Please replace OFT_ABI in layerzero-mcp.ts with your actual contract ABI to interact with existing contracts.",
                },
              ],
              isError: true,
            };
          }
          if (params.fromChain === params.toChain) {
            return {
              content: [
                {
                  type: "text",
                  text: "Error: Source and destination chains cannot be the same.",
                },
              ],
              isError: true,
            };
          }
    
          const signer = await getSigner(params.fromChain);
          const fromNetworkConfig = getNetworkConfig(params.fromChain);
          const toNetworkConfig = getNetworkConfig(params.toChain);
    
          // Assuming 18 decimals for OFT amounts. Make this configurable if needed.
          const amountDecimals = 18;
          const amountBigInt = parseUnits(params.amount, amountDecimals);
    
          const contract = new Contract(params.tokenAddress, OFT_ABI, signer);
    
          const formattedReceiverAddress = formatAddressForLayerZero(
            params.receiverAddress
          );
    
          const sendParam = {
            dstEid: toNetworkConfig.lzEid,
            to: formattedReceiverAddress,
            amountLD: amountBigInt,
            minAmountLD: amountBigInt,
            extraOptions: params.extraOptions || "0x",
            composeMsg: "0x",
            oftCmd: "0x",
          };
    
          const [nativeFee, lzFee] = await contract.quoteSend(sendParam, false);
    
          const messagingFee = {
            nativeFee: nativeFee,
            lzTokenFee: 0n,
          };
    
          const tx = await contract.send(
            sendParam,
            messagingFee,
            await signer.getAddress(),
            { value: nativeFee }
          );
    
          await tx.wait();
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  {
                    transactionHash: tx.hash,
                    fromChain: params.fromChain,
                    toChain: params.toChain,
                    amountSent: params.amount,
                    sender: await signer.getAddress(),
                    receiver: params.receiverAddress,
                    estimatedNativeFee: formatUnits(nativeFee),
                  },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (error: any) {
          console.error("Error bridging OFT:", error);
          return {
            content: [
              {
                type: "text",
                text: `Error: Failed to bridge OFT: ${
                  error.message || error.toString()
                }`,
              },
            ],
            isError: true,
          };
        }
      }
    );
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 the basic operation without disclosing critical behavioral traits such as transaction costs, execution time, security implications, error handling, or whether it's a read-only or destructive action.

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, making it highly concise and well-structured.

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?

For a complex tool involving cross-chain token transfers with 6 parameters and no annotations or output schema, the description is insufficient. It lacks details on outcomes, error cases, and operational constraints, leaving significant gaps in understanding.

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 fully documents all parameters. The description adds no additional meaning beyond the schema, maintaining the baseline score of 3 for adequate but not enhanced parameter context.

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 ('bridges'), the resource ('OFT tokens'), and the mechanism ('using LayerZero'), distinguishing it from the sibling tool 'deploy-and-configure-oft-multichain' which appears to be about setup rather than bridging operations.

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?

No guidance is provided on when to use this tool versus alternatives or under what conditions it should be invoked. The description lacks context about prerequisites, constraints, or comparison with the sibling tool.

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/thomasfevre/layerzero_mcp'

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