一个全面的模型上下文协议(MCP)服务器,用于管理Hats Protocol操作,包括角色管理、权限检查、组织结构以及跨多个区块链网络的分析。
# 克隆仓库
git clone <repository-url>
cd mcp-hats-protocol-server
# 安装依赖
npm install
# 构建项目
npm run build
复制 .env.template 到 .env 并进行配置:
# RPC提供程序API密钥(可选 - 如果未提供,则使用公共端点)
ALCHEMY_API_KEY=your_key_here
INFURA_API_KEY=your_key_here
# 区块浏览器API密钥(合约验证所需)
ETHERSCAN_API_KEY=your_key_here
POLYGONSCAN_API_KEY=your_key_here
# ...其他浏览器密钥
您也可以使用MCP工具设置API密钥:
{
"tool": "set-api-key",
"args": {
"keyName": "ALCHEMY_API_KEY",
"value": "your_key_here"
}
}
最简单的方式是将其与Claude Code集成。安装服务器后,将其添加到您的Claude配置中:
# 克隆并安装服务器
git clone https://github.com/your-username/mcp-hats
cd mcp-hats
npm install
npm run build
# 添加到Claude Code(可选API密钥以提高性能)
claude mcp add hats-protocol --env ALCHEMY_API_KEY=your_key_here -- node dist/index.js
选项1:本地开发(无需构建)
claude mcp add hats-protocol --env ALCHEMY_API_KEY=your_key_here -- npx tsx src/index.ts
选项2:全局NPM安装(如果已发布)
claude mcp add hats-protocol --env ALCHEMY_API_KEY=_your_key_here -- npx mcp-hats-protocol
选项3:团队/项目配置
# 通过.mcp.json共享团队
claude mcp add --scope project hats-protocol --env ALCHEMY_API_KEY=your_key_here -- node dist/index.js
# 跨所有项目访问用户范围
claude mcp add --scope user hats-protocol --env ALCHEMY_API_KEY=your_key_here -- node dist/index.js
# 列出所有MCP服务器
claude mcp list
# 查看服务器详情
claude mcp get hats-protocol
# 移除服务器
claude mcp remove hats-protocol
添加服务器时可以设置API密钥:
claude mcp add hats-protocol \
--env ALCHEMY_API_KEY=your_alchemy_key \
--env ETHERSCAN_API_KEY=your_etherscan_key \
-- node dist/index.js
如果您希望手动运行服务器(用于开发或独立使用):
# 开发模式
npm run dev
# 生产模式
npm start
一旦集成,您可以在与Claude的对话中直接使用Hats Protocol工具:
检查地址0x742C3cF9Af45f91B109a81EfEaf11535ECDe9571在Ethereum上是否佩戴了帽子0x0000000100010000000000000000000000000000000000000000000000000000
帮我创建一个名为“TechCollective”的DAO在Base Sepolia上,我自己(0x742C3cF9Af45f91B109a81EfEaf11535ECDe9571)作为创始人
显示Base上的树0x00000001的组织结构,并将其可视化为ASCII树
我需要将CTO角色分配给新团队成员。你能引导我完成这个过程并准备交易吗?
Claude将自动使用适当的Hats Protocol工具并通过内置提示和资源提供智能指导。
create-hat - 在层级中创建新的帽子mint-hat - 将帽子分配给佩戴者burn-hat - 从佩戴者处移除帽子transfer-hat - 在佩戴者之间转移帽子check-hat-wearer - 验证地址是否佩戴特定帽子check-hat-standing - 检查佩戴者是否处于良好状态get-hat-details - 获取帽子的详细信息query-hats-by-wearer - 获取地址佩戴的所有帽子get-tree-structure - 获取分层树结构list-networks - 列出所有支持的网络set-api-key - 配置API密钥{
"tool": "create-hat",
"args": {
"networkName": "ethereum",
"admin": "0x0000000100000000000000000000000000000000000000000000000000000000",
"details": "工程团队负责人",
"maxSupply": 1,
"eligibility": "0x0000000000000000000000000000000000000000",
"toggle": "0x0000000000000000000000000000000000000000",
"mutable": true,
"imageURI": "https://example.com/hat-image.png"
}
}
{
"tool": "check-hat-wearer",
"args": {
"networkName": "ethereum",
"wearer": "0x742C3cF9Af45f91B109a81EfEaf11535ECDe9571",
"hatId": "0x0000000100010000000000000000000000000000000000000000000000000000"
}
}
src/
├── index.ts # 入口点
├── server.ts # MCP服务器设置
├── types/ # TypeScript定义
├── utils/ # 工具函数
├── networks/ # 网络配置
├── clients/ # Hats SDK和子图客户端
├── tools/ # MCP工具实现
└── resources/ # MCP资源
test/
├── unit/ # 单元测试
├── integration/ # 集成测试
└── e2e/ # 端到端测试
# 运行所有测试
npm test
# 运行带有覆盖率的测试
npm run test:coverage
# 运行特定测试套件
npm run test:unit
npm run test:integration
npm run test:e2e
# 类型检查
npm run typecheck
# 代码检查
npm run lint
# 格式化
npm run format
MIT