MCP Ethereum Address Info Server

MCP Ethereum Address Info Server

使用模型上下文协议,跨多个链提供以太坊地址的实时信息,并具有用于实时更新的服务器发送事件 (Server-Sent Events) 端点。

Category
访问服务器

README

MCP 以太坊地址信息服务器

该服务器使用模型上下文协议 (MCP) 提供跨多个链的以太坊地址信息。它包括一个服务器发送事件 (SSE) 端点,用于实时更新。

目录

设置

  1. 克隆存储库:

    git clone <repository-url>
    cd mcp-0x-address
    
  2. 安装依赖项:

    npm install
    
  3. 创建一个包含以下变量的 .env 文件:

    MCP_PORT=3002
    

运行服务器

启动 HTTP MCP 服务器:

npm run start:http

这将在端口 3002(或您的 .env 文件中指定的端口)上启动服务器。

可用端点

服务器提供以下端点:

  • GET /health - 服务器健康检查
  • POST /mcp - 用于工具调用的 MCP 端点
  • GET /sse - 用于实时更新的服务器发送事件端点
  • GET /sse/clients - 获取有关已连接 SSE 客户端的信息
  • POST /sse/subscribe/:clientId - 订阅地址更新
  • POST /sse/unsubscribe/:clientId - 取消订阅地址更新

使用 SSE 端点

SSE 端点允许客户端从服务器接收实时更新。以下是如何使用它:

  1. 连接到 SSE 端点
  2. 从连接响应中获取您的客户端 ID
  3. 订阅特定地址
  4. 接收这些地址的实时更新

使用 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 功能的完整工作流程:

  1. 启动服务器:

    npm run start:http
    
  2. 在新的终端中,连接到 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"}
    
  3. 记下响应中的 clientId

  4. 在另一个终端中,订阅地址更新:

    curl -X POST \
      http://localhost:3002/sse/subscribe/client-1234567890abcdef \
      -H "Content-Type: application/json" \
      -d '{"addresses": ["0x742d35Cc6634C0532925a3b844Bc454e4438f44e"]}'
    
  5. 触发地址更新:

    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. 在您连接到 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 运行它。

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选