内存存储系统

一个基于MCP(模型上下文协议)的分层内存存储系统,允许AI助手以树状结构存储、检索和组织记忆,并跟踪元数据。

  • by gstiebler
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 gstiebler/h-memory-mcp-server

使用说明

内存MCP服务器

作为MCP(模型上下文协议)服务器构建的分层内存存储系统。该服务器允许AI助手在具有元数据跟踪的树状结构中存储、检索和组织内存。

特性

  • 分级组织:记忆以树形结构组织,每个记忆都可以有子记忆
  • 基于位置的导航:使用路径式位置系统访问存储器(例如。, ["projects", "mcp", "features"])
  • 元数据:每个存储器包括:
    • 唯一ID
    • 描述(短标识符)
    • 内容(可选详细文本)
    • 分类标签
    • 作者信息
    • 创建和更新时间戳
    • 访问跟踪(计数和上次访问时间)
  • 永久存储:内存存储在JSON文件中,以便跨会话持久化
  • 线程安全操作:所有操作对于并发访问都是线程安全的

安装

此项目使用 uv 用于Python包管理。

先决条件

设置

  1. 克隆存储库:
git clone <repository-url>
cd memory-mcp-server
  1. 使用uv安装依赖项:
uv sync

用法

运行服务器

要运行MCP服务器,请执行以下操作:

uv run -m src.server

与克劳德融合

  1. 复制 claude_mcp_config.json 到您的Claude配置目录
  2. 更新 cwd 配置中的路径与安装路径匹配
  3. 重新启动Claude以加载新的MCP服务器

可用操作

添加内存

在指定位置添加新内存:

add_memory(position=["projects"], description="mcp", content="MCP development notes", tags=["development"], author="user")

读存储器

阅读记忆的详细信息(没有孩子):

read_memory(position=["projects", "mcp"])

列出孩子

在以下位置列出所有儿童记忆:

list_children(position=["projects"])

编辑内存

更新内存的属性:

edit_memory(position=["projects", "mcp"], content="Updated MCP notes", tags=["development", "protocol"])

删除内存

删除内存及其所有子项:

remove_memory(position=["projects", "mcp"])

发展

使用Mise进行任务管理

该项目包括 mise.toml 为常见开发操作提供方便任务的配置文件:

# Install mise (if not already installed)
# See https://mise.jdx.dev for installation instructions

# Run all checks (format, lint, type check)
mise run check

# Run all tests
mise run test

# Run tests with coverage
mise run test-cov

# Auto-fix formatting and linting issues
mise run fix

# Run all checks and tests
mise run all

# Run individual tasks
mise run format      # Format code with ruff
mise run lint        # Run ruff linter
mise run mypy        # Run type checker

# Development server
mise run dev         # Run the MCP server

# Clean generated files
mise run clean

代码质量

该项目使用自动化工具来维护代码质量:

用Ruff打闹

# Run ruff linter
uv run ruff check

# Auto-fix issues
uv run ruff check --fix

# Format code
uv run ruff format

使用MyPy进行类型检查

# Run type checker
uv run mypy src/ tests/

持续集成

该项目包括在每次推送和拉取请求时自动运行的GitHub Actions:

  • 代码格式检查(ruff格式)
  • 绒毛(褶皱检查)
  • 类型检查(mypy)

运行测试

该项目包括对所有组件的全面测试:

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run specific test file
uv run pytest tests/test_models.py

# Run with coverage report
uv run pytest --cov=src

# Run tests and show print statements
uv run pytest -s

测试套件包括:

  • 模型试验:数据结构验证和序列化
  • 储存测试:CRUD操作、持久性和线程安全
  • 服务器测试:MCP工具功能行为和集成

测试文件位于 tests/ 目录:

  • test_models.py -内存数据模型测试
  • test_memory_store.py -存储操作测试
  • test_server.py -MCP服务器功能测试

开发模式

要在自动重新加载的开发模式下运行:

uv run --reload -m src.server

存储格式

记忆存储在 memories.json 具有以下结构:

{
  "id": "uuid",
  "description": "root",
  "content": "Root of all memories",
  "tags": [],
  "author": "system",
  "created_at": "2025-01-09T10:00:00",
  "access_count": 0,
  "last_accessed": "2025-01-09T10:00:00",
  "children": [
    {
      "id": "uuid",
      "description": "projects",
      "content": null,
      "tags": ["category"],
      "author": "user",
      "created_at": "2025-01-09T10:05:00",
      "access_count": 5,
      "last_accessed": "2025-01-09T11:00:00",
      "children": []
    }
  ]
}

许可证

MIT许可证