编码记忆管理系统

一个轻量级的、基于SQLite的学习管理系统,用于捕获、搜索和应用开发中的见解。

  • by zoul1380
  • C#
  • 本地部署
  • 更新于
在 GitHub 查看 zoul1380/memory-mcp

使用说明

MemoryMCP-用于编码的内存/上下文提供程序

一个轻量级的、SQLite支持的学习管理系统,可以捕获、搜索和应用跨项目的开发见解。

特性

  • 捕捉 重要经验:错误、修复、陷阱、部署步骤
  • 搜索 使用带有关键字和语义查询的全文搜索(FTS5)
  • 浏览 按存储库或跨项目
  • 应用 本次会议的经验教训:
    • 副驾驶指令片段
    • 飞行前检查表
    • Gotchas总结

项目结构

MemoryMcp/
├── MemoryMcp/                      # Main library
│   ├── Database/
│   │   ├── McpDb.cs               # DB initialization & schema
│   │   └── LearningNoteRepo.cs    # Repository pattern (CRUD + search)
│   ├── Models/
│   │   └── LearningNote.cs        # Data models
│   ├── Formatting/
│   │   └── ApplyFormatter.cs      # Output generation (instructions, checklist, gotchas)
│   └── MemoryMcp.csproj
├── MemoryMcp.Tests/               # Comprehensive test suite
│   ├── Database/
│   │   ├── DatabaseInitializationTests.cs
│   │   └── LearningNoteRepoTests.cs
│   ├── Formatting/
│   │   └── ApplyFormatterTests.cs
│   ├── Integration/
│   │   └── EndToEndWorkflowTests.cs
│   ├── TestDbFixture.cs
│   ├── Usings.cs
│   └── MemoryMcp.Tests.csproj
├── MemoryMcp.sln
└── README.md

先决条件

  • .NET 8.0或更高版本
  • Windows、macOS或Linux

建筑

dotnet build MemoryMcp.sln

运行测试

运行所有测试:

dotnet test MemoryMcp.sln

运行特定测试类:

dotnet test MemoryMcp.sln --filter "DatabaseInitializationTests"

以详细输出运行:

dotnet test MemoryMcp.sln --verbosity detailed

测试覆盖率

单元测试

  • 数据库初始化测试 (5次测试)

    • 架构创建
    • 表/FTS/触发器创建
    • 幂等性
  • 学习笔记报告测试 (20+次测试)

    • CRUD操作
    • 全文搜索(关键字、OR查询)
    • 存储库范围与全局搜索
    • 标签管理和重复数据消除
    • 链接持久性
    • 计数和过滤
    • 错误处理和验证
  • 应用格式化程序测试 (13次测试)

    • 副驾驶指令生成
    • 创建检查表
    • Gotchas摘要格式
    • 文本截断和格式化
    • 置信度处理

集成测试

  • EndToEndWorkflowTests (6次测试)
    • 完全捕获→ 搜索→ 应用工作流
    • 多回购搜索
    • 基于标签的过滤
    • 置信度过滤
    • 学习更新和验证
    • 完成会话输出生成

关键类

McpDB

通过以下方式处理SQLite数据库初始化:

  • 带全文搜索的学习笔记表
  • 标签和标签映射
  • PR/Jira/doc参考链接表
  • 通过触发器自动进行FTS同步
  • 跟踪时更新

学习笔记回购

存储库模式实现:

  • AddLearningAsync() -使用标签/链接创建新的学习
  • SearchAsync() -FTS搜索(回购范围或全局)
  • GetByIdAsync() -检索单张钞票
  • GetByRepoAsync() -回购的所有票据
  • GetMetaAsync() -相关标签和链接
  • DeleteAsync() -删除学习
  • CountAsync() -清点钞票

应用格式化程序

格式化当前会话的搜索结果:

  • BuildCopilotInstructions() -AI指令片段
  • BuildChecklist() -变更前/变更后检查表
  • BuildGotchasSummary() -按置信水平列出的问题

示例用法

// Initialize database
var db = new McpDb(@"%USERPROFILE%\.mcp\mcp.db");
await db.InitializeAsync();

// Create repository
var repo = new LearningNoteRepo(db.ConnectionString);

// Add a learning
var id = await repo.AddLearningAsync(new LearningNoteInput(
    RepoKey: "example-repo",
    Title: "Email reminder race condition",
    Problem: "Duplicate emails sent on retry",
    Solution: "Add idempotency check; verify state before send",
    RootCause: "Async message in flight when approval completes",
    Confidence: "confirmed",
    Tags: new[] { "email", "approval", "race-condition" },
    Links: new[] { ("PR", "https://github.com/org/repo/pull/123") }
));

// Search for it
var results = await repo.SearchAsync("email reminder", repoKey: "example-repo");

// Generate session aids
var instructions = ApplyFormatter.BuildCopilotInstructions(results);
var checklist = ApplyFormatter.BuildChecklist(results);
var gotchas = ApplyFormatter.BuildGotchasSummary(results);

数据模型

学习笔记

record LearningNote(
    long Id,
    string RepoKey,              // e.g., "example-repo"
    string Title,                // Main heading
    string Problem,              // What went wrong
    string Solution,             // How to fix/prevent
    string? RootCause,           // Optional root cause
    string? AppliesWhen,         // When this learning applies
    string Confidence,           // "confirmed" | "likely" | "hypothesis"
    string CreatedAt,            // ISO8601 timestamp
    string UpdatedAt,            // ISO8601 timestamp
    string? LastVerifiedAt       // When last confirmed
)

学习笔记输入

添加学习的输入模型(除核心4外,所有字段都是可选的):

record LearningNoteInput(
    string RepoKey,
    string Title,
    string Problem,
    string Solution,
    string? RootCause = null,
    string? AppliesWhen = null,
    string Confidence = "likely",
    IEnumerable<string>? Tags = null,
    IEnumerable<(string label, string url)>? Links = null
)

搜索语法(FTS5)

-- Simple keywords
"email timeout"

-- OR queries
"timeout OR deadline"

-- NEAR operator (within N words)
"reminder NEAR/3 approved"

-- Quoted phrases
"race condition"

-- Field-specific (if needed)
problem:timeout solution:retry

未来的增强功能

  • []CLI工具(mcp add, mcp search, mcp apply)
  • []VS代码扩展UI
  • []自动重复数据删除/合并
  • []每次回购的出口降价
  • []会话分组和历史记录
  • []更新/编辑学习操作
  • []团队同步和共享(有权限)
  • []Web用户界面
  • []与Git挂钩/PR模板集成

许可证

麻省理工学院