MCP服务器备忘录
一个轻量级的MCP(模型上下文协议)服务器,用于管理Claude等LLM的丰富会话摘要和备忘录。此服务器使用本地文件系统提供持久存储,支持会话历史版本跟踪,并提供用于存储、检索和列出摘要的工具。
概述
MCP服务器备忘录被设计为LLM的内存助手,允许它们通过MCP工具界面存储和检索详细的会话记录。服务器:
- 保存历史 -会话的所有历史版本(相同的sessionId)都会被保留,而不仅仅是最新版本
- 订购时间 -会话的多个版本按时间顺序组织,便于跟踪会话的发展
- 本地存储 -使用本地文件系统,不需要外部数据库
- 符合MCP标准 -遵循模型上下文协议规范提供工具接口
- 性能优化 -针对文件I/O和并发操作进行了优化
- 最小依赖性 -简洁的设计,易于维护和扩展
安装
# Clone the repository
git clone https://github.com/doggybee/mcp-server-memo.git
cd mcp-server-memo
# Install dependencies
npm install
# Build the project
npm run build配置
服务器使用以下配置选项:
MCP_SUMMARY_DIR:用于存储摘要的目录(默认:./summaries/)
您可以通过环境变量设置这些选项:
export MCP_SUMMARY_DIR="/path/to/summaries"运行服务器
# Standard startup
npm start
# Development mode (with auto-reload)
npm run dev
# Start with logging to file
npm run start:logMCP工具
服务器提供以下MCP工具:
1.意外摘要
创建会话摘要的新版本,而不删除以前的版本。
参数:
sessionId(字符串,必填):对话会话的唯一标识符。 生成此ID是客户端应用程序的责任。 它应该在新的逻辑对话会话开始时生成一次。 建议: 使用标准 UUID(版本4) 库以您的编程语言提供,以确保唯一性。然后,客户端必须重用 *相同* 为所有后续生成的IDupsertSummary与该特定会议有关的电话。summary(string,必填):会话历史记录/日志的详细内容。每次调用都会在会话历史记录中创建一个新版本,而不是覆盖以前的版本。title(字符串,可选):会话的简短描述性标题。tags(string\[\],可选):用于对会话进行分类的关键字或标签。
行为:
- 使用新的时间戳创建新文件
- 保留所有以前的版本
- 返回新版本的时间戳
2.获取摘要工具
检索特定会话摘要的最新版本。
参数:
sessionId(string,必填):要检索的会话摘要的唯一ID。maxLength(number,可选):如果提供,请将检索到的摘要文本截断到此最大长度。
退货:
- 最新的会话摘要对象(JSON格式)
3.列表摘要工具
列出可用摘要(仅显示每个会话的最新版本),并支持过滤、排序和分页。
参数:
tag(字符串,可选):按特定标记筛选会话。limit(数字,可选):限制结果。offset(数字,可选):分页偏移量。sortBy(字符串,可选):排序字段(“上次更新”或“标题”)。默认值:“lastUpdated”。order(string,可选):排序顺序('sc'或'sec')。默认值:“desc”。
退货:
- 摘要元数据对象列表(JSON格式),每个会话仅包含最新版本
4.更新元数据
仅更新会话最新版本的元数据(标题和/或标签),而不更改摘要内容或时间戳。
参数:
sessionId(string,必填):要更新其元数据的会话的唯一ID。title(字符串,可选):新标题。如果省略,标题保持不变。tags(string\[\],可选):新标签数组。如果省略,标签将保持不变。
注: 至少一个 title 或 tags 必须提供。
行为:
- 不更新文件名或
lastUpdated领域 - 仅修改指定的元数据字段
- 不影响摘要内容
5.附录摘要
将内容附加到会话摘要中,创建一个包含以前内容和新内容的新版本。
参数:
sessionId(字符串,必填):对话会话的唯一标识符。content(string,必填):要附加到会话的内容。这将添加到现有内容中并另存为新版本。title(string,可选):会话的可选标题。tags(string\[\],可选):用于对会话进行分类的可选标记。
行为:
- 读取现有的最新摘要(如果有的话)
- 在内容之间添加两行新行并附加新内容
- 使用新的时间戳创建新文件
- 保留所有以前的版本
6.列出所有摘要工具
列出所有可用的摘要和基本信息(仅每个会话的最新版本)。
参数:
- 无
退货:
- 包含基本信息的所有可用摘要列表(JSON格式)
7.获取会话历史记录
按从最新到最旧的顺序检索特定会话的所有历史版本。
参数:
sessionId(string,必填):要检索历史记录的会话的唯一ID。
退货:
- 所有版本及其完整内容的列表(JSON格式)
客户端工作流示例
下面是一个客户端应用程序如何与此服务器交互的示例:
import { v4 as uuidv4 } from 'uuid';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
// Initialize client
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/index.js'],
cwd: process.cwd()
});
const client = new Client({
name: 'example-client',
version: '1.0.0'
});
await client.connect(transport);
// Function to generate new session ID (done once per logical session)
function createNewSession() {
return uuidv4();
}
// Function to append to an existing session
async function appendToSession(sessionId, newContent) {
return client.callTool({
name: "appendSummary",
arguments: {
sessionId,
content: newContent,
title: "Example Session",
tags: ["example", "demo"]
}
});
}
// Function to get session history
async function getSessionHistory(sessionId) {
const response = await client.callTool({
name: "getSessionHistory",
arguments: { sessionId }
});
const result = JSON.parse(response.content[0].text);
if (result.success) {
return result.history;
}
throw new Error(result.error || "Failed to get session history");
}
// Usage example
const sessionId = createNewSession();
// Add initial content
await appendToSession(sessionId, "Initial conversation data");
// Add more content later in the conversation
await appendToSession(sessionId, "Second part of the conversation");
await appendToSession(sessionId, "Final part of the conversation");
// Get the full history
const history = await getSessionHistory(sessionId);
console.log(`Session ${sessionId} has ${history.length} versions`);项目结构
mcp-server-memo/
├── dist/ # Compiled JavaScript output
├── src/ # TypeScript source code
│ ├── config.ts # Server configuration
│ ├── index.ts # Main entry point
│ ├── storage.ts # File storage utilities
│ ├── tools.ts # MCP tool implementations
│ └── types.ts # TypeScript type definitions
├── summaries/ # Directory for storing session data
│ └── .gitkeep # Ensures directory is included in git
├── package.json # Project metadata and dependencies
├── tsconfig.json # TypeScript configuration
└── LICENSE # MIT License file许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
