本地记忆工具

MCP Local Memory 是一个轻量级、可操控的本地记忆工具,专为AI设计,支持SQLite和本地嵌入模型,可选OpenAI支持,适用于个人使用,存储2-3K条记忆。

  • by NickSmet
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 NickSmet/mcp-local-memory

使用说明

MCP本地存储器

适用于AI的轻量级、可操纵的本地内存工具(SQLite+本地嵌入模型,可选的OpenAI支持)。

让您的代理记住您想要的任何内容:首选项、项目详细信息,甚至重用提示。从记忆的结构和检索方式到它们的更新和删除方式,这一切都取决于你和你的提示。

专为个人使用而设计,存储2-3K内存。

安装

将此添加到AI客户端的MCP配置文件中:

选项A:本地

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "mcp-local-memory"]
    }
  }
}

为什么要去当地?

  • 自由
  • 不需要API密钥
  • 如果你的AI代理应用程序也使用本地运行的模型——你的数据永远不会离开你的计算机

权衡:

  • 安装程序在配置期间下载约130MB的模型(一次性)。
  • 使用本地模型的性能开销较小。
  • 在保存记忆时,你的AI代理需要稍微明确一些。
  • 检索准确率稍低

选项B:使用OpenAI API密钥

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "mcp-local-memory"],
      "env": {
        "OPENAI_API_KEY": "your-key-here"
      }
    }
  }
}

OpenAI API密钥: platform.openai.com/api-keys

为什么要使用OpenAI? 由于以下原因,性能有所提高:

  • OpenAI嵌入模型比本地运行的模型更好
  • 内存工具在保存时将使用快速的OpenAI模型来更好地构建内存

成本: 5美元够你用几个月

备注:在“本地”和“OpeanAI”模式下,您的所有记忆都存储在本地。 (默认路径为 ~/Documents/mcp-personal-memory/memory.db)


它能做什么?

安装后,您的AI助手可以:

记住你告诉它的事情:

You: "Remember: I prefer TypeScript over JavaScript"
AI: ✓ Saved in memory
You: "Store key information about this project we just discussed"
AI: ✓ 8 memories saved

稍后回忆信息:

You: "What programming language do I prefer?"
AI: [Searches memory] You prefer TypeScript over JavaScript
You: "What's the main Jira Epic for this project?"
AI: [Searches memory] It's [ABC-123](https://example.atlassian.net/browse/ABC-123)

更新/整理记忆:

You: "Hey, pls retrieve all the memories we've had about project ABC. Now that 
     there is a clear outline, pls structure them by frontend and backend. 
     Remove redundant memories. If you find conflicting memories -- ask me 
     before proceeding."

AI: [Searches memories for "project ABC"]
    Found 8 memories. I've organized them by adding clear tags:
    
    - 3 memories didn't have tags → added "frontend" tag
    - 4 memories had vague tags → updated to "backend" tag  
    - 1 memory was redundant (duplicate deployment info) → deleted
    
    Now structured as:
    
    Frontend (3 memories):
    - React + TypeScript stack
    - UI design in Figma, link: [...]
    - Deployment: Vercel
    
    Backend (4 memories):
    - Node.js API with Express
    - Database APIs
    - Database performance considerations
    - Hosted on Railway
    - API docs at [...]
    
    ⚠️ Conflict found: Memory bnL9Df8a says backend uses MongoDB, but memory Asq8Y6kq 
    (created recently) mentions CosmosDB. Which is correct?

系统提示示例

自定义系统提示将极大地影响代理使用该工具的方式。 以下是适当的系统提示可能包括的示例:


### Working with Memory

Your memory tool helps maintain context across conversations. Use it thoughtfully:

**When to retrieve from memory:**
- User mentions something that could benefit from past context
- Information from other sources seems incomplete or could be enriched
- You need account IDs, project details, or other recurring facts
- **User gives you a task without full context—search memory to understand connections and background**

**When to update memory:**
- Important facts or connections emerge from the conversation
- Actions or decisions result in changed understanding
- **Project phase transitions** (started → in development → testing → deployed → production)
- **Major milestones reached** (infrastructure deployed, API complete, feature shipped)
- **New features or capabilities added** that weren't in original scope
- **Corrections to outdated information** (especially when you're corrected by the user)
- **Key URLs, endpoints, or deployment locations** discovered or changed
- **Meta-patterns emerge** (e.g., "when user asks X, they typically mean Y" or common workflows/preferences)

**What NOT to store as updates:**
- Incremental progress percentages (40% → 60% done)
- Temporary states that will change soon ("currently debugging X")
- Information already well-captured elsewhere unless it provides quick-reference value
- Minor task status changes within the same phase

**Think of memory as "overall situational awareness":**
- Can we do X? (features/capabilities)
- Where is Y? (URLs, locations, resources)
- What phase is Z in? (not started / active development / testing / production)
- How does A relate to B? (architecture, dependencies, relationships)

If you've already retrieved relevant memories during this conversation, you can update them directly without re-checking. Otherwise, search first to see what exists.

💡 更高级的用法: 看 自述已完成.md 有关技术细节、工具调用说明系统和高级功能。

高级配置

独立的工作和个人记忆

添加 CONTEXT_ID 到您的配置:

{
  "memory-work": {
    "command": "npx",
    "args": ["-y", "mcp-local-memory"],
    "env": {
      "OPENAI_API_KEY": "your-key",
      "CONTEXT_ID": "work"
    }
  },
  "memory-personal": {
    "command": "npx",
    "args": ["-y", "mcp-local-memory"],
    "env": {
      "OPENAI_API_KEY": "your-key",
      "CONTEXT_ID": "personal"
    }
  }
}

现在,您有两个单独的内存空间,它们不会混合在一起。

自定义数据库位置

添加 SQLITE_PATH 到您的配置:

{
  "env": {
    "SQLITE_PATH": "/path/to/your/memory.db"
  }
}

适用于:

  • 跨设备同步内存(将数据库放在Dropbox/iCloud中)
  • 备份到特定位置
  • 同一台计算机上有多个用户

在OpenAI和离线之间切换

如果需要,您的AI可以切换模式:

  • 询问:“切换到离线存储模式”
  • AI将使用 switch_embedding_mode 工具
  • 如果OpenAI API有问题或您想离线,这很有用

面向开发者

这是一份用户指南。有关技术文档,请参阅:

更多示例: 检查 示例/ 用于不同配置选项的文件夹。

隐私和数据

  • 本地存储: 存储在计算机上的所有记忆
  • OpenAI模式: 将内存文本发送到OpenAI进行处理(受OpenAI隐私政策的约束)
  • 您的控制: 删除 memory.db 抹去一切

许可证

MIT-可自由用于个人或商业项目


问题或议题? 在GitHub上打开一个问题或查看上面的技术文档。