一个VS Code扩展,提供了一个模型上下文协议(MCP)服务器,使AI助手能够与您的VS Code环境进行交互,以实现语言智能、调试和代码执行。
语言智能:访问VS Code的语言服务器功能,包括:
调试支持:通过编程方式控制VS Code的调试器:
步骤 1:安装VS Code扩展
从发布页面下载.vsix文件并安装:
... 菜单 → 从VSIX安装code --install-extension mcp-server-vscode-*.vsix步骤 2:配置Claude Desktop
MCP服务器直接从GitHub使用npx运行。在Claude配置中添加以下内容:
~/Library/Application Support/Claude/claude_desktop_config.json{
"mcpServers": {
"vscode": {
"command": "npx",
"args": ["github:malvex/mcp-server-vscode"]
}
}
}
步骤 3:重启Claude Desktop
这样就完成了!现在VS Code工具已经在Claude中可用。
对于Claude Code用户,运行以下一行命令:
claude mcp add-json vscode '{"type":"stdio","command":"npx","args":["github:malvex/mcp-server-vscode"]}' -s user
安装后,扩展会在VS Code的状态栏(右下角)显示MCP服务器状态。
启动MCP服务器:点击状态栏中的“VS Code MCP: 已停止”。当运行时,它会变为“VS Code MCP: 8991”。
状态栏指示:
点击状态栏项目以切换服务器开关。
┌─────────────┐ stdio ┌──────────────────┐ HTTP ┌─────────────┐
│ Claude │ ◄────────────► │ MCP Standalone │ ◄───────────► │ VS Code │
│ Desktop │ │ Server │ :8991 │ Extension │
└─────────────┘ └──────────────────┘ └─────────────┘
如果Claude无法连接到VS Code:
npx github:malvex/mcp-server-vscode该扩展提供了25个工具,分为三大类:
| 工具 | 描述 | 主要参数 | 示例 |
|---|---|---|---|
| hover | 获取符号的悬停信息(类型信息、文档) | symbol(必需),uri(可选),format(可选) | hover({ symbol: "calculateSum" }) |
| definition | 查找符号的定义位置。立即跳转到声明 | symbol(必需),format(可选) | definition({ symbol: "Calculator" }) |
| references | 查找符号的所有引用。优于grep - 找到语义引用 | symbol(必需),includeDeclaration(可选),format(可选) | references({ symbol: "process" }) |
| callHierarchy | 分析什么函数调用了某个函数或某个函数调用了什么 | symbol(必需),direction(必需:'incoming'|'outgoing'|'both'),uri(可选),format(可选) | callHierarchy({ symbol: "initialize", direction: "incoming" }) |
| symbolSearch | 在工作区中搜索符号(类、函数、变量) | query(必需),kind(可选),format(可选) | symbolSearch({ query: "Controller", kind: "class" }) |
| workspaceSymbols | 获取工作区中所有符号的完整映射 | includeDetails(可选),filePattern(可选),maxFiles(可选),format(可选) | workspaceSymbols({ filePattern: "**/*.ts" }) |
| diagnostics | 获取文件或工作区的所有错误和警告 | uri(可选),format(可选) | diagnostics({}) |
| 工具 | 描述 | 主要参数 | 示例 |
|---|---|---|---|
| refactor_rename | 在所有文件中重命名符号。自动更新所有引用和导入 | symbol(必需),newName(必需),uri(可选),format(可选) | refactor_rename({ symbol: "OldName", newName: "NewName" }) |
| 工具 | 描述 | 主要参数 | 示例 |
|---|---|---|---|
| debug_setBreakpoint | 通过符号名称或文件/行设置断点,可选条件 | symbol 或 (file 和 line),condition(可选),hitCondition(可选),logMessage(可选),format(可选) | debug_setBreakpoint({ symbol: "processData", condition: "items.length > 100" }) |
| debug_toggleBreakpoint | 切换特定位置的断点开关 | symbol 或 (file 和 line),format(可选) | debug_toggleBreakpoint({ file: "app.js", line: 25 }) |
| debug_listBreakpoints | 列出工作区中的所有断点 | format(可选) | debug_listBreakpoints({}) |
| debug_clearBreakpoints | 清除工作区中的所有断点 | format(可选) | debug_clearBreakpoints({}) |
| 工具 | 描述 | 主要参数 | 示例 |
|---|---|---|---|
| debug_status | 获取当前调试会话状态和活动线程 | format(可选) | debug_status({}) |
| debug_listConfigurations | 列出launch.json中的可用调试配置 | format(可选) | debug_listConfigurations({}) |
| debug_startSession | 使用配置启动调试会话 | configuration(可选),format(可选) | debug_startSession({ configuration: "Launch Program" }) |
| debug_stopSession | 停止当前活动的调试会话 | format(可选) | debug_stopSession({}) |
| 工具 | 描述 | 主要参数 | 示例 |
|---|---|---|---|
| debug_pauseExecution | 暂停正在运行的程序 | threadId(可选),format(可选) | debug_pauseExecution({}) |
| debug_continueExecution | 继续从当前断点执行 | threadId(可选),allThreads(可选),format(可选) | debug_continueExecution({}) |
| debug_stepOver | 跳过当前行的代码 | threadId(可选),format(可选) | debug_stepOver({}) |
| debug_stepInto | 进入当前行的函数调用 | threadId(可选),format(可选) | debug_stepInto({}) |
| debug_stepOut | 退出当前函数 | threadId(可选),format(可选) | debug_stepOut({}) |
| 工具 | 描述 | 主要参数 | 示例 |
|---|---|---|---|
| debug_getCallStack | 获取当前调用堆栈及其源位置 | threadId(可选),startFrame(可选),levels(可选),format(可选) | debug_getCallStack({ levels: 10 }) |
| debug_inspectVariables | 在调试期间检查当前作用域中的变量 | threadId(可选),frameId(可选),scope(可选:'all'|'locals'|'globals'|'closure'),filter(可选),format(可选) | debug_inspectVariables({ scope: "locals" }) |
| debug_evaluateExpression | 在调试上下文中评估表达式 | expression(必需),frameId(可选),context(可选),format(可选) | debug_evaluateExpression({ expression: "user.permissions" }) |
| debug_getOutput | 获取调试控制台输出 | category(可选),filter(可选),limit(可选),format(可选) | debug_getOutput({}) |
所有工具都支持:
当通过MCP连接时,AI助手可以使用这些工具帮助用户完成开发任务:
用户:"handleRequest函数的作用是什么?"
AI 使用:hover({ symbol: "handleRequest" })
→ 获取类型签名和文档,无需阅读整个文件
用户:"DatabaseConnection类在哪里定义的?"
AI 使用:definition({ symbol: "DatabaseConnection" })
→ 立即找到声明的文件和行
用户:"展示所有调用processPayment的地方"
AI 使用:callHierarchy({ symbol: "processPayment", direction: "incoming" })
→ 获取完整的调用者列表及其位置
用户:"将oldMethodName方法重命名为newMethodName"
AI 使用:refactor_rename({ symbol: "oldMethodName", newName: "newMethodName" })
→ 安全地在所有文件中重命名,更新导入和引用
用户:"帮我调试为什么服务器崩溃"
AI 使用:debug_listConfigurations({})
→ 展示可用的调试配置
AI 使用:debug_startSession({ configuration: "Debug Server" })
→ 启动调试会话
用户:"在处理错误的地方设置一个断点"
AI 使用:debug_setBreakpoint({ symbol: "handleError" })
→ 在函数上设置断点
用户:"这里的user对象值是什么?"
AI 使用:debug_inspectVariables({ scope: "locals", filter: "user" })
→ 显示调试上下文中user变量的当前值
用户:"为什么这个条件为真?"
AI 使用:debug_evaluateExpression({ expression: "users.length > 0 && isActive" })
→ 在当前调试范围内评估表达式
# 克隆仓库
git clone https://github.com/malvex/mcp-server-vscode.git
cd mcp-server-vscode
# 安装依赖
npm install
# 构建所有内容
npm run compile
npm run package
# 打包VS Code扩展
npx vsce package
要测试您的本地开发版本:
{
"mcpServers": {
"vscode": {
"command": "node",
"args": ["/path/to/mcp-server-vscode/out/mcp/standalone-server.js"]
}
}
}
本项目根据MIT许可证发布 - 详情见LICENSE文件。