MCP内存管理器-Claude代码上下文管理
一种模型上下文协议(MCP)服务器,为Claude AI编码助手提供持久的上下文管理。在压缩过程中,切勿再次失去上下文!此MCP服务器帮助Claude Code维护会话之间的上下文,保留您的工作历史、决策和进度。
🚀 快速开始
在30秒内开始:
BASH``` 1 2 3 4# Add memory-keeper to Claude claude mcp add memory-keeper npx mcp-memory-keeper
Start a new Claude session and use it!
Try: Analyze the current repo and save your analysis in memory-keeper
就是这样!现在,您的所有Claude会话中都可以使用Memory Keeper。您的上下文存储在 `~/mcp-data/memory-keeper/` 并在会话中持续存在。
## 🚀 实用记忆管理器工作流程示例
### **自定义命令+CLAUDE.md=自动上下文管理**
#### **[CLAUDE.md](http://CLAUDE.md)** (简明示例)
MARKDOWN```
1
2
3
4
5
6
7
8# Project Configuration
## Development Rules
- Always use memory-keeper to track progress
- Save architectural decisions and test results
- Create checkpoints before context limits
## Quality Standards
- All tests must pass before marking complete
- Document actual vs claimed results
自定义命令示例: /my-dev-workflow
MARKDOWN``` 1 2 3 4 5 6 7 8 9 10 11 12# My Development Workflow When working on the provided project:
- Use memory-keeper with channel: <project_name>
- Save progress at every major milestone
- Document all decisions with category: “decision”
- Track implementation status with category: “progress”
- Before claiming anything is complete, save test results
Workflow Steps
- Initialize session with project name as channel
- Save findings during investigation
- Create checkpoint before major changes
- Document what actually works vs what should work
#### **用法示例**
1 2 3 4 5 6 7 8 9User: /my-dev-workflow authentication-service AI: Setting up workflow for authentication-service. [Uses memory-keeper with channel “authentication-service”] [… AI works, automatically saving context …] User: “Getting close to context limit. Create checkpoint and give me a key” AI: “Checkpoint created: authentication-service-checkpoint-20250126-143026” [Continue working until context reset or compact manually] User: “Restore from key: authentication-service-checkpoint-20250126-143026” AI: “Restored! Continuing OAuth implementation. We completed the token validation, working on refresh logic…”
**模式:**
1. 自定义命令包括使用内存保持器的说明
2. AI会自动遵循这些指令
3. **当你注意到谈话越来越长时,你让克劳德保存一个检查点** (就像在老板打架之前保存你的游戏!)
4. **当Claude用完空间并重新开始时,您告诉它使用检查点密钥进行恢复**
**🎯 主要特点:** Memory Keeper是一个共享板!你可以:
- 重置后继续同一会话
- 启动一个全新的会话并恢复
- 让多个Claude会话并行运行,所有会话共享相同的内存
- 一个会话可以保存另一个会话检索的上下文
这实现了强大的工作流程,比如让一个Claude会话进行研究,而另一个会话实现代码,两者都通过Memory Keeper共享发现!
## 为什么选择MCP内存管理器?
当对话窗口填满时,Claude Code用户经常面临上下文丢失。此MCP服务器通过为Claude AI提供持久内存层来解决这个问题。无论您是在进行复杂的重构、多文件更改还是长时间的调试会话,memory Keeper都能确保您的Claude助手记住重要的上下文、决策和进度。
### 非常适合:
- 与Claude Code进行长时间编码会话
- 需要保留上下文的复杂项目
- 使用Claude AI进行协作开发的团队
- 希望在Claude会话中保持持久上下文的开发人员
## 特性
- 🔄 保存和恢复Claude Code会话之间的上下文
- 📁 具有更改检测功能的文件内容缓存
- 🏷️ 按类别和优先级组织上下文
- 📺 **频道** -持久的基于主题的组织(从git分支自动派生)
- 📸 用于完整上下文快照的检查点系统
- 🤖 永不丢失关键信息的智能压缩助手
- 🔍 在所有已保存的上下文中进行全文搜索
- 🕐 **增强过滤** -基于时间的查询、正则表达式模式、分页
- 📊 **变更追踪** -查看自任何时间点以来添加、修改或删除的内容
- 💾 导出/导入以进行备份和共享
- 🌿 具有自动上下文关联的Git集成
- 📊 具有优先级意识的AI友好摘要
- 🚀 为Claude优化的基于SQLite的快速存储
- 🔁 **批量操作** -以原子方式保存、更新或删除多个项目
- 🔄 **频道重新分配** -根据模式在通道之间移动项目
- 🔗 **上下文关系** -用键入的关系链接相关项目
- 👁️ **实时监控** -使用过滤器观察上下文变化
## 安装
### 推荐:NPX安装
BASH```
1claude mcp add memory-keeper npx mcp-memory-keeper
这个命令:
- ✅ 始终使用最新版本
- ✅ 自动处理所有依赖关系
- ✅ 适用于macOS、Linux和Windows
- ✅ 没有手动构建或本机模块问题
替代安装方法
Global Installation BASH``` 1 2npm install -g mcp-memory-keeper claude mcp add memory-keeper mcp-memory-keeper
From Source (for development)
BASH```
1
2
3
4
5
6
7
8
9# 1. Clone the repository
git clone https://github.com/mkreyman/mcp-memory-keeper.git
cd mcp-memory-keeper
# 2. Install dependencies
npm install
# 3. Build the project
npm run build
# 4. Add to Claude
claude mcp add memory-keeper /absolute/path/to/mcp-memory-keeper/bin/mcp-memory-keeper
配置
环境变量
储存和安装
DATA_DIR-数据库存储目录(默认:~/mcp-data/memory-keeper/)MEMORY_KEEPER_INSTALL_DIR-安装目录(默认:~/.local/mcp-servers/memory-keeper/)MEMORY_KEEPER_AUTO_UPDATE-设置为1启用自动更新
令牌限制配置
-
MCP_MAX_TOKENS-响应中允许的最大令牌数(默认值:25000,范围:1000-100000) -
如果您的MCP客户端有不同的限制,请调整此设置
-
MCP_TOKEN_SAFETY_BUFFER-安全缓冲百分比(默认值:0.8,范围:0.1-1.0) -
仅使用最大令牌的这一部分来防止溢出
-
MCP_MIN_ITEMS-即使超过限制,也要返回的最小项目数(默认值:1,范围:1-100) -
确保至少返回一些结果
-
MCP_MAX_ITEMS-每个响应允许的最大项目数(默认值:100,范围:10-1000) -
无论令牌限制如何,结果集的上限
-
MCP_CHARS_PER_TOKEN-每个令牌的字符数比率(默认值:3.5,范围:2.5-5.0) [高级] -
调整不同内容类型的令牌估计精度
-
较低的值=更保守(更安全,但返回的项目更少)
-
更高的值=更激进(返回更多项目,但有溢出风险)
更严格令牌限制的示例配置:
BASH``` 1 2 3 4export MCP_MAX_TOKENS=20000 # Lower max tokens export MCP_TOKEN_SAFETY_BUFFER=0.7 # More conservative buffer export MCP_MAX_ITEMS=50 # Fewer items per response export MCP_CHARS_PER_TOKEN=3.0 # More conservative estimation (optional)
#### 工具配置文件
默认情况下,所有38个工具都是公开的。为了减少AI助手中的上下文开销,您可以激活一个工具配置文件,限制可用的工具。
**快速使用:**
BASH```
1
2
3
4
5
6# Essential tools only (8 tools)
TOOL_PROFILE=minimal npx mcp-memory-keeper
# Standard workflow set (22 tools)
TOOL_PROFILE=standard npx mcp-memory-keeper
# All tools (default)
TOOL_PROFILE=full npx mcp-memory-keeper
内置配置文件:
| 配置文件 | 工具 | 描述 |
|---|---|---|
minimal | 8 | 核心持久性:保存、获取、搜索、状态、检查点 |
standard | 22 | 日常工作流程:核心+git、批量操作、渠道、导出/导入 |
full | 38 | 所有工具(默认,向后兼容) |
通过配置文件自定义配置文件:
创建 ~/.mcp-memory-keeper/config.json 要定义或覆盖配置文件:
JSON``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14{ “profiles”: { “my_workflow”: [ “context_session_start”, “context_save”, “context_get”, “context_search”, “context_checkpoint”, “context_restore_checkpoint”, “context_diff”, “context_timeline” ] } }
然后激活它: `TOOL_PROFILE=my_workflow npx mcp-memory-keeper`
配置文件配置文件优先于具有相同名称的内置默认文件。
**配置文件分辨率优先级:**
| `TOOL_PROFILE` | 配置文件有配置文件吗? | 内置存在吗? | 结果 |
| --- | --- | --- | --- |
| 设置 | 是 | – | 使用配置文件定义 |
| 设置 | 否 | 是 | 使用内置定义 |
| 设置 | 否 | 否 | 警告+回退到 `full` |
| 未设置 | – | – | 使用内置 `full` (所有工具) |
**环境变量:**
| 变量 | 描述 |
| --- | --- |
| `TOOL_PROFILE` | 要激活的配置文件名称(例如。, `minimal`, `standard`, `full`,或自定义) |
| `TOOL_PROFILE_CONFIG` | 覆盖配置文件路径(默认: `~/.mcp-memory-keeper/config.json`) |
> 注意:配置文件解析在服务器启动时发生一次。对env-var或配置文件的更改将在下次服务器重启时生效。
**克劳德代码/克劳德桌面配置:**
JSON```
1
2
3
4
5
6
7
8
9
10
11{
"mcpServers": {
"memory-keeper": {
"command": "npx",
"args": ["mcp-memory-keeper"],
"env": {
"TOOL_PROFILE": "minimal"
}
}
}
}
看 examples/config.json 查看完整的示例配置文件。
克劳德代码(CLI)
配置范围
选择保存配置的位置:
BASH``` 1 2 3 4 5 6# Project-specific (default) - only for you in this project claude mcp add memory-keeper npx mcp-memory-keeper
Shared with team via .mcp.json
claude mcp add —scope project memory-keeper npx mcp-memory-keeper
Available across all your projects
claude mcp add —scope user memory-keeper npx mcp-memory-keeper
#### 验证配置
BASH```
1
2
3
4# List all configured servers
claude mcp list
# Get details for Memory Keeper
claude mcp get memory-keeper
Claude桌面应用程序
- 打开克劳德桌面设置
- 导航到“开发人员”→ “模型上下文协议”
- 点击“添加MCP服务器”
- 添加以下配置:
JSON``` 1 2 3 4 5 6 7 8{ “mcpServers”: { “memory-keeper”: { “command”: “npx”, “args”: [“mcp-memory-keeper”] } } }
就是这样!无需路径,npx会自动处理所有事务。
### 验证安装
#### 克劳德代码:
1. 重新启动Claude Code或启动新会话
2. Memory Keeper工具应自动可用
3. 测试: `mcp_memory_save({ key: "test", value: "Hello Memory Keeper!" })`
4. 如果不工作,请检查服务器状态:
BASH```
1claude mcp list # Should show memory-keeper as "running"
对于Claude Desktop:
- 添加配置后重新启动Claude Desktop
- 在新的对话中,应该可以使用Memory Keeper工具
- 使用上述相同命令进行测试
故障排除
如果Memory Keeper不工作:
BASH``` 1 2 3 4 5# Remove and re-add the server claude mcp remove memory-keeper claude mcp add memory-keeper npx mcp-memory-keeper
Check logs for errors
The server output will appear in Claude Code’s output panel
### 更新到最新版本
使用npx安装方法,您每次都会自动获得最新版本!无需手动更新。
如果您使用全局安装方法:
BASH```
1
2
3
4# Update to latest version
npm update -g mcp-memory-keeper
# Start a new Claude session
# The updated features will be available immediately
备注更新后,您无需在Claude中重新配置MCP服务器。开始新的会话!
用法
会话管理
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29// Start a new session mcp_context_session_start({ name: ‘Feature Development’, description: ‘Working on user authentication’, }); // Start a session with project directory for git tracking mcp_context_session_start({ name: ‘Feature Development’, description: ‘Working on user authentication’, projectDir: ‘/path/to/your/project’, }); // Start a session with a default channel mcp_context_session_start({ name: ‘Feature Development’, description: ‘Working on user authentication’, projectDir: ‘/path/to/your/project’, defaultChannel: ‘auth-feature’, // Will auto-derive from git branch if not specified }); // Set project directory for current session mcp_context_set_project_dir({ projectDir: ‘/path/to/your/project’, }); // List recent sessions mcp_context_session_list({ limit: 5 }); // Continue from a previous session mcp_context_session_start({ name: ‘Feature Dev Continued’, continueFrom: ‘previous-session-id’, });
### 使用通道(v0.10.0中的新功能)
通道提供了持久的基于主题的组织,可以在会话崩溃和重启后幸存下来:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18// Channels are auto-derived from git branch (if projectDir is set)
// Branch "feature/auth-system" becomes channel "feature-auth-system" (20 chars max)
// Save to a specific channel
mcp_context_save({
key: 'auth_design',
value: 'Using JWT with refresh tokens',
category: 'decision',
priority: 'high',
channel: 'auth-feature', // Explicitly set channel
});
// Get items from a specific channel
mcp_context_get({ channel: 'auth-feature' });
// Get items across all channels (default behavior)
mcp_context_get({ category: 'task' });
// Channels persist across sessions - perfect for:
// - Multi-branch development
// - Feature-specific context
// - Team collaboration on different topics
增强的上下文存储
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50// Save with categories and priorities mcp_context_save({ key: ‘current_task’, value: ‘Implement OAuth integration’, category: ‘task’, priority: ‘high’, }); // Save decisions mcp_context_save({ key: ‘auth_strategy’, value: ‘Using JWT tokens with 24h expiry’, category: ‘decision’, priority: ‘high’, }); // Save progress notes mcp_context_save({ key: ‘progress_auth’, value: ‘Completed user model, working on token generation’, category: ‘progress’, priority: ‘normal’, }); // Retrieve by category mcp_context_get({ category: ‘task’ }); // Retrieve specific item mcp_context_get({ key: ‘current_task’ }); // Get context from specific session mcp_context_get({ sessionId: ‘session-id-here’, category: ‘decision’, }); // Enhanced filtering (NEW in v0.10.0) mcp_context_get({ category: ‘task’, priorities: [‘high’, ‘normal’], includeMetadata: true, // Get timestamps, size info sort: ‘created_desc’, // created_asc/desc, updated_asc/desc, priority limit: 10, // Pagination offset: 0, }); // Time-based queries (NEW in v0.10.0) mcp_context_get({ createdAfter: ‘2025-01-20T00:00:00Z’, createdBefore: ‘2025-01-26T23:59:59Z’, includeMetadata: true, }); // Pattern matching (NEW in v0.10.0) mcp_context_get({ keyPattern: ‘auth_.*’, // Regex to match keys category: ‘decision’, });
### 文件高速缓存
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12// Cache file content for change detection
mcp_context_cache_file({
filePath: '/src/auth/user.model.ts',
content: fileContent,
});
// Check if file has changed
mcp_context_file_changed({
filePath: '/src/auth/user.model.ts',
currentContent: newFileContent,
});
// Get current session status
mcp_context_status();
完整工作流示例
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37// 1. Start a new session mcp_context_session_start({ name: ‘Settings Refactor’, description: ‘Refactoring settings module for better performance’, }); // 2. Save high-priority task mcp_context_save({ key: ‘main_task’, value: ‘Refactor Settings.Context to use behaviors’, category: ‘task’, priority: ‘high’, }); // 3. Cache important files mcp_context_cache_file({ filePath: ‘lib/settings/context.ex’, content: originalFileContent, }); // 4. Save decisions as you work mcp_context_save({ key: ‘architecture_decision’, value: ‘Split settings into read/write modules’, category: ‘decision’, priority: ‘high’, }); // 5. Track progress mcp_context_save({ key: ‘progress_1’, value: ‘Completed behavior definition, 5 modules remaining’, category: ‘progress’, priority: ‘normal’, }); // 6. Before context window fills up mcp_context_status(); // Check what’s saved // 7. After Claude Code restart mcp_context_get({ category: ‘task’, priority: ‘high’ }); // Get high priority tasks mcp_context_get({ key: ‘architecture_decision’ }); // Get specific decisions mcp_context_file_changed({ filePath: ‘lib/settings/context.ex’ }); // Check for changes
### 检查点(第2阶段)
创建整个上下文的命名快照,稍后可以恢复:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15// Create a checkpoint before major changes
mcp_context_checkpoint({
name: 'before-refactor',
description: 'State before major settings refactor',
includeFiles: true, // Include cached files
includeGitStatus: true, // Capture git status
});
// Continue working...
// If something goes wrong, restore from checkpoint
mcp_context_restore_checkpoint({
name: 'before-refactor',
restoreFiles: true, // Restore cached files too
});
// Or restore the latest checkpoint
mcp_context_restore_checkpoint({});
上下文总结(第2阶段)
获取您保存的上下文的AI友好摘要:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12// Get a summary of all context mcp_context_summarize(); // Get summary of specific categories mcp_context_summarize({ categories: [‘task’, ‘decision’], maxLength: 2000, }); // Summarize a specific session mcp_context_summarize({ sessionId: ‘session-id-here’, categories: [‘progress’], });
示例摘要输出:
MARKDOWN```
1
2
3
4
5
6
7
8
9
10# Context Summary
## High Priority Items
- **main_task**: Refactor Settings.Context to use behaviors
- **critical_bug**: Fix memory leak in subscription handler
## Task
- implement_auth: Add OAuth2 authentication flow
- update_tests: Update test suite for new API
## Decision
- architecture_decision: Split settings into read/write modules
- db_choice: Use PostgreSQL for better JSON support
批量操作
以原子方式执行多个操作:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21// Save multiple items at once mcp_context_batch_save({ items: [ { key: ‘config_api_url’, value: ‘https://api.example.com’, category: ‘note’ }, { key: ‘config_timeout’, value: ‘30000’, category: ‘note’ }, { key: ‘config_retries’, value: ‘3’, category: ‘note’ }, ], }); // Update multiple items mcp_context_batch_update({ updates: [ { key: ‘task_1’, priority: ‘high’ }, { key: ‘task_2’, priority: ‘high’ }, { key: ‘task_3’, value: ‘Updated task description’ }, ], }); // Delete by pattern mcp_context_batch_delete({ keyPattern: ‘temp_*’, dryRun: true, // Preview first });
### 渠道管理
在通道之间重新组织上下文项:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12// Move items to a new channel
mcp_context_reassign_channel({
keyPattern: 'auth_*',
toChannel: 'feature-authentication',
});
// Move from one channel to another
mcp_context_reassign_channel({
fromChannel: 'sprint-14',
toChannel: 'sprint-15',
category: 'task',
priorities: ['high'],
});
上下文关系
构建相关项目的图表:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12// Link related items mcp_context_link({ sourceKey: ‘epic_user_management’, targetKey: ‘task_create_user_api’, relationship: ‘contains’, }); // Find related items mcp_context_get_related({ key: ‘epic_user_management’, relationship: ‘contains’, depth: 2, });
### 实时监控
注意上下文变化:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13// Create a watcher
const watcher = await mcp_context_watch({
action: 'create',
filters: {
categories: ['task'],
priorities: ['high'],
},
});
// Poll for changes
const changes = await mcp_context_watch({
action: 'poll',
watcherId: watcher.watcherId,
});
智能压实(第3阶段)
当克劳德的窗口填满时,永远不要失去关键的上下文:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9// Before context window fills mcp_context_prepare_compaction(); // This automatically: // - Creates a checkpoint // - Identifies high-priority items // - Captures unfinished tasks // - Saves all decisions // - Generates a summary // - Prepares restoration instructions
### Git集成(第3阶段)
跟踪项目目录中的git更改,并使用提交保存上下文:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12// First, set your project directory (if not done during session start)
mcp_context_set_project_dir({
projectDir: '/path/to/your/project',
});
// Commit with auto-save
mcp_context_git_commit({
message: 'feat: Add user authentication',
autoSave: true, // Creates checkpoint with commit
});
// Context is automatically linked to the commit
// Note: If no project directory is set, you'll see a helpful message
// explaining how to enable git tracking for your project
上下文搜索(第3阶段)
在保存的上下文中查找任何内容:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12// Search in keys and values mcp_context_search({ query: ‘authentication’ }); // Search only in keys mcp_context_search({ query: ‘config’, searchIn: [‘key’], }); // Search in specific session mcp_context_search({ query: ‘bug’, sessionId: ‘session-id’, });
### 出口/进口(第3阶段)
共享上下文或备份您的工作:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16// Export current session
mcp_context_export(); // Creates memory-keeper-export-xxx.json
// Export specific session
mcp_context_export({
sessionId: 'session-id',
format: 'json',
});
// Import from file
mcp_context_import({
filePath: 'memory-keeper-export-xxx.json',
});
// Merge into current session
mcp_context_import({
filePath: 'backup.json',
merge: true,
});
知识图谱(第四阶段)
自动从上下文中提取实体和关系:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23// Analyze context to build knowledge graph mcp_context_analyze(); // Or analyze specific categories mcp_context_analyze({ categories: [‘task’, ‘decision’], }); // Find related entities mcp_context_find_related({ key: ‘AuthService’, maxDepth: 2, }); // Generate visualization data mcp_context_visualize({ type: ‘graph’, }); // Timeline view mcp_context_visualize({ type: ‘timeline’, }); // Category/priority heatmap mcp_context_visualize({ type: ‘heatmap’, });
### 语义搜索(第4.2阶段)
使用自然语言查询查找上下文:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16// Search with natural language
mcp_context_semantic_search({
query: 'how are we handling user authentication?',
topK: 5,
});
// Find the most relevant security decisions
mcp_context_semantic_search({
query: 'security concerns and decisions',
minSimilarity: 0.5,
});
// Search with specific similarity threshold
mcp_context_semantic_search({
query: 'database performance optimization',
topK: 10,
minSimilarity: 0.3,
});
多代理系统(第4.3阶段)
将复杂的分析任务委托给专业代理:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45// Analyze patterns in your context mcp_context_delegate({ taskType: ‘analyze’, input: { analysisType: ‘patterns’, categories: [‘task’, ‘decision’], }, }); // Get comprehensive analysis mcp_context_delegate({ taskType: ‘analyze’, input: { analysisType: ‘comprehensive’, }, }); // Analyze relationships between entities mcp_context_delegate({ taskType: ‘analyze’, input: { analysisType: ‘relationships’, maxDepth: 3, }, }); // Create intelligent summaries mcp_context_delegate({ taskType: ‘synthesize’, input: { synthesisType: ‘summary’, maxLength: 1000, }, }); // Get actionable recommendations mcp_context_delegate({ taskType: ‘synthesize’, input: { synthesisType: ‘recommendations’, analysisResults: {}, // Can pass previous analysis results }, }); // Chain multiple agent tasks mcp_context_delegate({ chain: true, taskType: [‘analyze’, ‘synthesize’], input: [{ analysisType: ‘comprehensive’ }, { synthesisType: ‘recommendations’ }], });
代理类型:
- **分析代理**:检测模式、分析关系、跟踪趋势
- **合成器代理**:创建摘要、合并见解、生成建议
### 会话分支和合并(阶段4.4)
在不丢失原创作品的情况下探索替代方案:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15// Create a branch to try something new
mcp_context_branch_session({
branchName: 'experimental-refactor',
copyDepth: 'shallow', // Only copy high-priority items
});
// Or create a full copy
mcp_context_branch_session({
branchName: 'feature-complete-copy',
copyDepth: 'deep', // Copy everything
});
// Later, merge changes back
mcp_context_merge_sessions({
sourceSessionId: 'branch-session-id',
conflictResolution: 'keep_newest', // or "keep_current", "keep_source"
});
日记条目(第4.4阶段)
用带时间戳的日记条目跟踪你的想法和进度:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10// Add a journal entry mcp_context_journal_entry({ entry: ‘Completed the authentication module. Tests are passing!’, tags: [‘milestone’, ‘authentication’], mood: ‘accomplished’, }); // Entries are included in timeline views mcp_context_timeline({ groupBy: ‘day’, });
### 时间线和活动跟踪(第4.4阶段)
随着时间的推移,可视化你的工作模式:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19// Get activity timeline
mcp_context_timeline({
startDate: '2024-01-01',
endDate: '2024-01-31',
groupBy: 'day', // or "hour", "week"
});
// Enhanced timeline (NEW in v0.10.0)
mcp_context_timeline({
groupBy: 'hour',
includeItems: true, // Show actual items, not just counts
categories: ['task', 'progress'], // Filter by categories
relativeTime: true, // Show "2 hours ago" format
itemsPerPeriod: 10, // Limit items shown per time period
});
// Shows:
// - Context items created per day/hour
// - Category distribution over time
// - Journal entries with moods and tags
// - Actual item details when includeItems: true
渐进式压缩(第4.4阶段)
通过智能压缩旧上下文来节省空间:
JAVASCRIPT``` 1 2 3 4 5 6 7 8 9 10 11// Compress items older than 30 days mcp_context_compress({ olderThan: ‘2024-01-01’, preserveCategories: [‘decision’, ‘critical’], // Keep these targetSize: 1000, // Target size in KB (optional) }); // Compression summary shows: // - Items compressed // - Space saved // - Compression ratio // - Categories affected
### 跨工具集成(第4.4阶段)
跟踪其他MCP工具的事件:
JAVASCRIPT```
1
2
3
4
5
6
7
8
9
10// Record events from other tools
mcp_context_integrate_tool({
toolName: 'code-analyzer',
eventType: 'security-scan-complete',
data: {
vulnerabilities: 0,
filesScanned: 150,
important: true, // Creates high-priority context item
},
});
文档
- 快速入门示例 -现实世界场景和工作流程
- API 参考 -完整的工具文档,包括所有参数和示例
- 配方书 -日常开发的常见模式和最佳实践
- 故障排除指南 -常见问题和解决方案
- 架构概述 -系统设计和技术细节
- 贡献指南 -如何为项目做出贡献
- 更新日志 -版本历史和发行说明
发展
以开发模式运行
BASH``` 1 2 3 4 5 6 7 8 9 10 11 12# Install dependencies npm install
Run tests
npm test
Run tests with coverage
npm run test:coverage
Run with auto-reload
npm run dev
Build for production
npm run build
Start production server
npm start
### 项目结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19mcp-memory-keeper/ ├── src/ │ ├── index.ts # Main MCP server implementation │ ├── utils/ # Utility modules │ │ ├── database.ts # Database management │ │ ├── validation.ts # Input validation │ │ ├── git.ts # Git operations │ │ ├── knowledge-graph.ts # Knowledge graph management │ │ ├── vector-store.ts # Vector embeddings │ │ └── agents.ts # Multi-agent system │ └── tests/ # Test files ├── dist/ # Compiled JavaScript (generated) ├── context.db # SQLite database (auto-created) ├── EXAMPLES.md # Quick start examples ├── TROUBLESHOOTING.md # Common issues and solutions ├── package.json # Project configuration ├── tsconfig.json # TypeScript configuration ├── jest.config.js # Test configuration └── README.md # This file
### 测试
该项目包括全面的测试覆盖范围:
BASH```
1
2
3
4
5
6
7
8# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Generate coverage report
npm run test:coverage
# Run specific test file
npm test -- summarization.test.ts
测试类别:
- 单元测试:输入验证、数据库操作、git集成
- 集成测试:全工具工作流程、错误场景、边缘案例
- 覆盖:关键模块的覆盖率超过97%
功能状态
| 特性 | 成熟度 | 版本 | 用例 |
|---|---|---|---|
| 基本保存/获取 | ✅ 稳定 | v0.1+ | 日常上下文管理 |
| 会议 | ✅ 稳定 | v0.2+ | 多项目工作 |
| 文件缓存 | ✅ 稳定 | v0.2+ | 跟踪文件更改 |
| 检查点 | ✅ 稳定 | v0.3+ | 上下文保留 |
| 智能压缩 | ✅ 稳定 | v0.3+ | 预压准备 |
| Git集成 | ✅ 稳定 | v0.3+ | 提交上下文跟踪 |
| 搜索 | ✅ 稳定 | v0.3+ | 查找已保存的项目 |
| 出口/进口 | ✅ 稳定 | v0.3+ | 备份和共享 |
| 知识图谱 | ✅ 稳定 | v0.5+ | 代码关系分析 |
| 可视化 | ✅ 稳定 | v0.5+ | 上下文探索 |
| 语义搜索 | ✅ 稳定 | v0.6+ | 自然语言查询 |
| 多代理 | ✅ 稳定 | v0.7+ | 智能处理 |
当前功能(v0.10.0)
- ✅ 会话管理:使用分支支持创建、列出和继续会话
- ✅ 频道:持久的基于主题的组织(从git分支自动派生)
- ✅ 上下文存储:保存/检索带有类别(任务、决策、进度、注释)和优先级的上下文
- ✅ 增强过滤:基于时间的查询、正则表达式模式、排序、分页
- ✅ 文件高速缓存:使用SHA-256哈希跟踪文件更改
- ✅ 检查点:创建和恢复完整的上下文快照
- ✅ 智能压缩:在达到极限时,永远不要失去关键背景
- ✅ Git集成:使用分支跟踪在提交时自动保存上下文
- ✅ 搜索:在所有已保存的上下文中进行全文搜索
- ✅ 导出/导入:以JSON格式备份和共享上下文
- ✅ SQLite存储:具有WAL模式的持久、可靠的数据存储
- ✅ 知识图谱:从上下文中自动提取实体和关系
- ✅ 可视化:生成图表、时间线和热图数据,用于上下文探索
- ✅ 语义搜索:使用轻量级向量嵌入的自然语言搜索
- ✅ 多代理系统:使用专用分析仪和合成器代理进行智能分析
- ✅ 会话分支:创建分支以探索替代方案,而不会丢失原始上下文
- ✅ 会话合并:使用冲突解决选项将分支合并回
- ✅ 日记账分录:带有标签和情绪跟踪的带时间戳的条目
- ✅ 增强的时间线:包含项目详细信息和相对时间的活动模式
- ✅ 渐进压缩:智能压缩旧上下文以节省空间
- ✅ 跨工具集成:跟踪其他MCP工具的事件
路线图
第四阶段:高级功能(开发中)
- 🚧 知识图谱:用于代码理解的实体关系跟踪
- 🚧 向量搜索:使用自然语言的语义搜索
- 📋 多代理处理:智能分析和综合
- 📋 时间感知上下文:时间线视图和日记条目
第5阶段:文件和波兰语
- ✅ 示例:全面的快速启动方案
- ✅ 故障排除:常见问题和解决方案
- 🚧 菜谱:常见模式和工作流程
- 📋 视频教程:关键功能的视觉指南
未来的增强功能
- []用于浏览上下文历史的Web UI
- []多用户/团队协作功能
- []云同步和共享
- []与其他AI助手集成
- []高级分析和见解
- []自定义上下文模板
- []自动保留策略
升级
数据库路径更改(v0.12.x+)
在此版本之前,服务器已解决 context.db 相对于进程的当前工作目录。数据库现在位于一个绝对路径上:
- 违约:
~/mcp-data/memory-keeper/context.db - 自定义: 集
DATA_DIR=/your/path—服务器将使用$DATA_DIR/context.db
如果您在 context.db 在您的旧工作目录中,在重新启动服务器之前将其移动到新位置:
BASH``` 1 2mkdir -p ~/mcp-data/memory-keeper cp /path/to/old/context.db ~/mcp-data/memory-keeper/context.db
如果 `DATA_DIR` 已设置,请使用该路径作为目标,而不是 `~/mcp-data/memory-keeper/`.
如果服务器检测到错误,它将向stderr打印警告 `context.db` 在与配置的数据目录不同的当前目录中,包括确切的 `cp` 命令运行。
### 从源代码安装命令更改
如果您使用注册了内存管理器 `node dist/index.js` 直接更新MCP配置以使用bin包装器:
BASH```
1
2
3
4# remove the old entry
claude mcp remove memory-keeper
# add the updated entry
claude mcp add memory-keeper /absolute/path/to/mcp-memory-keeper/bin/mcp-memory-keeper
贡献
欢迎投稿!请随时提交拉取请求。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/AmazingFeature) - 提交您的更改(
git commit -m 'Add some AmazingFeature') - 推到分支(
git push origin feature/AmazingFeature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
作者
马克·克雷曼
致谢
- 专为Claude Code社区打造
- 受AI编码会话中更好的上下文管理需求的启发
- 感谢Anthropic提供MCP协议
支持
如果您遇到任何问题或有疑问:
关键词
克劳德代码上下文管理、MCP服务器、克劳德AI内存、持久上下文、模型上下文协议、克劳德辅助内存、AI编码上下文、克劳德代码MCP、上下文保存、克劳德AI工具