Cursor DB MCP Server

Cursor DB MCP Server

一个模型上下文协议服务器,使 AI 助手能够探索和交互 Cursor IDE 的 SQLite 数据库,从而提供对项目数据、聊天记录和编辑器信息的访问。

Category
访问服务器

README

Cursor DB MCP 服务器

一个用于访问 Cursor IDE SQLite 数据库的模型上下文协议 (MCP) 服务器。此服务器允许 AI 助手探索和交互 Cursor 的项目数据、聊天记录和编辑器信息。

<!-- Claude In Claude GIF -->

Cursor In Cursor GIF

前提条件

Cursor IDE <!-- Claude Desktop (如果你想在 Claude 中使用 MCP) -->

安装

简易安装

使用提供的安装脚本来安装所有依赖项:

python install.py

此脚本将安装:

  • 基本 MCP 服务器和依赖项

<!-- ### 手动安装

  1. 克隆此仓库:
git clone https://github.com/yourusername/cursor-db-mcp.git
cd cursor-db-mcp
  1. 安装基本依赖项:
pip install -r requirements.txt
  1. 安装 MCP CLI 工具(可选,用于测试):
pip install 'mcp[cli]'  # 注意 mcp[cli] 周围的引号

如果上述命令失败,您可以直接安装 CLI 依赖项:

pip install typer rich
``` -->

<!-- ## 用法

### 与 Claude Desktop 一起使用

1. 在 Claude Desktop 中安装 MCP 服务器:
```bash
mcp install cursor-db-mcp-server.py
  1. 在 Claude Desktop 中,您现在可以通过提问来访问您的 Cursor 数据,例如:

    • "显示我的 Cursor 项目列表"
    • "我的项目 X 的聊天记录是什么?"
    • "查找编辑器 ID Y 的编辑器数据"

    请参阅下面的详细示例

注意:如果 Claude 显示连接到此 MCP 时出错,则可能是因为它找不到 uv。要解决此问题,请更改命令值以包含 uv 的完全限定路径。例如:

    "Cursor DB Manager": {
      "command": "/Users/johndamask/.local/bin/uv",
      "args": [
        "run",
        "--with",
        "mcp[cli]",
        "mcp",
        "run",
        "/Users/johndamask/code/cursor-db-mcp/cursor-db-mcp-server.py"
      ]
    }
``` -->

## 与 Cursor IDE 一起使用

1. 打开 Cursor 并导航到 Settings->Cursor Settings->MCP。
2. 点击:Add new MCP server
3. Name: Cursor DB MCP; Type: Command
4. Command: \<完全限定的路径到\>uv run --with mcp[cli] mcp run \<完全限定的路径到\>/cursor-db-mcp-server.py

![Cursor DB MCP](./img/cursor-db-mcp.png)

现在您可以询问有关数据库的问题或检索有关历史聊天的信息。

![DB structure](./img/cursor-db-structure.png)

![DB keys](./img/cursor-db-keys.png)

### 与 Claude Desktop 一起使用

[为 Claude Desktop 安装 MCP 服务器](https://modelcontextprotocol.io/quickstart/user)

将此添加到您的 claude_desktop_config.json 文件
"cursor-db-mcp": {
  "command": "<完全限定的路径到 >/uv",
  "args": [
    "run",
    "--with",
    "mcp[cli]",
    "mcp",
    "run",
    "<完全限定的路径到 >/cursor-db-mcp-server.py"
  ]
}

![Cursor DB fuzzy search](./img/mcp-cursor-db-search.png)

## 可用资源

- `cursor://projects` - 列出所有可用的 Cursor 项目
- `cursor://projects/detailed` - 列出包含详细信息的项目
- `cursor://projects/{project_name}/chat` - 获取特定项目的聊天数据
- `cursor://projects/{project_name}/composers` - 获取特定项目的编辑器 ID
- `cursor://composers/{composer_id}` - 获取特定编辑器的数据

## 可用工具

- `query_table` - 查询项目数据库中的特定表
- `refresh_databases` - 刷新数据库路径列表

<!-- # Example Usage with Claude

## Listing Projects

**User**: "Can you show me a list of my Cursor projects?"

**Claude**: 

I'll retrieve a list of your Cursor projects.

Here are the Cursor projects I found:

  • project1 (path: /Users/username/Library/Application Support/Cursor/User/workspaceStorage/abc123/state.vscdb)
  • project2 (path: /Users/username/Library/Application Support/Cursor/User/workspaceStorage/def456/state.vscdb)
  • custom-project (path: /Users/username/code/custom-project/state.vscdb)

## Viewing Chat History

**User**: "Show me the chat history from my 'project1' project."

**Claude**:

I'll retrieve the chat history from your 'project1' project.

Here's the chat history I found:

Chat: "Understanding React Hooks"

  • You: "Can you explain how useEffect works in React?"
  • Claude: "The useEffect hook in React is used for handling side effects in functional components..."

Chat: "Debugging API Connection"

  • You: "I'm getting a 401 error when connecting to the API. Here's my code..."
  • Claude: "It looks like you're missing the authorization header in your request..."

## Querying Database Tables

**User**: "Can you search for keys related to 'settings' in the ItemTable of my 'project1' project?"

**Claude**:

I'll search for keys related to 'settings' in the ItemTable of your 'project1' project.

Here are the results:

  1. Key: "workbench.settings.editor" Value: {"mode": "ui", "lastFocusedSettingId": "editor.fontSize"}

  2. Key: "settings.language" Value: "en"

  3. Key: "settings.theme" Value: "dark"


## Analyzing Chat Data

**User**: "Can you analyze the chat data from my 'project1' project and tell me what topics I've been discussing most frequently?"

**Claude**:

I'll analyze the chat data from your 'project1' project.

Based on your chat history, here are the most frequent topics you've been discussing:

  1. React Hooks and Components (5 conversations)
  2. API Integration (3 conversations)
  3. CSS Styling (2 conversations)
  4. Performance Optimization (2 conversations)
  5. Debugging (1 conversation)

The most common questions were about state management in React and handling API responses.


# Architecture

The server uses the Model Context Protocol (MCP) to expose Cursor's SQLite databases to AI assistants. Key components include:

1. **Lifespan Context Management**: The server uses MCP's lifespan API to efficiently manage resources throughout the server's lifecycle.

2. **CursorDBManager**: Handles the detection and management of Cursor projects and their databases.

3. **Resources**: Expose data from Cursor databases as MCP resources.

4. **Tools**: Provide functionality to query databases and manage projects.

5. **Prompts**: Define reusable templates for AI interactions. -->

# 工作原理

服务器扫描您的 Cursor 安装目录以查找项目数据库(state.vscdb 文件)。然后,它通过 MCP 资源和工具公开这些数据库,允许 AI 助手查询和分析数据。

# 注意事项
1. Cursor 将 AI 对话存储在不同的位置。越来越多的聊天记录作为 "composerData" 存储在 globalStorage/state.vscdb 下。如果您在询问最近项目的聊天记录时没有得到结果,请尝试询问编辑器。
2. 这是在 Mac 上编写的。在其他操作系统上可能会有所不同 (YMMV)。

# 无耻的推广
<img src="./img/cursor-journal-logo_thumbnail.jpg" width="150" />

喜欢这个吗?尝试 [Cursor Journal](https://medium.com/@jbdamask/building-cursor-journal-with-cursor-77445026a08c) 直接从 Cursor 聊天记录创建 DevLogs!

# 许可证

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选