关于 MCP Ethereum Address Info Server
MCP Ethereum Address Info Server 用于查询多个链上的 Ethereum 地址信息,并提供 SSE 地址更新推送。它适合需要订阅地址变化的 MCP 客户端。
主要功能
- 01查询多链 Ethereum 地址信息
- 02通过 SSE 接收实时更新
- 03订阅和取消订阅地址
- 04查看连接的 SSE 客户端
适用场景
- 01监控指定地址的更新
- 02将地址变化推送给已连接客户端
MCP 相关
该 MCP 服务提供地址信息查询工具,并通过 SSE 让客户端订阅地址更新。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
MCP Ethereum 地址信息服务
此服务使用 Model Context Protocol(MCP)提供多个链上的 Ethereum 地址信息。它包含一个用于实时更新的 Server-Sent Events(SSE)端点。
目录
设置
-
克隆仓库:
git clone <repository-url> cd mcp-0x-address -
安装依赖项:
npm install -
创建
.env文件并填入以下变量:MCP_PORT=3002
运行服务
启动 HTTP MCP 服务:
npm run start:http
这将在端口 3002 上启动服务(或使用 .env 文件中指定的端口)。
可用端点
此服务提供以下端点:
GET /health- 服务运行状况检查POST /mcp- 用于工具调用的 MCP 端点GET /sse- 用于实时更新的 Server-Sent Events 端点GET /sse/clients- 获取已连接 SSE 客户端的信息POST /sse/subscribe/:clientId- 订阅地址更新POST /sse/unsubscribe/:clientId- 取消订阅地址更新
使用 SSE 端点
SSE 端点允许客户端接收来自服务的实时更新。使用方法如下:
- 连接到 SSE 端点
- 从连接响应中获取客户端 ID
- 订阅特定地址
- 接收这些地址的实时更新
使用 Curl 测试
1. 连接到 SSE 端点
curl -N http://localhost:3002/sse
这将与 SSE 端点建立连接并开始接收事件。连接会保持打开状态,直到你手动终止它。
2. 检查已连接的客户端
curl http://localhost:3002/sse/clients
3. 订阅地址更新
连接到 SSE 端点后,你会收到一个客户端 ID。使用该 ID 订阅地址更新:
curl -X POST \
http://localhost:3002/sse/subscribe/YOUR_CLIENT_ID \
-H "Content-Type: application/json" \
-d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e", "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"]}'
将 YOUR_CLIENT_ID 替换为你连接到 SSE 端点时收到的客户端 ID。
4. 取消订阅地址更新
curl -X POST \
http://localhost:3002/sse/unsubscribe/YOUR_CLIENT_ID \
-H "Content-Type: application/json" \
-d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}'
5. 触发地址更新
如需触发地址更新(并将其发送给已订阅的客户端),请调用 get-address-info 工具:
curl -X POST \
http://localhost:3002/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get-address-info",
"arguments": {
"address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
}
}
}'
6. 检查服务运行状况
curl http://localhost:3002/health
7. 测试 Ping 工具
curl -X POST \
http://localhost:3002/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "ping",
"arguments": {}
}
}'
示例工作流
以下是测试 SSE 功能的完整工作流:
-
启动服务:
npm run start:http -
在新终端中连接到 SSE 端点:
curl -N http://localhost:3002/sse你会收到类似以下内容的响应:
data: {"type":"connection","clientId":"client-1234567890abcdef","message":"Connected to MCP SSE endpoint","timestamp":"2023-01-01T00:00:00.000Z"} -
记下响应中的
clientId。 -
在另一个终端中订阅地址更新:
curl -X POST \ http://localhost:3002/sse/subscribe/client-1234567890abcdef \ -H "Content-Type: application/json" \ -d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}' -
触发地址更新:
curl -X POST \ http://localhost:3002/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get-address-info", "arguments": { "address": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e" } } }' -
在连接到 SSE 端点的终端中,你会看到该地址的更新。
自动化测试脚本
如需进行更自动化的测试,可以使用以下 bash 脚本:
#!/bin/bash
# Start SSE connection in the background and capture the output
curl -N http://localhost:3002/sse > sse_output.txt &
SSE_PID=$!
# Wait a moment for the connection to establish
sleep 2
# Extract the client ID from the output
CLIENT_ID=$(grep -o '"clientId":"[^"]*"' sse_output.txt | head -1 | cut -d'"' -f4)
if [ -z "$CLIENT_ID" ]; then
echo "Failed to get client ID"
kill $SSE_PID
exit 1
fi
echo "Connected with client ID: $CLIENT_ID"
# Subscribe to an address
curl -X POST \
http://localhost:3002/sse/subscribe/$CLIENT_ID \
-H "Content-Type: application/json" \
-d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}'
echo "Subscribed to address. Waiting for updates..."
echo "Press Ctrl+C to stop"
# Keep the script running to see updates
tail -f sse_output.txt
# Clean up on exit
trap "kill $SSE_PID; rm sse_output.txt" EXIT
将其保存为 test_sse.sh,使用 chmod +x test_sse.sh 赋予可执行权限,然后运行 ./test_sse.sh。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。