Cursor对话历史分析工具

一个用于查询、导出和分析Cursor IDE对话历史的MCP服务器工具,支持跨工作区搜索和多种数据导出格式。

  • by TaylorChen
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 taylorchen/cursor-db-mcp

使用说明

游标db-mcp(mcp服务器)

用于查询、导出和分析新的Cursor IDE对话历史的MCP服务器 workspaceStorage (SQLite)布局。

亮点

  • 跨所有工作区查询对话(SQLite state.vscdb 在...之下 workspaceStorage)
  • 搜索和分析消息、代码块和估计的代码更改
  • 导出数据 json, csv,或 markdown
  • 用于列出/筛选最近工作区的工作区实用程序
  • 诊断工具,用于发现您环境中的实际存储密钥

数据来源和回退

  • 主要:传统聊天密钥(如果存在): workbench.panel.aichat.view.aichat.chatdata
  • 启发式:如果缺少遗留密钥,服务器将扫描包含以下内容的结构的值 conversations/messages/assistant/role.
  • 最后手段:综合以下对话 aiService.generations (用户端提示)。可选地,它启发式地将以下项目配对 aiService.prompts 助理回复以提高完整性。

注意:根据您的游标版本,助手回复可能不会在已知密钥下本地持久化。诊断工具可以帮助您发现新钥匙。如果您可以共享包含辅助消息的确认密钥/路径,则可以快速调整此服务器。

安装

npm install
npm run build

运行MCP检查器进行本地测试:

npm run inspector

检查器会打印一个本地URL,以便在浏览器中进行交互式测试。

在游标中配置

基本配置:

{
  "mcp.servers": {
    "cursor-db": {
      "command": "cursor-db-mcp",
      "args": []
    }
  }
}

自定义 workspaceStorage 路径:

{
  "mcp.servers": {
    "cursor-db": {
      "command": "cursor-db-mcp",
      "args": ["--workspace-path", "/custom/path/to/workspaceStorage"]
    }
  }
}

可用工具

  • list_workspaces

    • 输入: { recent_days?: number }
    • 返回包含哈希、路径、projectPath、lastModified的工作区列表
  • get_workspace_conversations

    • 输入: { workspace_hash: string }
    • 使用 list_workspaces 获得 workspace_hash
    • 返回该工作区的对话
  • get_all_对话

    • 输入: { limit?: number }
    • 返回跨工作区对话(按更新时间排序)
  • 搜索_对话

    • 输入: { query: string, limit?: number }
    • 标题和消息中的全文搜索
  • 分析对话

    • 输入: { conversation_id: string }
    • 返回统计数据(消息计数、代码块、估计的代码更改)
  • export_conversations

    • 输入: { format?: 'json'|'csv'|'markdown', conversation_id?: string, conversation_ids?: string[] }
    • 导出全部或按以下条件筛选的子集 conversation_id/conversation_ids
  • 分析代码统计

    • 输入: { days?: number, group_by?: 'day'|'week'|'month'|'language'|'workspace' }
    • 所选期间的汇总指标
  • 诊断存储

    • 输入: { limit?: number }
    • 列出最大的 ItemTable 每个工作区的键,以帮助定位实际的聊天存储

确保助理在结果中回复

  • 如果您的环境有一个包含完整对话(包括助理消息)的密钥,服务器将直接解析它。
  • 如果没有,服务器将回退到 aiService.generations (仅限用户提示)并尝试将其与 aiService.prompts 助理兴致勃勃地回答。这提高了完整性,但可能无法完全反映原始助理的回答。
  • 为了实现精确的助手输出,请提供已确认的存储密钥或路径,以便Cursor在您的版本中保存助手的回复。

导出格式

  • JSON:原始对话数组
  • CSV:每个对话一行,包含高级元数据
  • Markdown:每个对话部分都有消息和代码块

发展

npm install
npm run build
npm run watch   # optional: incremental builds
npm run inspector

备注

  • SQLite访问使用 sqlite3在某些系统上,您可能需要安装构建工具(例如macOS上的Xcode CLT)。
  • 默认工作区存储路径:
    • macOS: ~/Library/Application Support/Cursor/User/workspaceStorage
    • 窗户: %APPDATA%/Cursor/User/workspaceStorage
    • Linux: ~/.config/Cursor/User/workspaceStorage

故障排除

  • 没有返回对话:

    • 使用 diagnose_storage 检查钥匙。如果不存在类似对话的密钥,则您的游标版本可能不会在本地存储助手回复。
    • 服务器仍将返回来自的合成对话 aiService.generations (用户提示)。提供真实的聊天密钥以启用完整解析。
  • 权限/锁定错误:

    • 确保扫描时Cursor没有锁定数据库。尝试关闭Cursor中的繁重操作。

许可证

麻省理工学院——见 LICENSE.