内容
# VS 调试器 MCP 服务器
[](LICENSE)
[](https://dotnet.microsoft.com/download/dotnet/8.0)
[](https://modelcontextprotocol.io)
通过任何 AI 编码代理控制 Visual Studio 的调试器 — Claude Code、Cursor、GitHub Copilot、Cline、Continue、Windsurf 或任何 MCP 客户端。
```
AI 代理 → MCP (SSE 或 stdio) → VsDebuggerMcp.exe → Visual Studio DTE2 COM API
```
## 快速入门
```bash
# 选项 A:Claude Code 插件(自动启动服务器)
claude plugin marketplace add fhw12345/vs-debugger-mcp
claude plugin install vs-debugger-mcp
claude plugin enable vs-debugger-mcp
# 选项 B:任何 MCP 客户端 — stdio(代理启动服务器)
# 添加到您的代理的 MCP 配置:
# 命令: "C:\path\to\VsDebuggerMcp.exe"
# 参数: ["--stdio"]
# 选项 C:任何 MCP 客户端 — SSE(连接正在运行的服务器)
VsDebuggerMcp.exe # 在 http://localhost:5050/sse 上启动
```
## 要求
- Windows(COM 互操作)
- [.NET 8.0 运行时](https://dotnet.microsoft.com/download/dotnet/8.0)(或用于从源代码构建的 SDK)
- Visual Studio(必须正在运行以使用调试器功能)
## 功能
| 类别 | 功能 |
|----------|-------------|
| **构建** | 构建/重新构建/清理解决方案或项目,列出项目,查询构建状态 |
| **调试生命周期** | 打开/关闭解决方案,启动/停止/重启,附加到 PID 或名称,查询调试模式 |
| **断点** | 添加/删除/切换,条件,跟踪点,命中次数 |
| **步进** | 步过/步入/步出,继续,运行到光标,设置下一语句 |
| **检查** | 局部变量,评估表达式,调用堆栈,线程,变量成员 |
| **线程控制** | 冻结/解冻线程,切换调试器上下文 |
| **异常** | 当前异常详细信息,首次机会中断配置 |
| **输出和监视** | 读取输出窗格,监视表达式,即时窗口 |
## 安装
### Claude Code(插件)
```bash
claude plugin marketplace add fhw12345/vs-debugger-mcp
claude plugin install vs-debugger-mcp
claude plugin enable vs-debugger-mcp
```
服务器在每个会话中自动启动。所有 52 个 MCP 工具立即可用。
要更新到最新版本:
```bash
claude plugins update vs-debugger-mcp@vs-debugger-marketplace
```
<details>
<summary>替代:手动 settings.json</summary>
```json
{
"extraKnownMarketplaces": {
"vs-debugger-marketplace": {
"source": { "source": "github", "repo": "fhw12345/vs-debugger-mcp" }
}
},
"enabledPlugins": {
"vs-debugger-mcp@vs-debugger-marketplace": true
}
}
```
</details>
<details>
<summary>替代:手动 MCP 注册(无插件)</summary>
```bash
dotnet run # 或:dist/net8.0-windows/VsDebuggerMcp.exe
claude mcp add --transport sse vs-debugger http://localhost:5050/sse
```
</details>
### Cursor / Cline / Continue / Windsurf / GitHub Copilot
所有这些代理都支持 MCP。选择 **stdio**(推荐 — 代理自动启动服务器)或 **SSE**(连接正在运行的服务器)。
#### stdio(推荐)
代理将 `VsDebuggerMcp.exe --stdio` 作为子进程启动。不需要手动服务器管理。
| 代理 | 配置文件 | 配置 |
|-------|------------|--------|
| **Cursor** | `.cursor/mcp.json` | `{ "mcpServers": { "vs-debugger": { "command": "C:\\path\\to\\VsDebuggerMcp.exe", "args": ["--stdio"] } } }` |
| **GitHub Copilot** | `.vscode/mcp.json` | `{ "servers": { "vs-debugger": { "type": "stdio", "command": "C:\\path\\to\\VsDebuggerMcp.exe", "args": ["--stdio"] } } }` |
| **Cline** | MCP 服务器面板 | `{ "mcpServers": { "vs-debugger": { "command": "C:\\path\\to\\VsDebuggerMcp.exe", "args": ["--stdio"] } } }` |
| **Continue** | `.continue/mcpServers/mcp.json` | `{ "mcpServers": { "vs-debugger": { "command": "C:\\path\\to\\VsDebuggerMcp.exe", "args": ["--stdio"] } } }` |
| **Windsurf** | `~/.codeium/windsurf/mcp_config.json` | `{ "mcpServers": { "vs-debugger": { "command": "C:\\path\\to\\VsDebuggerMcp.exe", "args": ["--stdio"] } } }` |
> **注意:** GitHub Copilot 使用 `"servers"` 作为顶级键;其他所有键都使用 `"mcpServers"`。
<details>
<summary>完整的 JSON 示例</summary>
**Cursor**(`.cursor/mcp.json` 或 `~/.cursor/mcp.json`):
```json
{
"mcpServers": {
"vs-debugger": {
"command": "C:\\path\\to\\VsDebuggerMcp.exe",
"args": ["--stdio"]
}
}
}
```
**GitHub Copilot**(`.vscode/mcp.json`):
```json
{
"servers": {
"vs-debugger": {
"type": "stdio",
"command": "C:\\path\\to\\VsDebuggerMcp.exe",
"args": ["--stdio"]
}
}
}
```
**Cline** (`%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json`):
```json
{
"mcpServers": {
"vs-debugger": {
"command": "C:\\path\\to\\VsDebuggerMcp.exe",
"args": ["--stdio"],
"disabled": false,
"autoApprove": []
}
}
}
```
**Continue** (`.continue/mcpServers/mcp.json`):
```json
{
"mcpServers": {
"vs-debugger": {
"command": "C:\\path\\to\\VsDebuggerMcp.exe",
"args": ["--stdio"]
}
}
}
```
**Windsurf** (`~/.codeium/windsurf/mcp_config.json`):
```json
{
"mcpServers": {
"vs-debugger": {
"command": "C:\\path\\to\\VsDebuggerMcp.exe",
"args": ["--stdio"]
}
}
}
```
</details>
#### SSE(手动服务器)
首先启动服务器,然后将代理指向 `http://localhost:5050/sse`:
```bash
VsDebuggerMcp.exe # 或:dotnet run
```
| 代理 | 配置文件 | SSE URL 字段 |
|-------|------------|---------------|
| **Cursor** | `.cursor/mcp.json` | `"url": "http://localhost:5050/sse"` |
| **GitHub Copilot** | `.vscode/mcp.json` | `"type": "sse", "url": "http://localhost:5050/sse"` |
| **Cline** | MCP 服务器面板 | `"type": "sse", "url": "http://localhost:5050/sse"` |
| **Continue** | `.continue/mcpServers/mcp.json` | `"type": "sse", "url": "http://localhost:5050/sse"` |
| **Windsurf** | `~/.codeium/windsurf/mcp_config.json` | `"serverUrl": "http://localhost:5050/sse"` |
> **Windsurf 注意:** 使用 `"serverUrl"` 代替 `"url"`。
#### 任何其他 MCP 客户端
- **stdio:** 启动 `VsDebuggerMcp.exe --stdio` 作为子进程
- **SSE:** 连接到 `http://localhost:5050/sse`
可在 [`editors/`](editors/) 目录中找到现成的配置模板。
## 工具参考
<details>
<summary><strong>构建工具</strong>(6 个工具)</summary>
| 工具 | 描述 |
|------|-------------|
| `BuildSolution` | 构建整个解决方案 |
| `RebuildSolution` | 重新构建整个解决方案 |
| `BuildProject` | 构建特定项目(支持模糊名称匹配) |
| `ListProjects` | 列出所有项目及其唯一名称 |
| `GetBuildStatus` | 获取当前构建状态 |
| `CleanSolution` | 清理解决方案 |
</details>
<details>
<summary><strong>调试生命周期工具</strong>(12 个工具)</summary>
| 工具 | 描述 |
|------|-------------|
| `OpenSolution` | 在 Visual Studio 中打开 .sln 或 .csproj(如果未运行,则启动 VS) |
| `CloseSolution` | 关闭当前解决方案,可选退出 VS |
| `DebugStart` | 启动调试(F5) |
| `DebugStartWithBuild` | 构建然后启动调试启动项目 |
| `DebugStartWithoutDebugging` | 启动而不调试(Ctrl+F5) |
| `DebugStop` | 停止调试(Shift+F5) |
| `DebugRestart` | 重启调试 |
| `DebugGetMode` | 获取当前调试模式(设计/中断/运行) |
| `DebugBreakAll` | 中断所有执行 |
| `DebugListProcesses` | 列出可用进程(可选名称筛选) |
| `DebugAttachToProcess` | 附加到进程的 PID |
| `DebugAttachToProcessByName` | 按名称附加到进程 |
</details>
<details>
<summary><strong>断点工具</strong>(8 个工具)</summary>
文件路径可以是绝对的,也可以是相对于打开的解决方案。
| 工具 | 描述 |
|------|-------------|
| `BreakpointAdd` | 在文件:行添加断点 |
| `BreakpointAddConditional` | 添加条件断点 |
| `BreakpointAddTracepoint` | 添加跟踪点(记录而不中断) |
| `BreakpointAddHitCount` | 添加命中次数断点(等于/大于/多个) |
| `BreakpointRemove` | 删除断点 |
| `BreakpointToggle` | 切换断点启用/禁用 |
| `BreakpointList` | 列出所有断点 |
| `BreakpointRemoveAll` | 删除所有断点 |
</details>
<details>
<summary><strong>步进工具</strong>(6 个工具)</summary>
响应包括 Visual Studio 暴露文件和行信息时的源代码预览。
| 工具 | 描述 |
|------|-------------|
| `DebugStepOver` | 步过(F10) |
| `DebugStepInto` | 步入(F11) |
| `DebugStepOut` | 步出(Shift+F11) |
| `DebugContinue` | 继续执行(F5) |
| `DebugRunToCursor` | 运行到光标位置 |
| `DebugSetNextStatement` | 将执行指针移动到特定行 |
</details>
<details>
<summary><strong>检查工具</strong>(9 个工具)</summary>
| 工具 | 描述 |
|------|-------------|
| `DebugGetLocals` | 获取当前堆栈帧中的局部变量 |
| `DebugEvaluate` | 评估表达式 |
| `DebugGetCallStack` | 获取当前调用堆栈 |
| `DebugGetCurrentLocation` | 获取当前文件、行、函数和附近的源代码 |
| `DebugGetThreads` | 列出所有线程 |
| `DebugInspectVariable` | 展开变量以查看成员 |
| `DebugFreezeThread` | 冻结线程 |
| `DebugThawThread` | 解冻(取消冻结)线程 |
| `DebugSwitchThread` | 切换调试器到特定线程 |
</details>
<details>
<summary><strong>异常工具</strong>(3 个工具)</summary>
| 工具 | 描述 |
|------|-------------|
| `ExceptionGetCurrent` | 获取当前异常详细信息(类型、消息、堆栈跟踪) |
| `ExceptionEnableBreak` | 为 CLR 异常类型启用首次机会中断 |
| `ExceptionListSettings` | 列出异常组 |
</details>
<details>
<summary><strong>输出工具</strong>(4 个工具)</summary>
| 工具 | 描述 |
|------|-------------|
| `OutputReadDebug` | 读取调试输出窗格(最后 N 行) |
| `OutputListPanes` | 列出所有输出窗口窗格 |
| `OutputReadPane` | 读取特定输出窗格按名称 |
| `OutputImmediateExecute` | 在即时窗口上下文中评估 |
</details>
<details>
<summary><strong>监视工具</strong>(4 个工具)</summary>
| 工具 | 描述 |
|------|-------------|
| `WatchEvaluate` | 评估具有成员扩展的监视表达式 |
| `WatchEvaluateMultiple` | 一次评估多个表达式(分号分隔) |
| `WatchAdd` | 将监视表达式添加到监视窗口 |
| `WatchClearAll` | 清除所有监视表达式 |
</details>
## 从源代码构建
```bash
dotnet build # 构建
dotnet run # 运行(SSE 模式,端口 5050)
dotnet run -- --stdio # 运行(stdio 模式)
dotnet publish -c Release -o dist/net8.0-windows --no-self-contained # 发布
```
## 许可证
[MIT](LICENSE)