🚀 Cursor Chat History MCP
Cursor Chat History MCP 是一個模型上下文協議(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 許可證。