这是一个允许 AI(如 Cursor 中的 Claude)通过 Model Context Protocol (MCP) 直接执行 VSCode 命令的扩展。它极大地提升了 AI 与 VSCode 的协作效率,让开发工作更加流畅。
本扩展的工作流程简单清晰,只需按照以下步骤操作,即可让 AI 轻松使用 VSCode 命令工具:
~/.cursor/mcp.json 配置。graph TB
subgraph "Cursor"
LLM["AI Assistant
(Claude)"]
end
subgraph "VSCode Extension"
SSE["SSE Server
(Dynamic Port)"]
MCP["MCP Handler"]
Commands["VSCode
Commands"]
end
subgraph "Auto Config"
Config["~/.cursor/
mcp.json"]
end
LLM <-->|"MCP over SSE"| SSE
SSE <--> MCP
MCP <-->|"API Calls"| Commands
SSE -.->|"Auto Update"| Config
style LLM fill:#e1f5fe
style SSE fill:#e8f5e9
style MCP fill:#fff3e0
style Commands fill:#f3e5f5
style Config fill:#fce4ec
graph LR
A["📦 安装
npm install
npm run compile"]
B["📄 打包
npx vsce package"]
C["🔌 安装扩展
Install from VSIX"]
D["▶️ 启动
Start MCP Server"]
E["✅ 完成
在 Cursor 中使用"]
A --> B
B --> C
C --> D
D --> E
style A fill:#fff3e0
style B fill:#e8f5e9
style C fill:#e1f5fe
style D fill:#f3e5f5
style E fill:#e8f5e9
git clone https://github.com/louisfghbvc/mcp-vscode-commands.git
cd mcp-vscode-commands
npm install
# 编译 TypeScript
npm run compile
# 打包扩展
npx vsce package
Ctrl/Cmd + Shift + X)。.vsix 文件。Ctrl/Cmd + Shift + P)。Start MCP Server。~/.cursor/mcp.json。请帮我格式化当前文件
请列出所有编辑器相关的命令
请执行 workbench.action.openSettings 开启设定
请新建一个终端
{
"name": "vscode.listCommands",
"arguments": {
"filter": "editor"
}
}
{
"name": "vscode.executeCommand",
"arguments": {
"commandId": "editor.action.formatDocument"
}
}
{
"name": "vscode.executeCommand",
"arguments": {
"commandId": "vscode.open",
"args": ["file:///path/to/file.txt"]
}
}
在 VSCode 设定中配置:
mcpVscodeCommands.autoStart:自动启动 MCP server (预设: true)。mcpVscodeCommands.logLevel:日志级别 (预设: info)。editor.action.formatDocument - 格式化文件。editor.action.organizeImports - 整理 imports。editor.action.commentLine - 切换注解。editor.action.duplicateSelection - 复制选取内容。workbench.action.files.save - 保存当前档案。workbench.action.files.saveAll - 保存所有档案。workbench.action.files.newUntitledFile - 新建档案。workbench.action.quickOpen - 快速开启档案。workbench.action.showCommands - 显示命令面板。workbench.action.gotoSymbol - 跳到符号。workbench.action.terminal.new - 开启新终端。workbench.action.terminal.toggleTerminal - 切换终端。# 自动扫描并测试
node examples/test-sse-server.js
# 测试特定端口
node examples/test-sse-server.js 3000
# 扫描端口范围
node examples/test-sse-server.js scan 3000 8000
# 查看 Cursor MCP 配置
cat ~/.cursor/mcp.json
打开 VSCode Developer Tools 查看详细日志。
Start MCP Server - 启动 MCP server 并自动配置。Stop MCP Server - 停止 MCP server 并清理配置。Show MCP Server Status - 显示 server 状态和 URL。mcp-vscode-commands/
├── src/
│ ├── extension.ts # VSCode 扩展主档案
│ ├── mcp-sse-server.ts # SSE-based MCP server
│ ├── types.ts # TypeScript 类型定义
│ └── tools/ # MCP 工具实现
├── examples/
│ ├── README-MCP-Setup.md # 详细设定指南
│ ├── basic-usage.md # 基本使用范例
│ ├── cursor-config.json # Cursor 配置范例
│ └── test-sse-server.js # SSE 测试工具
└── .github/workflows/ # GitHub Actions 自动化
~/.cursor/mcp.json 档案是否正确。MIT License
让 AI 助手与 VSCode 完美协作! 🚀✨