AI内存管理系统

MCP Memory Server是一个基于模型上下文协议(MCP)的分层内存管理系统,为AI代理提供智能存储、检索和会话间上下文及知识生命周期管理。

  • by insomnolence
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 insomnolence/mcp-memory-server

使用说明

MCP内存服务器

使用模型上下文协议(MCP)的AI代理的分层内存管理系统。跨会话提供会话上下文和知识的智能存储、检索和生命周期管理。

特性

  • 三层内存架构:短期、长期和永久记忆收集
  • 智能文档评分:基于内容、新近度和访问模式的多因素重要性计算
  • 高级重复数据删除:具有可配置阈值和领域感知的语义相似性检测
  • 生命周期管理:基于TTL的自动清理,具有重要性加权老化
  • 查询性能监控:实时指标和性能分析
  • Chunk关系跟踪:维护文档片段之间的关系
  • FastAPI集成:具有全面MCP工具的RESTful API
  • 综合测试:带有pytest集成的完整测试套件

快速开始

先决条件

  • Python 3.8+
  • 点

安装

# Clone the repository
git clone <repository-url>
cd mcp-memory-server

# Install dependencies
pip install -r requirements.txt

# Run configuration wizard
python scripts/config_wizard.py

# Start the server
python scripts/start_server.py

测试

# Run all tests
pytest -v

# Run specific test categories
pytest tests/unit/ -v          # Unit tests only
pytest tests/integration/ -v   # Integration tests only

配置

交互式设置

配置向导为常见用例提供指导设置:

python scripts/config_wizard.py           # Interactive setup
python scripts/config_wizard.py template  # Template-based setup

手动配置

配置文件存储在 config/:

  • config.example.json -完整的配置模板
  • config/domains/ -域特定配置

建筑

内存层

  1. 短期记忆 -最近的互动和临时背景
  2. 长期记忆 -延长保留期的重要信息
  3. 永久存储器 -批判性知识无限期保存

重要性评分

使用多种因素对文档进行评分:

  • 语义分析 -内容相关性和意义
  • 近期加权 -基于时间的重要性衰减
  • 访问模式 -检索频率
  • 域模式 -可配置的关键字匹配

重复数据删除系统

  • 语义相似度检测 -防止重复存储
  • 内容合并 -智能地组合相似的文档
  • 域感知阈值 -每种内容类型的相似性要求不同
  • 性能跟踪 -监控重复数据消除的有效性

MCP工具API

文档管理

  • add_document -使用自动重要性评分存储内容
  • query_documents -重新排序的语义搜索
  • query_permanent_documents -仅搜索永久内容

系统监控

  • get_memory_stats -收集统计数据和健康指标
  • get_lifecycle_stats -TTL和老化系统状态
  • get_deduplication_stats -重复数据消除性能指标
  • get_query_performance -查询延迟和有效性
  • get_real_time_metrics -实时系统性能数据

高级功能

  • deduplicate_memories -手动重复数据删除触发器
  • cleanup_expired_memories -强制清理过期内容
  • get_chunk_relationships -分析文档关系
  • get_system_health_assessment -综合系统健康

项目结构

mcp-memory-server/
├── src/mcp_memory_server/      # Core server implementation
│   ├── analytics/              # Intelligence and analytics
│   ├── config/                 # Configuration management  
│   ├── deduplication/          # Duplicate detection system
│   ├── memory/                 # Hierarchical memory management
│   ├── server/                 # FastAPI server and handlers
│   └── tools/                  # MCP tools implementation
├── tests/                      # Comprehensive test suite
│   ├── unit/                   # Unit tests
│   ├── integration/            # Integration tests  
│   └── performance/            # Performance tests
├── config/                     # Configuration files
├── scripts/                    # Management utilities
├── client-examples/            # Client integration examples
└── docs/                       # Documentation

测试基础设施

该项目包括一个全面的测试框架:

  • 总共111次测试:全面覆盖功能
  • 单元测试:使用模拟进行组件级测试
  • 集成测试:端到端功能验证
  • 性能测试:内存使用和查询性能
  • 共享测试数据库:具有适当隔离的高效测试执行

客户端集成

与任何MCP客户端兼容。提供的示例配置用于:

  • 克劳德代码CLI -开发环境集成
  • Gemini CLI -替代客户支持
  • 通用MCP客户端 -标准协议实施

中提供的即用型配置文件 client-examples/.

性能特征

  • 内存效率:智能生命周期管理可防止无限增长
  • 查询性能:快速语义搜索,可选重新排序
  • 可扩展体系结构:模块化设计支持增长和定制
  • 监控:内置性能跟踪和健康评估

文档

  • docs/architecture.md -系统设计和组件
  • docs/configuration.md -配置指南和选项
  • docs/domain-configuration.md -域特定设置
  • client-examples/README.md -客户集成指南
  • REPORT.md -技术分析和改进机会

发展

运行测试

# All tests
pytest -v

# Specific test file
pytest tests/integration/test_deduplication_flow.py -v

# With coverage
pytest --cov=src/mcp_memory_server tests/

配置验证

# Validate configuration
python scripts/validate_config.py

# Test server startup
python scripts/start_server.py --test

该项目通过模型上下文协议探索人工智能系统的智能内存管理,重点关注实际会话持久性和知识保留。