内容
# Arbitrum MCP
MCP 服务器通过 Arbitrum 区块链能力为任何 MCP 兼容的 AI 代理(例如 Claude、Cursor 等)提供工具。
## 功能特点
- **9 种区块链工具**,可通过 MCP 协议访问
- **读取**:以太坊余额、ERC-20 代币余额、ARB 价格、合约读取、交易详情
- **写入**:代币兑换(Relay.link)、跨链桥接(Relay.link)、合约部署、代理注册(ERC-8004)
- **跨链桥接**:从以太坊、Base 或 BSC 桥接到 Arbitrum
- **双网络**:Arbitrum One(主网)+ Arbitrum Sepolia(测试网)
## 技术栈
- **运行时环境**:Cloudflare Workers
- **框架**:Hono
- **协议**:MCP 流式 HTTP
- **区块链**:viem
- **跨链桥**:Relay.link
## 安装技能
```bash
npx skills add https://github.com/starc007/arbitrum-mcp --skill arbitrum-mcp
```
## 快速开始
```bash
# 安装
bun install
# 本地运行
bun run dev
# 部署
bun run deploy
```
## 配置
### 必需
将您的钱包私钥设置为 Cloudflare Worker 机密:
```bash
bunx wrangler secret put PRIVATE_KEY
```
### 可选
这些在 `wrangler.toml` 中有默认值,可以被覆盖:
| 变量 | 默认值 | 描述 |
| --- | --- | --- |
| `ARBITRUM_RPC_URL` | `https://arb1.arbitrum.io/rpc` | Arbitrum One RPC |
| `ARBITRUM_SEPOLIA_RPC_URL` | `https://sepolia-rollup.arbitrum.io/rpc` | Arbitrum Sepolia RPC |
| `ETH_RPC_URL` | `https://0xrpc.io/eth` | 以太坊 L1 RPC(用于桥接) |
| `ETH_SEPOLIA_RPC_URL` | `https://eth-sepolia-testnet.api.pocket.network` | Sepolia L1 RPC(用于桥接) |
| `BASE_RPC_URL` | `https://base.api.pocket.network` | Base RPC(用于桥接) |
| `BSC_RPC_URL` | `https://public-bsc-mainnet.fastnode.io` | BSC RPC(用于桥接) |
## 工具列表
| 工具 | 描述 | 是否需要私钥 |
| --- | --- | --- |
| `get_eth_balance` | 获取任意地址的以太坊余额 | |
| `get_token_balance` | 获取 ERC-20 代币余额,包含符号和小数点 | |
| `get_arb_price` | 从 Chainlink 预言机获取 ARB/USD 价格 | |
| `read_contract` | 调用任意只读合约函数 | |
| `get_transaction` | 获取交易详情和回执哈希 | |
| `swap_tokens` | 通过 Relay.link 在 Arbitrum 上兑换任意代币对 | 是 |
| `bridge_to_arbitrum` | 通过 Relay.link 从以太坊/Base/BSC 桥接到 Arbitrum | 是 |
| `deploy_contract` | 从字节码部署合约 | 是 |
| `register_agent` | 在 ERC-8004 身份注册表中注册 | 是 |
## 代理注册
在 Arbitrum 身份注册表(ERC-8004)中注册您的代理:
```bash
# 创建 .env 文件并填写您的私钥
cp .env.example .env
# 在 Sepolia 上运行注册
bun run register
```
注册地址:
- **Arbitrum One**:`0x8004A169FB4a3325136EB29fA0ceB6D2e539a432`
- **Arbitrum Sepolia**:`0x8004A818BFB912233c491871b3d84c89A494BD9e`
## 项目结构
```
arbitrum-mcp/
├── src/
│ ├── index.ts # Hono 应用 + MCP 端点
│ ├── server.ts # MCP 服务器 + 工具注册
│ ├── tools/
│ │ ├── balance.ts # get_eth_balance, get_token_balance
│ │ ├── price.ts # get_arb_price
│ │ ├── contract.ts # read_contract
│ │ ├── transaction.ts # get_transaction
│ │ ├── swap.ts # swap_tokens
│ │ ├── bridge.ts # bridge_to_arbitrum
│ │ ├── deploy.ts # deploy_contract
│ │ └── registry.ts # register_agent
│ └── lib/
│ ├── clients.ts # viem 客户端工厂
│ └── constants.ts # 地址、ABI、链配置
├── scripts/
│ └── register-agent.ts # 独立注册脚本
├── skills/
│ └── arbitrum-mcp/
│ └── SKILL.md # MCP 技能文档
├── wrangler.toml
└── package.json
```
## MCP 端点
```
POST /mcp
Headers:
Content-Type: application/json
Accept: application/json, text/event-stream
```
服务器使用 MCP 流式 HTTP 传输。连接任意 MCP 兼容的客户端到 `https://your-worker.workers.dev/mcp`。
## 许可证
MIT