🚀 Cursor Chat History MCP
本项目允许AI助手访问你的Cursor聊天历史记录。借助Model Context Protocol (MCP) 服务器,Cursor、Claude等AI助手能够读取并分析你的Cursor聊天数据,从而基于你的实际开发模式和历史记录提供个性化的编码辅助。
🚀 快速开始
1. 配置MCP
在你的 .cursor/mcp.json 文件中添加以下内容:
{
"mcpServers": {
"cursor-chat-history": {
"command": "npx",
"args": ["-y", "--package=cursor-chat-history-mcp", "cursor-chat-history-mcp"]
}
}
}
2. 开始使用
你可以向AI助手提出如下指令:
"Analyze my React conversations and create component guidelines"
"Find debugging patterns in my chat history"
"Generate TypeScript coding standards from my actual usage"
"What are the main themes in my recent coding discussions?"
✨ 主要特性
本项目的功能
你可以要求AI助手完成以下任务:
- 分析你的聊天历史记录,以了解你的编码模式和使用统计信息。
- 根据你实际的开发讨论生成特定项目的规则。
- 从过去的问题解决会话中提取见解,并查找相关对话。
- 根据关于你代码的真实对话创建文档。
- 导出聊天数据,以便进行外部分析和可视化。
- 查找并应用你已经解决过的问题的解决方案。
核心优势
- 生成个性化规则:根据你实际的开发模式创建编码标准,而非通用的最佳实践。
- 从历史中学习:从过去的聊天记录中提取见解,以改进未来的开发工作。
- 上下文感知辅助:获得基于你特定项目和编码风格的帮助。
- 模式识别:识别你开发工作中反复出现的主题和解决方案。
📦 安装指南
开发环境安装
git clone https://github.com/vltansky/cursor-chat-history-mcp
cd cursor-chat-history-mcp
yarn install
yarn build
使用环境安装
上述的 npx 配置会自动处理安装过程。
💻 使用示例
基础用法
{
"mcpServers": {
"cursor-chat-history": {
"command": "npx",
"args": ["-y", "--package=cursor-chat-history-mcp", "cursor-chat-history-mcp"]
}
}
}
高级用法
"Analyze my React conversations and create component guidelines"
"Find debugging patterns in my chat history"
"Generate TypeScript coding standards from my actual usage"
"What are the main themes in my recent coding discussions?"
📚 详细文档
可用工具
核心工具
list_conversations - 可通过过滤选项浏览对话,并可选择对项目相关性进行评分。
get_conversation - 检索包含代码和文件引用的完整对话内容。
search_conversations - 支持多关键字、LIKE模式和文本搜索的增强搜索功能。
分析与数据提取工具
get_conversation_analytics - 提供全面的分析,包括使用模式、文件活动、编程语言分布和时间趋势。
find_related_conversations - 查找通过共享文件、文件夹、语言、大小或时间接近度相关联的对话。
extract_conversation_elements - 灵活分组提取文件、代码块、语言、元数据和对话结构。
export_conversation_data - 以JSON、CSV或图形格式导出聊天数据,以便进行外部分析和可视化。
常见用例
生成编码规则
"Create TypeScript interface naming conventions from my conversations"
"Extract error handling patterns and create guidelines"
"Find all my discussions about testing and create best practices"
提取最佳实践
"Show me how I typically use React hooks in my projects"
"Find patterns in my state management discussions"
"Analyze my class inheritance usage and create guidelines"
高级分析
"Find conversations where I discussed specific functions or patterns"
"Search for file-specific discussions across my projects"
"Compare how I've approached similar problems over time"
创建项目文档
"Generate API documentation from my service discussions"
"Create technical docs from my auth module conversations"
从过去的解决方案中学习
"Find similar debugging sessions and extract solutions"
"Analyze my performance optimization discussions"
数据分析与洞察
"Get comprehensive analytics on my coding patterns over the last 3 months"
"Export all conversations with React code to CSV for analysis"
"Find conversations similar to this database migration discussion"
工具参考
输出格式
所有工具都支持通过 outputMode 参数以JSON格式输出:
json(默认) - 格式良好、具有适当缩进的JSON,便于阅读。
compact-json - 无格式的压缩JSON,尺寸最小。
核心工具
list_conversations
limit(默认值:10) - 要返回的对话数量。
includeAiSummaries(默认值:true) - 包含AI生成的摘要,以便高效浏览。
projectPath - 按项目路径过滤。
includeRelevanceScore(默认值:false) - 按项目路径过滤时包含相关性分数。
hasCodeBlocks - 过滤包含/不包含代码的对话。
keywords - 按关键字搜索。
filePattern - 按文件模式过滤。
get_conversation
conversationId(必需) - 要检索的对话。
summaryOnly(默认值:false) - 获取增强摘要而不获取完整内容,以节省上下文。
includeMetadata(默认值:false) - 包含额外的元数据。
search_conversations - 支持多种方法的增强搜索
- 简单查询:
query - 基本文本搜索(向后兼容)。
- 多关键字:
keywords 数组,搭配 keywordOperator('AND'/'OR')。
- LIKE模式:
likePattern - SQL LIKE模式(% = 任意字符,_ = 单个字符)。
searchType(默认值:'all') - 'all'、'project'、'files'、'code'。
maxResults(默认值:10) - 最大结果数。
includeCode(默认值:true) - 包含代码块。
分析与数据提取工具
get_conversation_analytics
scope(默认值:'all') - 'all'、'recent'、'project'。
projectPath - 关注特定项目(当 scope='project' 时必需)。
recentDays(默认值:30) - 近期范围的时间窗口。
includeBreakdowns(默认值:['files', 'languages']) - 分析类型:'files'、'languages'、'temporal'、'size'。
find_related_conversations
referenceConversationId(必需) - 起始对话。
relationshipTypes(默认值:['files']) - 'files'、'folders'、'languages'、'size'、'temporal'。
maxResults(默认值:10) - 结果数量。
minScore(默认值:0.1) - 最小相似度分数(0 - 1)。
includeScoreBreakdown(默认值:false) - 显示单个关系分数。
extract_conversation_elements
conversationIds - 特定对话(可选,若为空则处理所有对话)。
elements(默认值:['files', 'codeblocks']) - 'files'、'folders'、'languages'、'codeblocks'、'metadata'、'structure'。
includeContext(默认值:false) - 包含周围的消息文本。
groupBy(默认值:'conversation') - 'conversation'、'element'、'none'。
filters - 按代码长度、文件扩展名或语言过滤。
export_conversation_data
conversationIds - 特定对话(可选,若为空则导出所有对话)。
format(默认值:'json') - 'json'、'csv'、'graph'。
includeContent(默认值:false) - 包含完整的消息文本。
includeRelationships(默认值:false) - 计算文件/文件夹连接。
flattenStructure(默认值:false) - 扁平化以兼容CSV。
filters - 按大小、代码块或项目路径过滤。
数据库路径
自动检测的位置如下:
| 属性 |
详情 |
| macOS |
~/Library/Application Support/Cursor/User/globalStorage/state.vscdb |
| Windows |
%APPDATA%/Cursor/User/globalStorage/state.vscdb |
| Linux |
~/.config/Cursor/User/globalStorage/state.vscdb |
技术说明
- 支持旧版和现代版的Cursor对话格式。
- 使用SQLite访问Cursor的聊天数据库。
- 运行前请关闭Cursor,以避免数据库锁定问题。
- 按大小(>1000字节)过滤对话,以排除空对话。
- 使用ROWID进行按时间顺序排序(UUID不按时间顺序排列)。
贡献指南
- 派生仓库。
- 创建功能分支。
- 进行更改。
- 如有必要,添加测试。
- 提交拉取请求。
许可证
本项目采用MIT许可证。