MCP 服务器 - 集群 API v1
这是 Clusters API v1 的模型上下文协议 (MCP) 服务器实现。它提供了身份验证、集群管理、名称注册等端点。
依赖项
{
"@modelcontextprotocol/sdk": "^1.7.0",
"dotenv": "^16.4.7",
"zod": "^3.24.2"
}
设置
- 安装依赖项:
- 创建一个
.env
文件,其中包含以下内容:CLUSTERS_API_KEY={CLUSTERS_API_KEY} - 构建并启动服务器:
测试端点
由于此服务器使用StdioServerTransport
,因此您需要通过 stdin 发送 JSON-RPC 消息。以下是用于测试每个端点的示例命令:
身份验证端点
获取消息
echo '{"jsonrpc":"2.0","id":1,"method":"auth_get_message","params":{"address":"0x123...","chainId":1,"nonce":"abc123"}}' | node dist/index.js
获取令牌
echo '{"jsonrpc":"2.0","id":1,"method":"auth_get_token","params":{"signature":"0x123...","signingDate":"2024-03-21","type":"evm","wallet":"0x123..."}}' | node dist/index.js
验证令牌
echo '{"jsonrpc":"2.0","id":1,"method":"auth_validate_token","params":{"authKey":"your-auth-key"}}' | node dist/index.js
集群管理端点
创建集群
echo '{"jsonrpc":"2.0","id":1,"method":"create_cluster","params":{"wallets":[{"address":"0x123...","name":"MyWallet","isPrivate":false}],"authKey":"your-auth-key","testnet":false}}' | node dist/index.js
通过 ID 获取集群
echo '{"jsonrpc":"2.0","id":1,"method":"get_cluster_by_id","params":{"id":"cluster-id","testnet":false}}' | node dist/index.js
通过名称获取集群
echo '{"jsonrpc":"2.0","id":1,"method":"get_cluster_by_name","params":{"name":"cluster-name","testnet":false}}' | node dist/index.js
通过地址获取集群ID
echo '{"jsonrpc":"2.0","id":1,"method":"get_cluster_id_by_address","params":{"address":"0x123...","testnet":false}}' | node dist/index.js
添加钱包
echo '{"jsonrpc":"2.0","id":1,"method":"add_wallets","params":{"wallets":[{"address":"0x123...","name":"NewWallet","isPrivate":false}],"authKey":"your-auth-key","testnet":false}}' | node dist/index.js
生成钱包
echo '{"jsonrpc":"2.0","id":1,"method":"generate_wallet","params":{"type":"evm","name":"NewWallet","isPrivate":false,"authKey":"your-auth-key","testnet":false}}' | node dist/index.js
更新钱包
echo '{"jsonrpc":"2.0","id":1,"method":"update_wallets","params":{"wallets":[{"address":"0x123...","name":"UpdatedName"}],"authKey":"your-auth-key","testnet":false}}' | node dist/index.js
移除钱包
echo '{"jsonrpc":"2.0","id":1,"method":"remove_wallets","params":{"addresses":["0x123..."],"authKey":"your-auth-key","testnet":false}}' | node dist/index.js
验证钱包
echo '{"jsonrpc":"2.0","id":1,"method":"verify_wallet","params":{"clusterId":"cluster-id","authKey":"your-auth-key","testnet":false}}' | node dist/index.js
地址 ↔ 名称解析端点
通过地址获取数据
echo '{"jsonrpc":"2.0","id":1,"method":"get_data_by_address","params":{"address":"0x123...","testnet":false}}' | node dist/index.js
通过地址获取批量数据
echo '{"jsonrpc":"2.0","id":1,"method":"get_bulk_data_by_addresses","params":{"addresses":["0x123...","0x456..."],"testnet":false}}' | node dist/index.js
根据名称获取批量数据
echo '{"jsonrpc":"2.0","id":1,"method":"get_bulk_data_by_names","params":{"names":[{"name":"name1"}],"testnet":false}}' | node dist/index.js
注册端点
检查名称是否可用
echo '{"jsonrpc":"2.0","id":1,"method":"check_name_availability","params":{"names":["name1","name2"]}}' | node dist/index.js
获取注册标志数据
echo '{"jsonrpc":"2.0","id":1,"method":"get_registration_sign_data","params":{"network":"1","sender":"0x123...","names":[{"name":"name1","amountWei":"1000000000000000000"}],"referralClusterId":"optional-id","testnet":false}}' | node dist/index.js
获取交易状态
echo '{"jsonrpc":"2.0","id":1,"method":"get_transaction_status","params":{"txHash":"0x123..."}}' | node dist/index.js
笔记
- 用实际值替换占位符值(如
0x123...
、 your-auth-key
等) - 对于大多数端点来说,
testnet
参数是可选的 - 所有响应都将采用 JSON-RPC 2.0 格式
- 对于经过身份验证的端点,请确保获取并包含有效的
authKey
- 服务器使用环境变量进行配置,请确保您的
.env
文件已正确设置
替代测试方法
为了方便测试,您可以修改服务器,使用 HTTP 传输协议而非 stdio。这样您就可以使用 curl 命令代替 echo 管道。如果您想切换到 HTTP 传输协议,请告诉我。