Mnemosyne缓存MCP
高性能MCP(模型上下文协议)响应缓存服务器。将重复工具调用的延迟从~3000ms降低到~0.001ms。
概述
Mnemosyne Cache MCP服务器使用双层架构为MCP工具响应提供透明缓存:
- SQLite:持久存储后端
- LRU内存缓存:热进入加速
主要特点
- 智能TTL管理:特定于服务器的过期策略
- 写入操作检测:自动跳过突变缓存
- SHA256缓存密钥:从工具调用生成确定性密钥
- 统计跟踪:点击、未点击、驱逐和点击率监控
- 零配置:具有环境变量覆盖的合理默认值
性能影响
Uncached serena tool call: ~3000ms
Cached serena tool call: ~0.001ms
Performance improvement: 3,000,000% faster安装
npm install -g @zhadyz/mnemosyne-cache-mcp或者与npx一起使用:
npx @zhadyz/mnemosyne-cache-mcp配置
环境变量
# Database location (default: ./mcp_cache.db)
export MNEMOSYNE_CACHE_DB="/path/to/cache.db"
# Memory cache settings (default: enabled, 1000 entries)
export MEMORY_CACHE="true"
export MEMORY_CACHE_SIZE="1000"默认TTL值
| 服务器 | TTL(秒) | 基本原理 |
|---|---|---|
| serena | 1800(30分钟) | 代码频繁更改 |
| context7 | 7200(2小时) | 文档稳定 |
| github | 600(10分钟) | 仓库更改 |
| 文件系统 | 300(5分钟) | 文件更改 |
| 内存 | 0(从不) | 可变状态 |
| mnemosyne | 0(从不) | 可变状态 |
MCP配置
添加到您的Claude Code MCP设置中(.claude/mcp.json):
{
"mcpServers": {
"mnemosyne-cache": {
"command": "npx",
"args": ["@zhadyz/mnemosyne-cache-mcp"],
"env": {
"MNEMOSYNE_CACHE_DB": "./.cache/mcp_cache.db",
"MEMORY_CACHE": "true",
"MEMORY_CACHE_SIZE": "1000"
}
}
}
}或者本地安装:
{
"mcpServers": {
"mnemosyne-cache": {
"command": "node",
"args": ["/path/to/mnemosyne-cache-mcp/dist/index.js"]
}
}
}可用工具
cache_get
检索缓存的MCP工具响应。
{
"server_name": "serena",
"tool_name": "find_symbol",
"args": {
"name_path": "MyClass",
"relative_path": "src/main.ts"
}
}答复:
{
"cached": true,
"data": { /* tool response */ }
}cache_set
使用自动TTL存储MCP工具响应。
{
"server_name": "serena",
"tool_name": "find_symbol",
"args": { /* tool arguments */ },
"response": { /* tool response */ }
}答复:
{
"success": true,
"message": "Cached response for serena:find_symbol"
}cache_invalidate
按服务器或工具使缓存条目无效。
{
"server_name": "github",
"tool_name": "get_issue" // optional
}答复:
{
"success": true,
"invalidated_entries": 42
}cache_stats
获取缓存性能统计信息。
{}答复:
{
"hits": 1523,
"misses": 287,
"evictions": 12,
"totalEntries": 1810,
"totalSizeBytes": 15728640,
"sizeMB": 15.0,
"hitRate": 84.14,
"avgHitTimeMs": 0.001,
"avgMissTimeMs": 3127.5
}缓存密钥生成
使用SHA256确定地生成缓存密钥:
const keyMaterial = `${serverName}:${toolName}:${sortedArgs}`;
const cacheKey = sha256(keyMaterial);参数是用排序键进行JSON字符串化的,以确保无论参数顺序如何,相同的调用都会产生相同的键。
写入操作检测
工具名称中的以下动词将自动从缓存中排除:
- 创建
- 更新
- 删除
- 移除
- 修改
- 写
不可缓存操作的示例:
github__create_issuefilesystem__write_fileserena__replace_symbol_body
建筑
┌─────────────────────────────────────────┐
│ MCP Client (Claude Code) │
└────────────────┬────────────────────────┘
│
│ stdio transport
▼
┌─────────────────────────────────────────┐
│ Mnemosyne Cache MCP Server │
│ │
│ ┌───────────────────────────────────┐ │
│ │ LRU Memory Cache (Hot) │ │
│ │ - 1000 entries (default) │ │
│ │ - O(1) lookup │ │
│ └───────────┬───────────────────────┘ │
│ │ miss │
│ ▼ │
│ ┌───────────────────────────────────┐ │
│ │ SQLite Database (Cold) │ │
│ │ - Persistent storage │ │
│ │ - TTL expiration │ │
│ └───────────────────────────────────┘ │
│ │
│ Cache Key: SHA256(server:tool:args) │
└─────────────────────────────────────────┘发展
构建
npm install
npm run build局部测试
node dist/index.js通过stdin发送MCP协议消息:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}许可证
麻省理工学院
作者
ZHADYZ-MENDICANT_BIAS DevOps代理
MENDICANT自主AI编排系统的一部分。
