一个用于Ergo MCP API响应的标准化工具,它将各种输出格式(JSON、Markdown、纯文本)转换为一致的JSON结构,以提高集成性和易用性。
MCP API返回的响应格式不一致:
这种不一致性使得与其他系统集成变得困难,并且需要针对每个端点进行自定义处理。
MCPResponseStandardizer将所有响应转换为一致的JSON结构:
{
"success": true,
"data": {
// 从原始响应中提取的标准化响应数据
},
"meta": {
"format": "json|markdown|text|mixed",
"endpoint": "endpoint_name",
"timestamp": "ISO-timestamp"
}
}
对于错误响应:
{
"success": false,
"error": {
"code": 400,
"message": "错误信息"
},
"meta": {
"format": "json|markdown|text|mixed",
"endpoint": "endpoint_name",
"timestamp": "ISO-timestamp"
}
}
from mcp_response_standardizer import MCPResponseStandardizer
# 初始化标准化工具
standardizer = MCPResponseStandardizer()
# 标准化响应
endpoint_name = "blockchain_status"
response_content = "..." # 来自MCP API的内容
status_code = 200 # API调用的HTTP状态码
# 获取标准化响应
standardized = standardizer.standardize_response(
endpoint_name,
response_content,
status_code
)
# 访问标准化的数据
if standardized["success"]:
data = standardized["data"]
# 使用标准化的数据...
else:
error = standardized["error"]
print(f"错误 {error['code']}: {error['message']}")
您也可以通过命令行使用标准化工具:
python mcp_response_standardizer.py blockchain_status response.txt
其中:
blockchain_status 是端点名称response.txt 是包含响应内容的文件提供了一个测试脚本 test_standardizer.py,用于演示标准化工具有样本响应:
python test_standardizer.py
该脚本:
sample_responses 目录标准化工具有以下方法:
Ergo Explorer Model Context Protocol (MCP) 是一个全面的服务器,通过标准化接口为AI助手提供了直接访问Ergo区块链数据的能力。
该项目通过以下方式弥合了AI助手与Ergo区块链生态系统之间的差距:
Ergo Explorer MCP中的所有端点都实现了标准化响应格式系统,该系统:
@standardize_response 装饰器进行自动格式转换{
"status": "success", // 或 "error"
"data": {
// 端点特定的结构化数据
},
"metadata": {
"execution_time_ms": 123,
"result_size_bytes": 456,
"is_truncated": false,
"token_estimate": 789
}
}
有关响应标准化的更多信息,请参阅 RESPONSE_STANDARDIZATION.md。
Ergo Explorer MCP通过地址聚类算法提供了先进的实体识别能力。此功能有助于识别可能由同一实体控制的一组地址。
以下端点可用于实体识别:
/address_clustering/identify
/address_clustering/visualize
/address_clustering/openwebui_entity_tool
/address_clustering/openwebui_viz_tool
Ergo Explorer MCP与 Open WebUI 集成,以提供增强的可视化和交互能力:
要识别与地址相关的实体:
from ergo_explorer.api import make_request
# 识别地址的实体
response = make_request("address_clustering/identify", {
"address": "9gUDVVx75KyZ783YLECKngb1wy8KVwEfk3byjdfjUyDVAELAPUN",
"depth": 2,
"tx_limit": 100
})
# 获取地址的可视化
viz_response = make_request("address_clustering/visualize", {
"address": "9gUDVVx75KyZ783YLECKngb1wy8KVwEfk3byjdfjUyDVAELAPUN",
"depth": 2,
"tx_limit": 100
})
# 访问实体集群
entities = response["data"]["clusters"]
for entity_id, entity_data in entities.items():
print(f"实体 {entity_id}: {len(entity_data['addresses'])} 个地址")
print(f"置信度: {entity_data['confidence_score']}")
要使用Open WebUI工具:
[工具: openwebui_entity_tool]
[地址: 9gUDVVx75KyZ783YLECKngb1wy8KVwEfk3byjdfjUyDVAELAPUN]
[深度: 2]
[交易限制: 100]
[工具: openwebui_viz_tool]
[地址: 9gUDVVx75KyZ783YLECKngb1wy8KVwEfk3byjdfjUyDVAELAPUN]
[深度: 2]
[交易限制: 100]
Ergo Explorer MCP内置了代币估算功能,帮助AI助手优化其上下文窗口使用。此功能提供了每种LLM模型响应中的代币数量估计。
tiktoken也能工作代币估算是所有标准化响应的metadata部分的一部分:
{
"status": "success",
"data": {
// 响应数据
},
"metadata": {
"execution_time_ms": 123,
"result_size_bytes": 456,
"is_truncated": false,
"token_estimate": 789,
"token_breakdown": {
"data": 650,
"metadata": 89,
"status": 50
}
}
}
要访问响应中的代币估算:
from ergo_explorer.api import make_request
# 向任何端点发出请求
response = make_request("blockchain/status")
# 访问代币估算信息
token_count = response["metadata"]["token_estimate"]
is_truncated = response["metadata"]["is_truncated"]
print(f"响应大约包含 {token_count} 个代币")
if is_truncated:
print("响应被截断以适应代币限制")
您可以指定用于代币估算的LLM模型类型:
from ergo_explorer.api import make_request
# 请求时指定特定模型类型进行代币估算
response = make_request("blockchain/address_info",
{"address": "9hdcMw4eRpJPJGx8RJhvdRgFRsE1URpQCsAWM3wG547gQ9awZgi"},
model_type="gpt-4")
# 代币估算将基于GPT-4的标记化计算
| 响应类型 | 目标代币范围 | 优化策略 |
|---|---|---|
| 简单查询 | < 500 代币 | 完整响应,无截断 |
| 标准查询 | 500-2000 代币 | 选择性字段包含 |
| 复杂查询 | 2000-5000 代币 | 分页或截断响应 |
| 数据密集型 | > 5000 代币 | 摘要,可选详细信息检索 |
Ergo Explorer MCP包括全面的功能,用于跟踪代币的历史所有权并分析其如何随时间变化:
// 只包含基本参数的简单请求
GET /token/historical_token_holders
{
"token_id": "d71693c49a84fbbecd4908c94813b46514b18b67a99952dc1e6e4791556de413",
"max_transactions": 200
}
响应格式包括详细的代币转移历史和在各个时间点(或区块高度)的代币分布快照。
克隆仓库:
git clone https://github.com/ergo-mcp/ergo-explorer-mcp.git
cd ergo-explorer-mcp
安装依赖项:
pip install -r requirements.txt
配置环境:
# 设置环境变量
export ERGO_EXPLORER_API="https://api.ergoplatform.com/api/v1"
export ERGO_NODE_API="http://your-node-address:9053" # 可选
export ERGO_NODE_API_KEY="your-api-key" # 可选
运行MCP服务器:
python -m ergo_explorer.server
构建Docker镜像:
docker build -t ergo-explorer-mcp .
运行容器:
docker run -d -p 8000:8000 \
-e ERGO_EXPLORER_API="https://api.ergoplatform.com/api/v1" \
-e ERGO_NODE_API="http://your-node-address:9053" \
-e ERGO_NODE_API_KEY="your-api-key" \
--name ergo-mcp ergo-explorer-mcp
要贡献于项目:
pip install -r requirements.txt
pip install -r requirements.test.txt
pytest
有关全面文档,请参阅:
本项目根据MIT许可证发布 - 详情见 LICENSE 文件。