帽子协议MCP服务器
一个全面的模型上下文协议(MCP)服务器,用于管理Hats协议操作,包括角色管理、权限检查、组织结构和跨多个区块链网络的分析。
特性
- 帽子管理:创建、铸造、烧制和转移帽子
- 树木操作:管理分层组织结构
- 权限检查:验证佩戴者、站立和资格
- 元数据操作:更新帽子详细信息和属性
- 查询工具:使用GraphQL子图搜索和过滤帽子
- 分析:生成报告并跟踪活动
- 多链支持:适用于所有Hats协议网络
- 外部签名:为硬件钱包签名准备交易
支持的网络
主网
- 以太坊
- 多边形
- Arbitrum One
- 乐观主义
- 基础
- Gnosis链
测试
- Sepolia
- 基础Sepolia
安装
# Clone the repository
git clone
cd mcp-hats-protocol-server
# Install dependencies
npm install
# Build the project
npm run build配置
环境变量
复制 .env.template 向 .env 并配置:
# RPC Provider API Keys (optional - uses public endpoints if not provided)
ALCHEMY_API_KEY=your_key_here
INFURA_API_KEY=your_key_here
# Block Explorer API Keys (required for contract verification)
ETHERSCAN_API_KEY=your_key_here
POLYGONSCAN_API_KEY=your_key_here
# ... other explorer keysAPI密钥管理
您还可以使用MCP工具设置API密钥:
{
"tool": "set-api-key",
"args": {
"keyName": "ALCHEMY_API_KEY",
"value": "your_key_here"
}
}用法
与Claude Code集成
使用此MCP服务器的最简单方法是将其与Claude Code集成。安装服务器后,将其添加到Claude配置中:
快速设置
# Clone and install the server
git clone https://github.com/your-username/mcp-hats
cd mcp-hats
npm install
npm run build
# Add to Claude Code (with optional API key for better performance)
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:团队/项目配置
# For team sharing via .mcp.json
claude mcp add --scope project hats-protocol --env ALCHEMY_API_KEY=your_key_here -- node dist/index.js
# For user-wide access across all projects
claude mcp add --scope user hats-protocol --env ALCHEMY_API_KEY=your_key_here -- node dist/index.js管理集成
# List all MCP servers
claude mcp list
# View server details
claude mcp get hats-protocol
# Remove the server
claude mcp remove hats-protocolClaude代码中的环境变量
添加服务器时,可以设置API密钥:
claude mcp add hats-protocol \
--env ALCHEMY_API_KEY=your_alchemy_key \
--env ETHERSCAN_API_KEY=your_etherscan_key \
-- node dist/index.js手动服务器使用
如果您更喜欢手动运行服务器(用于开发或独立使用):
# Development mode
npm run dev
# Production mode
npm start使用Claude代码
集成后,您可以在与Claude的对话中直接使用帽子协议工具:
示例:检查某人是否有角色
Check if address 0x742C3cF9Af45f91B109a81EfEaf11535ECDe9571 is wearing hat 0x0000000100010000000000000000000000000000000000000000000000000000 on Ethereum示例:创建新组织
Help me create a new DAO called "TechCollective" on Base Sepolia with myself (0x742C3cF9Af45f91B109a81EfEaf11535ECDe9571) as the founder示例:分析组织结构
Show me the organizational structure for tree 0x00000001 on Base and visualize it as an ASCII tree示例:获取角色分配指导
I need to assign the CTO role to a new team member. Can you guide me through the process and prepare the transaction?克劳德将自动使用适当的帽子协议工具,并通过内置的提示和资源提供智能指导。
可用工具
帽子管理
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": "Engineering Team Lead",
"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 # Entry point
├── server.ts # MCP server setup
├── types/ # TypeScript definitions
├── utils/ # Utility functions
├── networks/ # Network configurations
├── clients/ # Hats SDK and subgraph clients
├── tools/ # MCP tool implementations
└── resources/ # MCP resources
test/
├── unit/ # Unit tests
├── integration/ # Integration tests
└── e2e/ # End-to-end tests运行测试
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test suites
npm run test:unit
npm run test:integration
npm run test:e2e代码质量
# Type checking
npm run typecheck
# Linting
npm run lint
# Formatting
npm run format建筑
核心组件
- MCP服务器:处理工具注册和请求路由
- 帽子客户:围绕帽子协议SDK的包装
- 子图客户端:用于查询索引数据的GraphQL客户端
- 网络管理器:多链配置和RPC管理
- 工具实施:用于特定操作的单个工具
数据流
- MCP客户端发送工具请求→ MCP服务器
- 服务器使用Zod模式验证输入
- 工具实现调用适当的客户端方法
- 客户端与区块链或子图交互
- 响应已格式化并返回给MCP客户端
资源
贡献
- 创建要素分支
- 为新功能编写测试
- 确保所有测试通过
- 提交带有详细描述的拉取请求
许可证
麻省理工学院
