Cursor MCP Server
作为Claude桌面应用程序和Cursor编辑器之间的桥梁,通过标准化的通信和安全的基于令牌的身份验证,实现跨平台无缝的AI驱动自动化和多实例管理。
README
Cursor MCP (模型上下文协议)
Cursor MCP 是 Claude 桌面应用程序和 Cursor 编辑器之间的桥梁,可实现无缝的 AI 驱动的自动化和多实例管理。它是更广泛的模型上下文协议 (MCP) 生态系统的一部分,允许 Cursor 通过标准化接口与各种 AI 模型和服务进行交互。
概述
🤖 AI 集成
- 与 Claude 桌面应用程序直接集成
- 能够利用其他 MCP 兼容的 AI 服务
- AI 和编辑器之间的实时上下文共享
- AI 驱动的自动化和代码生成
🔌 MCP 协议支持
- 与 AI 模型进行标准化通信
- 用于其他 MCP 的可扩展插件系统
- 上下文感知的命令执行
- 安全的基于令牌的身份验证
🖥️ 跨平台窗口管理
- 跨操作系统无缝管理 Cursor 编辑器窗口
- 以编程方式聚焦、最小化、恢复和排列窗口
- 跟踪窗口状态更改和位置
- 同时处理多个 Cursor 实例
⌨️ 输入自动化
- AI 驱动的键盘输入,支持:
- 代码生成和插入
- 重构操作
- 上下文感知的补全
- 多光标编辑
- 智能鼠标自动化,包括:
- 智能选择
- 上下文菜单操作
- AI 引导的导航
🔄 进程管理
- AI 编排的实例管理
- 智能工作区组织
- 自动上下文保存
- 智能会话恢复
MCP 集成
Claude 桌面集成
import { ClaudeMCP } from 'cursor-mcp/claude'
// 连接到 Claude 的桌面应用程序
const claude = await ClaudeMCP.connect()
// 执行 AI 驱动的操作
await claude.generateCode({
prompt: '创建一个 React 组件',
context: currentFileContent,
language: 'typescript'
})
// 获取 AI 建议
const suggestions = await claude.getSuggestions({
code: selectedText,
type: 'refactor'
})
使用多个 MCP
import { MCPRegistry } from 'cursor-mcp/registry'
// 注册可用的 MCP
MCPRegistry.register('claude', ClaudeMCP)
MCPRegistry.register('github-copilot', CopilotMCP)
// 使用不同的 AI 服务
const claude = await MCPRegistry.get('claude')
const copilot = await MCPRegistry.get('github-copilot')
// 比较建议
const claudeSuggestions = await claude.getSuggestions(context)
const copilotSuggestions = await copilot.getSuggestions(context)
自定义 MCP 集成
import { BaseMCP, MCPProvider } from 'cursor-mcp/core'
class CustomMCP extends BaseMCP implements MCPProvider {
async connect() {
// 自定义连接逻辑
}
async generateSuggestions(context: CodeContext) {
// 自定义 AI 集成
}
}
// 注册自定义 MCP
MCPRegistry.register('custom-ai', CustomMCP)
配置
该工具可以通过环境变量或以下位置的配置文件进行配置:
- Windows:
%LOCALAPPDATA%\cursor-mcp\config\config.json
- macOS:
~/Library/Application Support/cursor-mcp/config/config.json
- Linux:
~/.config/cursor-mcp/config.json
配置示例:
{
"mcp": {
"claude": {
"enabled": true,
"apiKey": "${CLAUDE_API_KEY}",
"contextWindow": 100000
},
"providers": {
"github-copilot": {
"enabled": true,
"auth": "${GITHUB_TOKEN}"
}
}
},
"autoStart": true,
"maxInstances": 4,
"windowArrangement": "grid",
"logging": {
"level": "info",
"file": "cursor-mcp.log"
}
}
安装
Windows
# 以管理员身份运行
Invoke-WebRequest -Uri "https://github.com/your-org/cursor-mcp/releases/latest/download/cursor-mcp-windows.zip" -OutFile "cursor-mcp.zip"
Expand-Archive -Path "cursor-mcp.zip" -DestinationPath "."
.\windows.ps1
macOS
# 使用 sudo 运行
curl -L "https://github.com/your-org/cursor-mcp/releases/latest/download/cursor-mcp-macos.zip" -o "cursor-mcp.zip"
unzip cursor-mcp.zip
sudo ./macos.sh
Linux
# 使用 sudo 运行
curl -L "https://github.com/your-org/cursor-mcp/releases/latest/download/cursor-mcp-linux.zip" -o "cursor-mcp.zip"
unzip cursor-mcp.zip
sudo ./linux.sh
用法
基本用法
import { CursorInstanceManager } from 'cursor-mcp'
// 获取实例管理器
const manager = CursorInstanceManager.getInstance()
// 启动一个新的 Cursor 实例
await manager.startNewInstance()
// 获取所有正在运行的实例
const instances = await manager.getRunningInstances()
// 聚焦特定实例
await manager.focusInstance(instances[0])
// 关闭所有实例
await manager.closeAllInstances()
窗口管理
import { WindowManager } from 'cursor-mcp'
const windowManager = WindowManager.getInstance()
// 查找所有 Cursor 窗口
const windows = await windowManager.findCursorWindows()
// 聚焦一个窗口
await windowManager.focusWindow(windows[0])
// 将窗口并排排列
await windowManager.arrangeWindows(windows, 'sideBySide')
// 最小化所有窗口
for (const window of windows) {
await windowManager.minimizeWindow(window)
}
输入自动化
import { InputAutomationService } from 'cursor-mcp'
const inputService = InputAutomationService.getInstance()
// 输入文本
await inputService.typeText('Hello, World!')
// 发送键盘快捷键
if (process.platform === 'darwin') {
await inputService.sendKeys(['command', 'c'])
} else {
await inputService.sendKeys(['control', 'c'])
}
// 鼠标操作
await inputService.moveMouse(100, 100)
await inputService.mouseClick('left')
await inputService.mouseDrag(100, 100, 200, 200)
工作原理
桥接架构
该工具充当 Cursor 和 MCP 服务器之间的中间件层:
-
Cursor 集成:
- 监视 Cursor 的文件系统事件
- 捕获编辑器状态和上下文
- 将响应注入回编辑器
- 管理窗口和进程自动化
-
MCP 协议转换:
- 将 Cursor 的内部事件转换为 MCP 协议消息
- 将 MCP 响应转换为 Cursor 兼容的操作
- 维护会话状态和上下文
- 处理身份验证和安全性
-
服务器通信:
- 连接到 Claude 的桌面应用程序 MCP 服务器
- 将请求路由到适当的 AI 提供程序
- 管理与多个 MCP 的并发连接
- 处理回退和错误恢复
graph LR
A[Cursor 编辑器] <--> B[Cursor MCP 桥接]
B <--> C[Claude 桌面 MCP]
B <--> D[GitHub Copilot MCP]
B <--> E[自定义 AI MCP]
示例工作流程
-
代码补全请求:
// 1. Cursor 事件 (文件更改) // 当用户在 Cursor 中输入时: function calculateTotal(items) { // 计算商品的总价| <-- 光标位置 // 2. 桥接转换 const event = { type: 'completion_request', context: { file: 'shopping-cart.ts', line: 2, prefix: '// 计算商品的总价', language: 'typescript', cursor_position: 43 } } // 3. MCP 协议消息 await mcpServer.call('generate_completion', { prompt: event.context, max_tokens: 150, temperature: 0.7 }) // 4. 响应转换 // 桥接转换 MCP 响应: const response = `return items.reduce((total, item) => { return total + (item.price * item.quantity); }, 0);` // 5. Cursor 集成 // 桥接在光标位置注入代码
-
代码重构:
// 1. Cursor 事件 (命令) // 用户选择代码并触发重构命令 const oldCode = ` if (user.age >= 18) { if (user.hasLicense) { if (car.isAvailable) { rentCar(user, car); } } } ` // 2. 桥接转换 const event = { type: 'refactor_request', context: { selection: oldCode, command: 'simplify_nesting' } } // 3. MCP 协议消息 await mcpServer.call('refactor_code', { code: event.context.selection, style: 'simplified', maintain_logic: true }) // 4. 响应转换 const response = ` const canRentCar = user.age >= 18 && user.hasLicense && car.isAvailable; if (canRentCar) { rentCar(user, car); } ` // 5. Cursor 集成 // 桥接替换选定的代码
-
多文件上下文:
// 1. Cursor 事件 (文件依赖项) // 当用户请求有关组件的帮助时 // 2. 桥接转换 const event = { type: 'context_request', files: { 'UserProfile.tsx': '...', 'types.ts': '...', 'api.ts': '...' }, focus_file: 'UserProfile.tsx' } // 3. MCP 协议消息 await mcpServer.call('analyze_context', { files: event.files, primary_file: event.focus_file, analysis_type: 'component_dependencies' }) // 4. 响应处理 // 桥接在请求之间维护上下文
集成方法
-
文件系统监视:
import { FileSystemWatcher } from 'cursor-mcp/watcher' const watcher = new FileSystemWatcher({ paths: ['/path/to/cursor/workspace'], events: ['change', 'create', 'delete'] }) watcher.on('change', async (event) => { const mcpMessage = await bridge.translateEvent(event) await mcpServer.send(mcpMessage) })
-
窗口集成:
import { CursorWindow } from 'cursor-mcp/window' const window = new CursorWindow() // 注入 AI 响应 await window.injectCode({ position: cursorPosition, code: mcpResponse.code, animate: true // 平滑的打字动画 }) // 处理用户交互 window.onCommand('refactor', async (selection) => { const mcpMessage = await bridge.createRefactorRequest(selection) const response = await mcpServer.send(mcpMessage) await window.applyRefactoring(response) })
-
上下文管理:
import { ContextManager } from 'cursor-mcp/context' const context = new ContextManager() // 跟踪文件依赖项 await context.addFile('component.tsx') await context.trackDependencies() // 维护对话历史记录 context.addMessage({ role: 'user', content: '重构此组件' }) // 发送到 MCP 服务器 const response = await mcpServer.send({ type: 'refactor', context: context.getFullContext() })
安全性
- 用于 AI 服务的安全令牌身份验证
- 加密的通信通道
- 沙盒执行环境
- 细粒度的权限控制
要求
Windows
- Windows 10 或更高版本
- Node.js 18 或更高版本
- 安装需要管理员权限
macOS
- macOS 10.15 (Catalina) 或更高版本
- Node.js 18 或更高版本
- Xcode 命令行工具
- 终端的辅助功能权限
Linux
- X11 显示服务器
- Node.js 18 或更高版本
- xdotool
- libxtst-dev
- libpng++-dev
- build-essential
开发
设置
# 克隆存储库
git clone https://github.com/your-org/cursor-mcp.git
cd cursor-mcp
# 安装依赖项
npm install
# 构建项目
npm run build
# 运行测试
npm test
运行测试
# 运行所有测试
npm test
# 运行特定测试套件
npm test -- window-management
# 运行覆盖率测试
npm run test:coverage
贡献
欢迎贡献!请参阅我们的 贡献指南 了解详细信息。
许可证
该项目已获得 MIT 许可证的许可 - 有关详细信息,请参阅 LICENSE 文件。
支持
致谢
- Cursor 编辑器 - AI 优先的代码编辑器
- Claude AI - 高级 AI 助手
- @nut-tree/nut-js - 跨平台自动化
- active-win - 窗口检测
推荐服务器
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
MCP Package Docs Server
促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。
Claude Code MCP
一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。
@kazuph/mcp-taskmanager
用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。
mermaid-mcp-server
一个模型上下文协议 (MCP) 服务器,用于将 Mermaid 图表转换为 PNG 图像。
Jira-Context-MCP
MCP 服务器向 AI 编码助手(如 Cursor)提供 Jira 工单信息。

Linear MCP Server
一个模型上下文协议(Model Context Protocol)服务器,它与 Linear 的问题跟踪系统集成,允许大型语言模型(LLM)通过自然语言交互来创建、更新、搜索和评论 Linear 问题。

Sequential Thinking MCP Server
这个服务器通过将复杂问题分解为顺序步骤来促进结构化的问题解决,支持修订,并通过完整的 MCP 集成来实现多条解决方案路径。
Curri MCP Server
通过管理文本笔记、提供笔记创建工具以及使用结构化提示生成摘要,从而实现与 Curri API 的交互。