tron-event-mcp
Enables natural-language-driven on-chain data analysis for TRON blockchain events via MongoDB, allowing AI assistants to query blocks, transactions, contract events, and perform analytics like aggregations, histograms, and address profiling.
README
tron-event-mcp
TRON blockchain event data query MCP Server — let AI assistants analyze on-chain data directly.
Works with event-plugin: event-plugin writes TRON on-chain events into MongoDB in real time, and this project exposes that data to AI assistants (Claude, Cursor, etc.) via the Model Context Protocol (MCP), enabling natural-language-driven on-chain data analysis.
Data Source
event-plugin listens to a Java-tron node and writes the following 7 event types into MongoDB:
| Collection | Description | Unique Index |
|---|---|---|
block |
Block event, triggered for every new block | blockNumber |
transaction |
Transaction event, triggered for every packaged transaction | transactionId |
contractevent |
Contract event, triggered when a smart contract emits an event (ABI-decoded) | uniqueId |
contractlog |
Contract raw log, not ABI-decoded (hex data) | uniqueId |
solidity |
Solidity trigger, fired when a block is finalized | latestSolidifiedBlockNumber |
solidityevent |
Solidified contract event, same structure as contractevent |
uniqueId |
soliditylog |
Solidified contract raw log, same structure as contractlog |
uniqueId |
Available Tools
Metadata
| Tool | Description |
|---|---|
describe_schema |
Return field descriptions, index info, and business meaning for all collections |
get_collection_stats |
Return document count and earliest/latest timestamps per collection |
Query
| Tool | Description |
|---|---|
search_contract_activity |
Query events/logs for a specific contract, with event name and time range filters |
query_events |
General-purpose query with arbitrary filters and field projection |
count_events |
Quickly count documents matching given criteria |
get_block |
Look up a block by height |
get_transaction |
Look up a transaction by hash |
Aggregation & Analytics
| Tool | Description |
|---|---|
aggregate_field |
Compute sum / avg / min / max on a specified field |
group_by_field |
Group-by aggregation for address rankings, event distribution, etc. |
aggregate_by_time |
Time-series aggregation (hour / day / week) with optional sum field |
get_top_contracts |
Leaderboard of most active contracts in a time range |
Cross-Collection
| Tool | Description |
|---|---|
get_transaction_full |
Full transaction view: details + associated contract events |
get_address_profile |
Address activity profile across sender, receiver, and contract caller roles |
Distribution Analysis
| Tool | Description |
|---|---|
histogram |
Numeric field bucketing with auto or manual boundaries |
percentiles |
Compute percentiles (P50 / P90 / P95 / P99, etc.) |
Recommended Indexes
event-plugin itself only creates unique indexes (for data deduplication/upsert). To get optimal query performance with this MCP Server's analytics tools, add the following indexes to MongoDB:
// contractevent (highest query volume)
db.contractevent.createIndex({ contractAddress: 1, eventName: 1, timeStamp: -1 });
db.contractevent.createIndex({ contractAddress: 1, timeStamp: -1 });
db.contractevent.createIndex({ timeStamp: -1 });
// solidityevent
db.solidityevent.createIndex({ contractAddress: 1, eventName: 1, timeStamp: -1 });
db.solidityevent.createIndex({ contractAddress: 1, timeStamp: -1 });
db.solidityevent.createIndex({ timeStamp: -1 });
// transaction
db.transaction.createIndex({ timeStamp: -1 });
db.transaction.createIndex({ result: 1 });
// block
db.block.createIndex({ timeStamp: -1 });
// contractlog / soliditylog
db.contractlog.createIndex({ contractAddress: 1, timeStamp: -1 });
db.soliditylog.createIndex({ contractAddress: 1, timeStamp: -1 });
The create_index.js file in the project root contains the complete index creation script (unique + analytics indexes). Run it directly:
mongosh mongodb://host:27017/tron create_index.js
Quick Start
Prerequisites
- Python >= 3.11
- MongoDB >= 7.0 (the
percentilestool uses the$percentileaggregation operator, which requires 7.0+; all other tools work with 5.0+)
Installation
cd tron-event-mcp
make setup
Configuration
Edit the .env file (make setup copies it from .env.example automatically):
# MongoDB connection (strongly recommended to use a read-only user)
MONGO_URI=mongodb://readonly_user:password@host:27017/dbname?authSource=admin
MONGO_DB=tron
# Maximum documents per query (prevents fetching massive datasets)
MAX_RESULT_LIMIT=500
# Query timeout in milliseconds
QUERY_TIMEOUT_MS=10000
Running
# stdio mode (for local clients like Claude Code, Cursor, etc.)
make run
# SSE mode (for remote access)
make run-sse
Integration with Claude Code
Add the following to your Claude Code MCP configuration:
{
"mcpServers": {
"tron-events": {
"command": "/path/to/tron-event-mcp/.venv/bin/python",
"args": ["-m", "tron_event_mcp"]
}
}
}
Integration with Cursor
In Cursor Settings > MCP, add the same configuration as above.
Usage Examples
Once connected, you can ask questions in natural language:
- "What are the most active contracts in the last 24 hours?"
- "Show me the hourly USDT Transfer event volume trend"
- "Analyze the on-chain activity of address TXxx..."
- "What does the energy consumption distribution look like for transactions?"
- "Show me the full details of transaction abc123..."
The AI assistant will automatically select the right combination of tools to answer.
Project Structure
tron-event-mcp/
├── src/tron_event_mcp/
│ ├── server.py # MCP Server entry point; registers all tools and resources
│ ├── config.py # Configuration management (env vars / .env)
│ ├── db/ # MongoDB connection and query layer
│ ├── tools/
│ │ ├── schema.py # describe_schema, get_collection_stats
│ │ ├── query.py # get_recent_events, get_block, get_transaction, query_events
│ │ ├── analytics.py # search_contract_activity, aggregate_field, group_by_field, etc.
│ │ ├── cross_collection.py # get_transaction_full, get_address_profile
│ │ └── distribution.py # histogram, percentiles
│ └── resources/ # MCP Resources (documentation resources)
├── tests/
├── pyproject.toml
├── Makefile
└── .env.example
Security Notes
- Use a read-only MongoDB user — this tool only performs queries, no write access needed
- Query filters forbid
$where,$function,$accumulatorand other code-execution operators MAX_RESULT_LIMITcaps documents per request, protecting database performanceQUERY_TIMEOUT_MSenforces query timeout, preventing slow queries from blocking
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。