使用说明
mcp服务器沙丘
用于集成AI代理的模型上下文协议(MCP)服务器 沙丘分析 区块链数据。
需求
- Python 3.11+
- 沙丘分析API密钥
特性
工具
- run_query -执行已保存的Dune查询并等待结果
- submit_query -为长时间运行的作业异步提交查询
- 获取执行状态 -检查正在运行的查询的状态
- getexecution_results -从已完成的执行中检索结果
- run_sql -执行原始的即席DuneSQL查询
- create_query -将新查询保存到Dune库
- update_query -修改现有查询
- 归档查询 -将活动工作区中的查询存档
资源(沙丘://方案)
dune://query/{id}/latest-缓存结果(零学分)dune://query/{id}/sql-查询SQL定义dune://execution/{id}/status-执行作业状态
提示
- generate-dune-sql -编写有效DuneSQL的指南
- 分析结果 -查询结果解释指南
安装
# Install from source
pip install -e .
# Or install dependencies directly
pip install fastmcp>=2.0.0 dune-client>=1.10.0 pydantic>=2.0.0
配置
将Dune API密钥设置为环境变量:
# Linux/macOS
export DUNE_API_KEY="your-api-key-here"
# Windows Command Prompt
set DUNE_API_KEY=your-api-key-here
# Windows PowerShell
$env:DUNE_API_KEY="your-api-key-here"
克劳德桌面版
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"dune": {
"command": "python",
"args": ["-m", "mcp_server_dune"],
"env": {
"DUNE_API_KEY": "your-api-key-here"
}
}
}
}
直接执行
# Run the server
python -m mcp_server_dune
使用示例
执行已保存的查询
# Run query ID 123456 with parameters
run_query(
query_id=123456,
params={"token_address": "0x..."},
performance="medium",
limit=50
)
执行特殊SQL
# Run raw DuneSQL
run_sql(
sql="""
SELECT DATE_TRUNC('day', block_time) as day,
COUNT(*) as tx_count
FROM ethereum.transactions
WHERE block_time > NOW() - INTERVAL '7' DAY
GROUP BY 1
ORDER BY 1
LIMIT 100
""",
performance="medium"
)
读取缓存结果(零学分)
访问资源 dune://query/123456/latest 在不消耗执行信用的情况下获得缓存结果。
DuneSQL提示
- 地址是字节数组:使用
0x...直接文字 - 日期间隔:
NOW() - INTERVAL '7' DAY - 更喜欢解码表:
uniswap_v3_ethereum.Factory_evt_PoolCreated - 始终包括
LIMIT防止超时
发展
# Clone the repository
git clone https://github.com/your-org/mcp-server-dune
cd mcp-server-dune
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/macOS
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Run the server locally
python -m mcp_server_dune
许可证
麻省理工学院
