TRON区块链集成服务

TRON MCP服务器提供与TRON区块链的无缝集成,支持余额查询、交易管理、智能合约交互和实时区块链数据访问等功能。

  • by Netts-official
  • JavaScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 Netts-official/tron_mcp_server

使用说明

TRON MCP服务器

模型上下文协议(MCP)服务器,提供与TRON区块链的无缝集成,使Claude等AI助手能够与TRON网络功能进行交互,包括余额检查、交易管理、智能合约交互和实时区块链数据。

🚀 特性

核心区块链功能

  • 余额管理:检查TRX和TRC20代币余额
  • 交易操作:发送TRX并与智能合约交互
  • 资源管理:监控和管理能源和带宽
  • 智能合约交互:调用合约方法并估算能耗
  • 区块浏览器:查询区块、交易和合同信息

高级功能

  • 智能回退系统:当本地节点不可用时,自动回退到TronGrid/TronScan API
  • 能量估计:对交易进行准确的能耗预测
  • 价格跟踪:实时TRX价格和能源成本计算
  • 网络监控:链参数和网络统计
  • 文档搜索:访问TRON开发人员文档
  • 代码示例:用于常见操作的现成代码片段

🔄 智能回退系统

MCP服务器现在具有一个智能回退系统,可以在数据源之间自动切换:

  1. 主要的,重要的:本地TRON节点(最快、最可靠)
  2. 回退1:TronGridneneneba API(TRON基金会API官方)
  3. 回退2:TronScan API(社区资源管理器API)

优点:

  • ✅ 无需安装本地TRON节点即可工作
  • ✅ 自动故障转移,实现最长正常运行时间
  • ✅ 基于可用性的智能源选择
  • ✅ 使用可用性缓存进行性能优化

支持回退功能:

  • get_balance -TRX余额检查
  • get_account_resources -能源/带宽资源
  • get_transaction -交易详情
  • get_block -块信息
  • get_current_block_number -最新区块编号
  • get_chain_parameters -网络参数
  • contract_call -智能合约交互(通过TronGrid只读)
  • send_trx -TRX传输(通过TronGrid广播)

📋 先决条件

  • Node.js 18或更高版本
  • npm或yarn包管理器
  • TRON钱包地址(用于余额查询)
  • 私钥(可选,仅用于发送交易)
  • TronGridneneneba API密钥(可选,用于更高的速率限制)

🛠️ 安装

快速安装(推荐)

  1. 克隆存储库:
git clone https://github.com/Netts-official/tron_mcp_server.git
cd tron_mcp_server
  1. 运行自动安装程序:
# For Linux/macOS
chmod +x setup.sh
./setup.sh

# For Windows (PowerShell)
.\setup.ps1

# Alternative: Use npm script
npm run install-claude

安装脚本将:

  • ✅ 检查Node.js版本(18+)
  • ✅ 安装 npm 依赖项
  • ✅ 从.env.example.创建.env
  • ✅ 配置Claude CLI(如果已安装)
  • ✅ 配置Claude Desktop(如果已安装)
  • ✅ 测试服务器功能

手动安装

如果您更喜欢手动设置:

  1. 安装依赖项:
npm install
  1. 配置环境变量:
cp .env.example .env
# Edit .env with your configuration
  1. 添加到Claude CLI:
claude mcp add tron -s user -- node $(pwd)/src/index.js
  1. 测试安装:
npm test-server

⚙️ 配置

环境变量

创建一个 .env 根目录中的文件:

# Network Configuration
NETWORK=mainnet

# TRON Node URLs
FULL_NODE_URL=https://api.trongrid.io
SOLIDITY_NODE_URL=https://api.trongrid.io
EVENT_SERVER_URL=https://api.trongrid.io

# Optional: TronGrid API Key
TRONGRID_API_KEY=your-api-key-here

# Optional: Private Key (for sending transactions)
# WARNING: Keep this secure!
PRIVATE_KEY=your-private-key-here

使用自定义节点

如果您运行自己的TRON节点:

FULL_NODE_URL=http://your-full-node:8090
SOLIDITY_NODE_URL=http://your-solidity-node:8091
EVENT_SERVER_URL=http://your-full-node:8090

🚀 快速开始

安装后,重新启动Claude以使用TRON功能:

✅ 如果您使用了自动安装

安装脚本已经配置了所有内容。只需重新启动Claude并尝试:

"What is the current TRX price?"
"Check balance for address TXxx..."
"Estimate energy for USDT transfer"

🔧 手动配置(如果需要)

克劳德桌面

在以下位置编辑配置文件:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json
  • 视窗: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "tron": {
      "command": "node",
      "args": ["/absolute/path/to/tron_mcp_server/src/index.js"],
      "env": {
        "NETWORK": "mainnet",
        "TRONGRID_API_KEY": "your-api-key"
      }
    }
  }
}

Claude CLI

claude mcp add tron -s user -- node /absolute/path/to/src/index.js

光标IDE

添加到您的Cursor settings.json:

{
  "mcp.servers": {
    "tron": {
      "command": "node",
      "args": ["/absolute/path/to/tron_mcp_server/src/index.js"]
    }
  }
}

📚 可用工具

余额和账户工具

get_balance

获取地址的TRX余额

{
  "address": "TRX_ADDRESS_HERE"
}

get_account_resources

获取带宽和能源资源

{
  "address": "TRX_ADDRESS_HERE"
}

智能合约工具

estimate_contract_energy

估算合同执行所需的能源

{
  "contractAddress": "CONTRACT_ADDRESS",
  "functionName": "transfer",
  "parameters": ["TO_ADDRESS", 1000000]
}

get_contract_info

获取详细的合同信息

{
  "contractAddress": "CONTRACT_ADDRESS"
}

区块链数据工具

get_transaction

获取交易详情

{
  "txId": "TRANSACTION_ID"
}

get_block

获取区块信息

{
  "block": "12345678" // block number or hash
}

get_current_block_number

仅获取当前块号(紧凑输出)

{}

API集成工具

trongrid_api_call

直接调用TronGridneneneba API端点

{
  "endpoint": "/wallet/getnowblock",
  "method": "POST",
  "data": {}
}

tronscan_api_call

直接调用TronScan API端点

{
  "endpoint": "/api/block",
  "params": {"sort": "-number", "limit": 1}
}

get_trongrid_block

直接从TronGridneneneba API获取区块信息

{
  "blockNumber": 12345678,
  "onlyNumber": true
}

get_trongrid_account

直接从TronGridneneneba API获取帐户信息

{
  "address": "TRX_ADDRESS_HERE"
}

市场数据工具

get_energy_prices

获取当前能源价格和TRX/USD汇率

{}

💡 使用示例

示例1:检查TRX余额

User: Check the TRX balance of TRX1234567890abcdefghijklmnop
Claude: I'll check the TRX balance for that address.

[Claude uses get_balance tool]

The address has a balance of 1,234.56 TRX (1,234,560,000 SUN).

示例2:估算USDT传输能量

User: How much energy do I need to transfer USDT to a new address?
Claude: I'll estimate the energy needed for a USDT transfer.

[Claude uses estimate_contract_energy tool]

For transferring USDT to a new address (that hasn't held USDT before), 
you'll need approximately 130,285 energy. This accounts for the initial 
storage allocation on the TRON network.

示例3:获取当前能源价格

User: What's the current cost of energy on TRON?
Claude: Let me check the current energy prices.

[Claude uses get_energy_prices tool]

Current energy pricing:
- Energy Price: 420 SUN per unit
- In TRX: 0.00042 TRX per energy unit
- In USD: $0.000042 per energy unit (at TRX price of $0.10)

示例4:获取当前块编号

User: What's the current block number on TRON?
Claude: I'll get the current block number for you.

[Claude uses get_current_block_number tool]

Current block number: 67,891,234
Timestamp: 2024-01-15T10:30:45.123Z
Source: trongrid_api

示例5:直接调用TronGridneneneba API

User: Use TronGrid API to get current block information
Claude: I'll make a direct call to the TronGrid API.

[Claude uses trongrid_api_call with endpoint "/wallet/getnowblock"]

Successfully retrieved current block data directly from TronGrid API:
- Block Number: 74,086,797
- Timestamp: 2024-01-15T10:30:45.123Z
- Transactions: 156

示例6:TronScan API查询

User: Get latest account activity from TronScan for address TXxx...
Claude: I'll query TronScan API for account information.

[Claude uses tronscan_api_call with endpoint "/api/account"]

Account activity retrieved from TronScan:
- Balance: 1,234.56 TRX
- Latest transactions: 25
- Contract interactions: 12

🔧 高级配置

多个API密钥

对于跨多个TronGrid API密钥的负载平衡:

TRONGRID_API_KEY=key1,key2,key3

缓存

启用缓存以获得更好的性能:

ENABLE_CACHE=true
CACHE_TTL=300 # Cache time-to-live in seconds

调试模式

启用详细日志记录:

DEBUG=true

📖 创建CLAUDE.md文件

对于使用此MCP服务器的项目,请创建 CLAUDE.md 项目根目录中的文件,帮助Claude了解如何使用TRON功能:

# TRON Integration Instructions

This project uses the TRON MCP server for blockchain interactions.

## Available TRON Operations

### Checking Balances
Use `get_balance` with any TRON address to check TRX balance.

### Energy Estimation
Use `estimate_contract_energy` before transactions to ensure sufficient energy.

### Smart Contract Interaction
Use `get_contract_info` to understand contract interfaces.

## Best Practices
1. Always estimate energy before sending transactions
2. Check account resources before complex operations
3. Use caching for frequently accessed data

🔄 更新MCP服务器

要将TRON MCP服务器更新到最新版本:

  1. 退出克劳德 (关闭应用程序或在终端中按Ctrl+C)

  2. 导航到项目目录:

cd /path/to/your/mcp-tron-server-github
  1. 初始化Git(如果尚未完成):
# Only run if git is not initialized
git init
git remote add origin https://github.com/Netts-official/tron_mcp_server.git
  1. 拉取最新更改:
git pull origin main
  1. 重新启动Claude:
claude
# or restart Claude Desktop application

替代快速更新:

cd /path/to/your/mcp-tron-server-github && git pull origin main && claude

当Claude重新启动时,MCP服务器将自动使用更新的代码。

🛡️ 安全最佳实践

  1. 从不提交私钥 到版本控制
  2. 对敏感数据使用环境变量
  3. 在生产中实施限速
  4. 尽可能使用只读操作
  5. 操作前验证所有地址
  6. 监控API的使用情况和成本

🐛 故障排除

服务器未启动

# Check Node.js version
node --version # Should be 18+

# Verify dependencies
npm install

# Check environment variables
node -e "console.log(require('dotenv').config())"

连接问题

# Test TRON node connectivity
curl https://api.trongrid.io/wallet/getnowblock

# Check API key validity
curl -H "TRON-PRO-API-KEY: your-key" https://api.trongrid.io/wallet/getnowblock

能量估算误差

  • 确保合同地址有效
  • 检查合同是否在TronScan上经过验证
  • 验证函数名和参数是否与ABI匹配

🤝 贡献

欢迎投稿!拜托:

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 如果适用,添加测试
  5. 提交拉取请求

📄 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

🌟 致谢

  • TRON区块链基础设施基金会
  • MCP协议的拟人化
  • TronWeb for JavaScript SDK
  • 社区贡献者

📞 支持