层次推理模型服务器

一个基于DeepMind研究的层次推理模型(HRM)的模型上下文协议(MCP)服务器,提供战略规划、战术执行和任务分解功能,适用于复杂问题解决和软件开发。

  • by aortegamel
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Angleito/hrmmcp

使用说明

受人力资源管理启发的MCP服务器

受DeepMind对分层问题解决和双系统推理的研究启发,实现分层推理模型的MCP(模型上下文协议)服务器。

🚀 快速开始

安装(3个简单步骤)

# 1. Clone the repository
git clone https://github.com/Angleito/hrmmcp.git
cd hrmmcp

# 2. Install dependencies (auto-detects Python)
chmod +x install-auto.sh
./install-auto.sh

# 3. Configure Claude Code
chmod +x configure-claude.sh
./configure-claude.sh

就是这样! 重新启动Claude Code,人力资源管理推理工具将可用。

没有Python 3.11+? 这 install-auto.sh 脚本将帮助您使用自动安装 uv.

📦 替代安装方法

方法1:直接使用Python

# Install with pip
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

# Configure Claude
python3 configure_claude.py

方法2:手动配置

  1. 安装依赖项:
uv sync  # or: pip install mcp pydantic aiosqlite pyyaml
  1. 增添 ~/.claude.json:
{
  "mcpServers": {
    "hrm-reasoning": {
      "command": "uv",
      "args": ["run", "--project", "/path/to/hrmmcp", "python", "-m", "src.hrm_mcp_server"],
      "cwd": "/path/to/hrmmcp"
    }
  }
}

方法3:项目级配置

存储库包括 .mcp.json 用于自动项目级配置。当您在Claude Code中打开此项目时,它将自动检测并使用HRM MCP服务器。

🛠️ MCP工具

安装后,这些工具在Claude Code中可用:

  • hierarchical_reason -使用双H/L模块方法的主要推理工具

    • H-Module的战略规划
    • 使用L模块进行战术执行
    • 自动收敛检测
  • decompose_task -将复杂任务分解为分层子任务

    • 智能任务分解
    • 依赖追踪
    • 复杂性估计
  • refine_solution -迭代改进现有解决方案

    • 目标导向的改进
    • 收敛监测
    • 质量指标
  • analyze_reasoning_trace -分析推理模式和瓶颈

    • 性能分析
    • 模式识别
    • 优化建议

💡 使用示例

在Claude Code中,您可以使用自然语言:

"Use hierarchical reasoning to design a REST API for a library management system"

"Decompose the task of building a real-time chat application"

"Refine this solution to improve performance and maintainability"

"Analyze the reasoning trace for implementing a caching system"

⚙️ 配置

编辑 config.yaml 自定义:

server:
  max_concurrent_sessions: 10
  session_timeout_minutes: 30

reasoning:
  h_module:
    max_iterations: 10
    min_confidence_threshold: 0.7
  l_module:
    max_cycles_per_h: 6
    min_cycles_per_h: 3
  convergence:
    global_threshold: 0.85

persistence:
  database_path: "hrm_reasoning.db"
  retention_days: 7

🧪 发展

类型检查

uv run mypy src/

运行测试

uv run pytest tests/ -v

手动测试

# Test the MCP server
echo '{"jsonrpc": "2.0", "method": "initialize", "params": {"protocolVersion": "1.0.0", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0"}}, "id": 1}' | uv run python -m src.hrm_mcp_server

📋 需求

  • Python 3.11+ (安全性和MCP兼容性要求)
  • 克劳德代码(支持MCP)
  • uv(推荐)或pip

安全说明:最新的安全补丁和完整的MCP协议支持需要Python 3.11+。旧版本可能存在已知漏洞。

🏗️ 建筑

HRM MCP服务器采用双模块架构:

  • H-Module(战略):高层规划、目标分解、战略决策
  • L模块(战术):低级执行、局部优化、迭代细化
  • 收敛检测:监测本地和全球趋同情况
  • 状态管理:基于SQLite的持久性和会话生命周期管理

📄 许可证

麻省理工学院

🤝 贡献

欢迎投稿!请确保:

  • 所有测试均通过(uv run pytest)
  • 类型检查通过(uv run mypy src/)
  • 代码遵循现有模式

🐛 故障排除

服务器无法在Claude代码中连接

  1. 检查安装: ./install.sh
  2. 验证配置: cat ~/.claude.json | grep hrm-reasoning
  3. 手动测试: uv run python -m src.hrm_mcp_server
  4. 重新启动Claude代码

依赖关系问题

# Clean install
rm -rf .venv
./install.sh

权限不足

chmod +x install.sh configure-claude.sh

📚 了解更多