mcp netcoredbg
的MCP服务器。NET调试通过 netcoredbg.
允许AI代理(Claude等)设置断点、遍历代码和检查中的变量。NET应用程序。
建筑
┌─────────┐ MCP ┌─────────────────┐ DAP ┌─────────────┐
│ Claude │ ──────────► │ mcp-netcoredbg │ ──────────► │ netcoredbg │
│ │ (tools) │ (this repo) │ (stdio) │ (Samsung) │
└─────────┘ └─────────────────┘ └──────┬──────┘
│
▼
┌─────────────┐
│ .NET App │
└─────────────┘工具
会话管理(v2.0中的新功能)
| 工具 | 说明 |
|---|---|
list_sessions | 列出所有活动的调试会话 |
select_session | 为命令设置默认会话 |
terminate_session | 终止特定会话 |
启动和连接
| 工具 | 说明 |
|---|---|
launch | 开始调试a。NET应用程序(DLL路径) |
launch_watch | 使用热重新加载开始调试 通过 dotnet watch |
stop_watch | 停止热重载调试模式 |
attach | 附属于跑步。NET进程 |
invoke | 调用特定方法 在程序集中(带可选调试) |
restart | 重新启动已调试的程序(用于 launch 模式) |
terminate | 停止调试会话 |
断点
| 工具 | 说明 |
|---|---|
set_breakpoint | 在file:行设置断点(支持条件) |
remove_breakpoint | 删除断点 |
list_breakpoints | 列出所有活动断点 |
执行控制
| 工具 | 说明 |
|---|---|
continue | 继续执行 |
pause | 暂停执行 |
step_over | 跨过当前线路 |
step_into | 进入函数调用 |
step_out | 退出当前功能 |
检查
| 工具 | 说明 |
|---|---|
stack_trace | 获取当前调用堆栈 |
scopes | 获取堆栈帧的变量作用域 |
variables | 从作用域获取变量 |
evaluate | 在调试上下文中计算表达式 |
threads | 列出所有线程 |
output | 获取最近的程序输出 |
status | 获取调试器状态 |
注: 所有工具都接受可选 sessionId 参数以针对特定会话。如果省略,则使用默认会话。
多会话调试(v2.0)
2.0版本引入了对多个同时调试会话的支持。这允许您调试多个。NET应用程序—例如API和后台工作程序。
自动生成的会话ID
当您启动调试会话而不指定 sessionId,一个是从项目/程序名称自动派生出来的:
TopServer.Service.Api→ 会话ID:apiTopServer.Service.Worker→ 会话ID:workerMyApp.Web→ 会话ID:web- 自定义:指定
sessionId显式参数
示例:同时调试API+Worker
# Start API debugging
launch_watch projectPath=/path/to/MyApp.Api launchProfile=https
→ Session 'api' created
# Start Worker in a second session
launch_watch projectPath=/path/to/MyApp.Worker launchProfile=default
→ Session 'worker' created
# List all sessions
list_sessions
→ api (default): watch - /path/to/MyApp.Api [running]
worker: watch - /path/to/MyApp.Worker [running]
# Set breakpoint in API
set_breakpoint file=/path/to/ApiController.cs line=42 sessionId=api
# Set breakpoint in Worker
set_breakpoint file=/path/to/WorkerService.cs line=100 sessionId=worker
# Continue API execution
continue sessionId=api
# Check Worker status
status sessionId=worker
# Switch default session
select_session sessionId=worker
# Now commands without sessionId go to worker
continue # continues worker会话管理命令
| 命令 | 描述 |
|---|---|
list_sessions | 显示所有活动会话及其状态 |
select_session | 更改默认情况下接收命令的会话 |
terminate_session | 停止特定会话 |
向后兼容
如果只使用一个会话,则从v1.x开始行为不变-否 sessionId 需要参数。
方法调用(invoke)
这 invoke 该工具允许您从运行特定方法。NET程序集,而无需启动整个应用程序。这有助于:
- 单独测试单个方法
- 运行实用程序功能
- 调试特定的代码路径,而无需遍历整个应用程序
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
assembly | string | 是 | 到的路径。NET DLL |
type | string | Yes | 完全限定类型名称(例如。, MyApp.Services.Calculator) |
method | string | 是 | 要调用的方法名称 |
args | array | 否 | 方法参数为JSON数组 |
ctorArgs | array | 否 | 构造函数参数(例如实例方法) |
debug | boolean | 否 | 在调试器下启动以支持断点(默认值:false) |
cwd | string | 否 | 工作目录 |
例子
静态方法:
{
"assembly": "/path/to/MyApp.dll",
"type": "MyApp.StringUtils",
"method": "FormatName",
"args": ["John", "Doe"]
}带有构造函数参数的实例方法:
{
"assembly": "/path/to/MyApp.dll",
"type": "MyApp.Calculator",
"method": "Add",
"args": [5],
"ctorArgs": [10]
}通过调试(支持断点):
{
"assembly": "/path/to/MyApp.dll",
"type": "MyApp.Calculator",
"method": "Add",
"args": [5],
"debug": true
}特性
- 静态方法:只需提供类型、方法和参数
- 实例方法:自动构造类型(提供
ctorArgs如果需要) - 自动ILogger注射:
ILogger参数自动解析 - 异步支持:自动等待任务返回方法
- 控制台捕获:捕获
Console.WriteLine输出 - 日志捕获:捕获
ILogger执行过程中拨打的电话 - 丰富的错误:失败时,显示可用的构造函数/方法以帮助您修复调用
输出格式
该工具返回结构化的JSON结果:
{
"success": true,
"method": "MyApp.StringUtils.FormatName",
"args": ["John", "Doe"],
"returnType": "string",
"returnValue": "Doe, John",
"durationMs": 2.5,
"logs": [
{"level": "Information", "message": "Processing..."}
],
"stdout": ""
}出现错误时,它会提供有用的诊断:
{
"success": false,
"error": "Method not found",
"errorDetails": {
"type": "MyApp.StringUtils",
"reason": "Method 'DoSomething' not found",
"methods": [
{"name": "FormatName", "params": ["string firstName", "string lastName"], "returnType": "string", "isStatic": true}
]
}
}热重载调试(launch_watch)
这 launch_watch 该工具支持通过以下方式进行热重载调试 dotnet watch。当您更改代码时,应用程序会自动重新启动,调试器会重新连接,从而保留断点。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
projectPath | string | 是 | 到的路径。NET项目目录(包含.csproj) |
launchProfile | string | 否 | 启动配置文件的名称 Properties/launchSettings.json |
args | array | 否 | 要传递的其他参数 dotnet watch |
例子
基本用法:
{
"projectPath": "/path/to/MyApp"
}使用启动配置文件(建议用于ASP.NET应用程序):
{
"projectPath": "/path/to/MyApp.Api",
"launchProfile": "https"
}发布配置文件对ASP很重要。NET应用程序设置:
ASPNETCORE_ENVIRONMENT(例如,开发)applicationUrl(例如。,https://localhost:7179)- 正常运行所需的其他环境变量
运作原理
- 开始
dotnet watch run使用指定的项目 - 等待应用程序构建和启动
- 自动将调试器附加到正在运行的进程
- 当您编辑代码并保存时,
dotnet watch重建和重新启动 - 调试器检测到重新启动并自动重新连接
- 断点在重启过程中得以保留
停止热重新加载模式
使用 stop_watch 彻底终止调试器和 dotnet watch 过程。
状态信息
使用 status 查看热重载的具体信息:
- 监视进程PID
- 子应用程序PID
- 调试器当前是否正在重新连接
先决条件
- netcoredbg 已安装并位于PATH中
- Node.js 18+
- .NET SDK 8.0+(用于构建线束和目标应用程序)
安装
# Install netcoredbg (example for Linux x64)
curl -sLO https://github.com/Samsung/netcoredbg/releases/download/3.1.3-1062/netcoredbg-linux-amd64.tar.gz
tar xzf netcoredbg-linux-amd64.tar.gz
sudo mv netcoredbg /opt/netcoredbg
sudo ln -sf /opt/netcoredbg/netcoredbg /usr/local/bin/netcoredbg
# Build this MCP server
npm install
npm run build
# The method invocation harness is auto-built on first use使用Claude代码
快速安装:
# Clone and build
git clone https://github.com/AerialByte/mcp-netcoredbg.git
cd mcp-netcoredbg && npm install && npm run build
# Add to Claude Code
claude mcp add netcoredbg -- node $(pwd)/dist/index.js或手动 添加到您的Claude Code MCP设置中:
{
"mcpServers": {
"netcoredbg": {
"command": "node",
"args": ["/path/to/mcp-netcoredbg/dist/index.js"]
}
}
}安全
此工具启动并控制调试器。通过设计,它可以:
- 任意执行。应用程序
- 评估调试进程中的表达式
- 检查内存和变量
仅将其用于您信任的代码。不要调试不受信任的应用程序。
示例会话
完整应用程序调试
- 建立你的。带有调试符号的.NET应用程序:
dotnet build --configuration Debug - 启动调试器:
launch使用DLL路径 - 设置断点:
set_breakpoint在file:行 - 继续/逐步执行代码
- 检查变量
scopes和variables - 使用以下公式计算表达式
evaluate - 完成后终止
方法调用(快速测试)
- 构建目标程序集:
dotnet build - 使用
invoke具有类型和方法名称 - 如果失败,请检查可用构造函数/方法的错误
- 调试:先设置断点,然后使用
invoke随着debug: true
代理商指南
当使用此MCP服务器作为AI代理时:
选择 launch 和 invoke
- 使用
invoke当你想单独测试一个特定的方法时 - 使用
launch当您需要运行完整的应用程序或调试复杂的场景时
使用 invoke 有效地
- 简单开始:不尝试
ctorArgs首先,线束将使用无参数构造函数或自动注入ILogger
- 迭代处理错误:如果调用失败,错误响应将包括可用的方法/构造函数。使用此功能更正您的呼叫。
- 用于调试特定方法:
1. Set breakpoints in the source files first
2. Call invoke with debug: true
3. Use continue/step_over/step_into to navigate
4. Use output to see the final result- 参数为JSON:将args作为JSON数组传递。线束控制类型转换:
- 串: "hello" - 数字: 42, 3.14 - 布尔人: true, false - 无效的: null - 物体: {"name": "Alice", "age": 30}
常见模式
测试实用方法:
invoke assembly=/path/to.dll type=MyApp.Utils method=Parse args=["input"]使用构造函数注入进行测试:
invoke assembly=/path/to.dll type=MyApp.Service method=Process ctorArgs=[100] args=["data"]调试失败的方法:
1. set_breakpoint file=/path/to/Service.cs line=42
2. invoke assembly=/path/to.dll type=MyApp.Service method=Process args=["bad-input"] debug=true
3. (breakpoint hits)
4. variables variablesReference=1
5. continue
6. output许可证
麻省理工学院
