mcpField
L
Layer2 MCP Server

Layer2 MCP Server

本地服务
github.com/anylots金融数据185 周前更新

关于 Layer2 MCP Server

Layer2 MCP Server 为 Ethereum Layer 2 网络提供区块链交互接口,面向需要让 AI 模型执行链上开发和交易操作的场景。它涵盖代币部署、转账及跨链支持。

主要功能

  1. 01部署 ERC20 代币合约
  2. 02转账 ETH 与 ERC20 代币
  3. 03批量转账以供测试和模拟
  4. 04支持 L1 结算与数据可用性验证
  5. 05支持跨链操作

适用场景

  1. 01部署新的 ERC20 代币
  2. 02向指定地址转账 ETH 或代币
  3. 03模拟批量代币转账
  4. 04在 AI 工作流中执行 Layer 2 区块链操作

MCP 相关

该 MCP 服务向 AI 客户端提供与 Ethereum Layer 2 网络交互的工具,包括部署代币、转账及批量转账。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Layer2 MCP Server MCP 实现

用于开发和使用以太坊 Layer 2 网络的模型上下文协议服务,提供标准化接口,让 AI 模型能够与区块链网络交互、部署代币并管理交易。

概述

MCP Layer2 服务实现了 Model Context Protocol 规范,为 AI 模型提供以下工具:

  1. 基础
  • 部署新的 ERC20 代币合约
  • 向指定地址转账 ETH
  • 向指定地址转账 ERC20 代币
  • 向随机地址执行批量转账,用于测试和模拟
  1. 进阶
  • L1 结算与数据可用性验证
  • 支持跨链

此实现使 AI 助手能够通过标准化协议直接与区块链网络交互,从而更轻松地将区块链功能集成到 AI 工作流中。

使用示例

以下是 AI 助手使用这些工具的示例:

  1. 部署新的 ERC20 代币合约:

    👤You: Deploy a new ERC20 token
    
    🤖AI: I'll deploy a new ERC20 token contract for you.
    [Tool call: deployToken]
    Result: Token deployed successfully!
            Contract Address: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
            Transaction Hash: 0xd4ec9bf7ca67a581e78a8637974cd84c9c3524a75efe8851b808f0d58879ebd9
    
  2. 向某个地址转账代币:

    👤You: Transfer 100 erc20 tokens to the address 0x6ea5e8971eC8cf32d43AeB18a6999aFc3a3ec65d
    
    🤖AI: I need to deploy an ERC20 token contract before I can transfer 100 ERC20 tokens to a specified address.
    [Tool call: deployToken]
    Result: Token deployed successfully!
            Contract Address: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
            Transaction Hash: 0xd4ec9bf7ca67a581e78a8637974cd84c9c3524a75efe8851b808f0d58879ebd9
    
    🤖AI: Now I will use the ERC20 token contract I just deployed to transfer 100 tokens to the address 0x6ea5e8971eC8cf32d43AeB18a6999aFc3a3ec65d.
    
    [Tool call: transferToken with tokenAddress=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512, 
                targetAddress=0x6ea5e8971eC8cf32d43AeB18a6999aFc3a3ec65d]
                
    🤖AI: ERC20 token transfer has been successfully completed!
    Details:
    Token contract address: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
    Receiving address: 0x6ea5e8971eC8cf32d43AeB18a6999aFc3a3ec65d
    Transfer transaction hash: 0x82b7bdc69ffebfc946ab5101cf853a06e64d5aceaf96ca4fe70622fcee89d83e
    The token has been successfully transferred to the specified address. Do you need to perform other operations?
    
  3. 向某个地址转账 ETH:

    🤖AI: I'll transfer 10 ETH to the specified address.
    [Tool call: transferETH with targetAddress=0x6ea5e8971eC8cf32d43AeB18a6999aFc3a3ec65d, amount=10]
    Result: ETH transfer successful!
            Transaction Hash: 0x9f46076f1c9b84d49c7314d8b8586e20c5c5b389ec56931e510408b3f6052bac
    
  4. 执行批量转账:

    🤖AI: I'll execute 100 token transfers over 10 seconds.
    [Tool call: batchTransfer with tokenAddress=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512, 
                transactionCount=100, durationSeconds=10]
    Result: Batch transfer initiated!
            Processing 100 transactions over 10 seconds.
    

安装

# Clone the repository
git clone https://github.com/anylots/layer2-mcp.git
cd layer2-mcp

# Install dependencies
npm install

# Build the project
npm run build

使用方法

配置

在根目录中创建 .env 文件,并添加以下变量:

PRIVATE_KEY=your_ethereum_private_key
ETH_L2_RPC=your_layer2_rpc_url
与 Cursor 搭配使用

在 Cursor MCP 设置面板中添加一个 command 类型的 MCP 服务,并填写执行命令,例如:node \\wsl.localhost\Ubuntu-22.04\root\xxxx\xxxx\layer2-dev\build\index.js

与 Claude Desktop 搭配使用
  1. 安装 Claude Desktop
  2. 使用以下配置添加新的 MCP 服务:
     "layer2-mcp": {
       "command": "node",
       "args": [
         "/path-to-layer2-mcp/build/src/index.js"
       ],
       "env": {
         "PRIVATE_KEY": "<<your eth-wallet private key>>",
         "ETH_L2_RPC": "<<The layer2 chain rpc you want to interact with>>"
       }
     }
    
  3. 现在,这些工具将在 Claude 对话中可用
使用 MCP Inspector 进行测试
  1. 安装 MCP Inspector:

    npm install -g @modelcontextprotocol/inspector
    
  2. 启动服务:

    npm start
    
  3. 在另一个终端中运行检查器:

    mcp-inspector
    
  4. 在浏览器中打开 http://localhost:5173,与这些工具交互

可用工具

代币操作
  • deployToken:部署新的 ERC20 代币合约

    • 返回合约地址和交易哈希
  • transferETH:向指定地址转账 ETH

    • 参数:
      • targetAddress:接收 ETH 的地址
      • amount:要转账的 ETH 数量(1 = 1 ETH)
    • 返回交易哈希
  • transferToken:向指定地址转账代币

    • 参数:
      • tokenAddress:已部署的 ERC20 代币合约地址
      • targetAddress:接收代币的地址
    • 返回交易哈希
  • batchTransfer:向随机地址执行批量转账

    • 参数:
      • tokenAddress:已部署的 ERC20 代币合约地址
      • transactionCount:要执行的交易数量
      • durationSeconds:批量操作的总时长(秒)
    • 在指定时间段内执行指定数量的交易

网络支持

此服务可配置为适用于任何兼容以太坊的网络,包括:

  • Ethereum 主网
  • Layer 2 网络(Optimism、Arbitrum 等)
  • 本地开发网络(Hardhat、Ganache)

将 ETH_L2_RPC 环境变量设为相应的 RPC URL,即可配置网络。

开发

# Install dependencies
npm install

# Run in development mode
npm run dev

# Build
npm run build

# Start the server
npm start

贡献

欢迎在 GitHub 上提交问题和拉取请求。

许可证

本项目采用 ISC License 许可,详情请参阅 LICENSE 文件。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。