
.NET Debugger for MCP
io.github.nevse由 GitHub 账号 nevse 发布v0.7.1更新于 Oct 30, 2026
Give an AI agent a real .NET debugger: breakpoints, stepping, locals, expression evaluation.
概览
本地 MCP 服务器,为 AI 助手提供真正的 .NET 调试器:启动或附加进程、设置断点、单步执行、查看变量并求值 C# 表达式。
- 可以做什么
- 列出、附加和启动 .NET 进程,运行程序、等待停止、读取程序输出并管理会话
- 按文件行号或方法名设置、列出和删除断点,支持条件与命中次数,并选择哪些异常会中断程序
- 控制执行:继续、暂停、逐行、步入和步出,并读取线程与调用栈
- 查看局部变量、展开对象、求值 C# 表达式并读取异常信息
- 构建并调试 Android 模拟器或设备、iOS 模拟器或设备以及 Mac Catalyst 上的 .NET MAUI 应用
- 检索内置的 ICorDebug、调试适配器协议和表达式求值文档
- 适用场景
- 适合在 .NET 程序启动即失败、抛出意外异常或行为异常,而仅阅读代码不足以定位问题时使用。适用于通过 Claude Code、Claude Desktop 或 VS Code 等客户端对桌面和 MAUI 应用进行交互式调试。
- 运行要求
- 以本地 stdio 进程运行,从 NuGet 安装 DotnetDebugger.Mcp,通常通过 dotnet tool exec 或 dnx 并固定版本。需要 Windows、macOS 或 Linux 上的 .NET 10 SDK 或更高版本,以及兼容 MCP 的客户端。可用 DOTNET_DEBUGGER_MCP_* 环境变量调整日志、超时、会话数和脱敏。被调试程序需带 portable PDB 才能绑定断点。
安装
在 SourceWeft 中
- 打开 控制台中的 .NET Debugger for MCP,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
DotnetDebugger.Mcp
An MCP server that lets an AI assistant debug .NET programs: launch or attach to a process, set breakpoints, step through code, inspect variables and evaluate expressions. It also carries a searchable reference on how .NET debuggers work internally.
Published on NuGet as DotnetDebugger.Mcp.
Built on clrdbg, driven over the Debug Adapter Protocol. The
debugger travels inside the package and runs as a child process, so a crash in native debugging code
costs the debug session rather than the server.
Origin. A fork of decriptor/SharpDbg.MCP, now far enough from it to carry its own name: the debugger layer speaks the Debug Adapter Protocol instead of calling a debugger's internal API, the debugger underneath has since changed from SharpDbg to clrdbg, launching a program under the debugger is new, and the two have not shared a commit since. This repository was called
SharpDbg.MCPuntil the first release, and GitHub redirects the old name. TheSHARPDBG_*settings were renamed toDOTNET_DEBUGGER_MCP_*in the release that followed 0.6.3; the old names are no longer read.
What it can do
- Attach to a running .NET process, or launch one and stop before its first line executes
- Set breakpoints by file and line or by method name, with conditions and hit counts
- Step over, into and out of code, and read the call stack for any thread
- Inspect local variables, expand objects member by member, and evaluate C# expressions
- Break on exceptions - all of them, only the unhandled ones, or only the types you name - and read what was thrown
- Read the debuggee's stdout and stderr
- Debug more than one process at once, each with its own breakpoints and stops
- Debug a .NET MAUI app on an Android emulator or phone, an iOS simulator or device, or this Mac as a Mac Catalyst app - building it and stopping before its first line, same as a desktop program
- Search embedded documentation on ICorDebug, the Debug Adapter Protocol and expression evaluation
What it cannot do
Some of these need changes in the underlying debugger rather than here.
- Report the exit code of a process it attached to.
exit_codeisnullthere. The debugger reads the code off a process it started itself and has none for one it was pointed at, so for an attached process there is nothing to report — and the protocol cannot say "unknown", only0, which would be a number this server made up. A program started withlaunch_programdoes report its real code. - Debug a self-contained single-file publish. The runtime is packed inside the executable, so the
debugger shim cannot find it to load the matching components. The attempt fails immediately with
CORDBG_E_DEBUG_COMPONENT_MISSING(0x80131C3C), reported asAttempting to register for runtime startup failed: -2146231236. Self-contained on its own works, and single-file on its own works; only the combination does not. - Watch expressions, hot reload and data breakpoints are not implemented.
Requirements
- .NET 10 SDK or later
- An MCP-compatible client, such as Claude Code or Claude Desktop
- Windows, macOS or Linux
Install
One package carries the debugger and its native shims for every platform, so the same configuration works everywhere. There is nothing to clone or build.
Claude Code, for the current project:
Add --scope user to make it available in every project, or --scope project to write a .mcp.json
that is committed and shared with your team.
VS Code, in .vscode/mcp.json for the workspace, or with MCP: Open User Configuration for every
workspace. VS Code calls the section servers, not mcpServers:
Claude Desktop, by editing ~/.config/Claude/claude_desktop_config.json on macOS and Linux, or
%APPDATA%\Claude\claude_desktop_config.json on Windows:
dnx DotnetDebugger.Mcp --version 0.8.0 --yes is the shorter equivalent, and the form NuGet.org
suggests. Prefer dotnet tool exec in a client launched from a desktop environment rather than from a
shell: dnx lives in the SDK directory, which such a client often does not have on its PATH, while
dotnet reliably is.
A client only connects its MCP servers when a session starts, so restart it after changing the
configuration. To confirm the server is there, run claude mcp list or ask the client to list .NET
processes.
Why the version is pinned
Every command here names a version. Without --version, dotnet tool exec resolves the package on
each start, so a newly published release would run on the next session without anyone having chosen
it. A debugger can read and change everything in the process it attaches to, so which build of it runs
should be a decision rather than a side effect. Change the version in the command to upgrade; the
latest is on nuget.org.
Installing the tool once instead avoids the resolution step on every start:
The command is then dotnet-debugger-mcp, with no arguments. This needs ~/.dotnet/tools on your
PATH, which is why it is not the default suggestion: a client that cannot find the command fails
the same way a wrong path does.
Checking where a package came from
Releases after 0.6.1 carry a build provenance attestation: a statement, signed through GitHub, that
this repository's release workflow built that package from a given commit. To check one before
mirroring or installing it, download the .nupkg from nuget.org and run:
nuget.org adds its own repository signature to every package it accepts, which changes the file, so
the release workflow attests both: the package as built, attached to the GitHub Release, and nuget.org's
copy, once it has checked that copy holds exactly what was built. For 0.6.2 only the first exists:
verify the copy from gh release download v0.6.2 -R nevse/dotnet-debugger-mcp -p '*.nupkg'.
Upgrading
dotnet tool exec can keep running a version it has already downloaded, even after a newer one is
published and indexed. Nothing looks wrong when it does: the server starts, the client reports it as
connected, and the only sign is that the new release's tools are missing.
Measured while releasing 0.1.1. With only 0.1.0 in the local package folder, the unpinned command kept running 0.1.0, and clearing the NuGet HTTP cache did not change that. Naming the version once fetched the new package, after which the unpinned command used it too:
With the version pinned, upgrading is changing it in the command, and the question does not arise. An installed tool is upgraded explicitly too:
To see which version is actually running, ask the client to list this server's tools, or read the first line the server writes to stderr — it names the version at startup. A client's own health check reports only that the process started, not what it is.
A worked example
Catching a program before it has run a single line, which is the case attaching cannot reach:
Tools
Each tool declares MCP annotations, so a client that reads them can approve the read-only ones without asking and still ask for the rest. The last column says which:
- read-only - reads the session or the machine and changes nothing.
- session - changes only the debug session: stepping, resuming, removing a breakpoint. Not destructive.
- runs getters - reads that run the debuggee's own code: the debugger calls
ToString, property getters andDebuggerDisplayto show a value. Not marked read-only, though not destructive either. - ends a launched program - destructive: a program the session launched is killed.
- runs code - destructive and open-world: it starts, builds or evaluates code the agent chose. A breakpoint's condition is a C# expression evaluated at every hit, so setting one counts.
The annotations are hints, and a client is free to ignore them.
Debugging
.NET MAUI
Needs a one-off setup - see Debugging a .NET MAUI app.
Breakpoints
Execution and inspection
Documentation
Things worth knowing
Breakpoints need portable PDBs
A breakpoint binds through the target's symbols, so the debuggee must be built with portable PDBs
sitting next to its assembly. A missing or mismatched PDB is the most common reason set_breakpoint
answers verified: false with No symbols have been loaded for this document.
Debug builds already do this. For a Release build, or any project that changes the defaults:
Optimized code also moves locals out of reach, so get_variables is only fully useful with
<Optimize>false</Optimize>.
macOS: headless environments may need an entitlement
macOS will not let a debugger take another process's task port unless the target carries
com.apple.security.get-task-allow. A program run through the dotnet muxer is fine, because the
muxer ships with that entitlement; an apphost produced by dotnet publish is ad-hoc signed with no
entitlements at all.
The debugger's own side of this needs nothing from you: the debug adapter is started through the
dotnet muxer as well, so it inherits the entitlements that let it debug at all.
On a desktop session this does not affect you. Debugging a self-contained publish carrying no entitlements is verified to work there.
It matters in a headless environment, such as a CI runner, and it fails badly when it does: macOS refuses by blocking rather than returning an error, so the debugger stops responding and the call never comes back. If a launch or attach hangs on macOS with no error at all, sign the target and try again:
with get-task-allow.entitlements containing:
What Just My Code changes about stepping
DOTNET_DEBUGGER_MCP_JUST_MY_CODE=false does not make a step stop in code you have no symbols for. Neither
setting does: a step that lands in a module without symbols steps straight back out, because there is
no source to report a location against. A step through an interpolated string goes through
System.Private.CoreLib and comes back to the next statement of your own method either way.
What the setting changes is which modules get their symbols looked for at all. With Just My Code on, only assemblies built by you are searched; with it off, every module is, so a step does surface inside a dependency you happen to have symbols for. That is what to turn it off for.
What launch_program will run
The debugger starts whatever it is given, so launch_program only accepts a .NET app: a .dll with
its .runtimeconfig.json beside it, or an apphost with the app's .dll and .runtimeconfig.json
beside it under the same name. That covers a normal build and a self-contained publish. A shell, a
system tool or any other native executable is refused, as is a single-file publish, which cannot be
debugged anyway.
Environment variables that load other code into the program are refused too, since any of them turns
launching a legitimate app into running something else: DOTNET_STARTUP_HOOKS,
DOTNET_ADDITIONAL_DEPS, DOTNET_SHARED_STORE, DOTNET_ROOT*, the CoreCLR profiler variables
(CORECLR_ENABLE_PROFILING, CORECLR_PROFILER*, COR_ENABLE_PROFILING, COR_PROFILER*), ASP.NET
Core's hosting startup assemblies (ASPNETCORE_HOSTINGSTARTUPASSEMBLIES,
DOTNET_HOSTINGSTARTUPASSEMBLIES), LD_PRELOAD, LD_LIBRARY_PATH, LD_AUDIT and every DYLD_*.
A launchSettings.json profile is read by this server, not handed to the debugger. Pass project_path
(the project file or its directory) and optionally launch_profile. With no name given, the https
profile is used, or else the first profile with commandName: "Project". Its commandLineArgs,
workingDirectory and environmentVariables become the launch's arguments, working directory and
environment, and applicationUrl becomes ASPNETCORE_URLS. These are then checked the same way as the
parameters above. Arguments and a working directory passed to launch_program replace the profile's.
Passed environment variables are added on top of the profile's. Only Project profiles are accepted,
because an Executable profile names a program of its own, and executablePath is ignored, so the
program is always the one passed in. Values are used literally: neither $(...) nor %VAR% is expanded.
The profile comes with the repository, so it gets no more trust than the agent does: a startup hook set
in it is refused like any other, and the error names the profile. A project with no launchSettings.json
is launched without a profile unless one was named.
This is not a sandbox, and it does not stop launch_program from serving as a shell. A .NET app can do
anything its user can, an agent able to write and build code can launch what it built, and ready-made
.NET apps that run other programs are already on the machine: the SDK's own
sdk/<version>/dotnet.dll has its .runtimeconfig.json beside it, so launching it reaches the whole
dotnet CLI, building and running any project included. evaluate_expression can call
Process.Start in whatever is being debugged. What the check stops is the agent naming a native
program directly. Treat a client that allows this server's tools as one that allows a shell, and
confirm launch_program, evaluate_expression, build_mobile_app and attach_to_process calls rather
than approving them automatically, along with set_breakpoint and set_function_breakpoint, whose
condition is code run at every hit. All of these are annotated as destructive and open-world, together
with start_program and launch_mobile_app (see Tools), so a client that honours the
annotations can be set to ask for those and approve the reads.
Secrets in what the debugger shows
Values read from the debuggee go to the model, so get_variables, expand_variable,
evaluate_expression, get_exception_info and get_program_output mask what looks like a secret
first, as [redacted: N chars]. Two rules decide it:
- By name. A string whose variable or member name contains
password,passwd,pwd,secret,token,apiKey,connectionString,credential,privateKey,accessKeyorauthorizationis masked whole. Only strings: anint tokenCountor aCancellationToken tokenshows as it is. An object is not masked, and its members are checked when they are expanded. Forevaluate_expressionthe name is the last member the expression reads, soconfig.Db.Passwordcounts. - By format. In any text, named or not:
BearerandBasiccredentials, JWTs,Password=,Pwd=,ApiKey=,sig=and the like inside connection strings and URLs, keys with a well-known prefix (sk-,ghp_,github_pat_,AKIA,xoxb-,AIza), and PEM private keys. Only the secret itself is masked, so the rest of a connection string stays readable.
null and an empty string are shown as they are, since whether a secret is set at all is often the
question. Each response says how many values it masked in redacted.
The server's own log, which MCP clients usually keep on disk, records only how long each line of program
output was. The text itself is logged at DOTNET_DEBUGGER_MCP_LOG_LEVEL=Debug and below, masked one line at a
time, so a secret printed over several lines, such as a PEM key, may be masked only in part there. Errors the
debugger reports after a request gave up waiting, and the debugger's own diagnostic output, are masked too.
This reduces exposure; it does not prevent it. A secret in a variable called s, in a format the
patterns do not know, or read piecemeal - evaluate_expression of password.Length or password[0] -
passes. Set DOTNET_DEBUGGER_MCP_REDACT_SECRETS=false to see values unmasked; the agent has no way to
turn it off itself.
Running code in the program
evaluate_expression runs whatever the expression calls - a property getter, ToString, any method,
Process.Start included - with the program's privileges, and listing variables runs property getters,
ToString overrides and DebuggerTypeProxy constructors to show values. That is how a debugger shows
what a program holds, and DOTNET_DEBUGGER_MCP_EVAL_TIMEOUT_MS is the only bound on it by default.
Set DOTNET_DEBUGGER_MCP_ALLOW_FUNC_EVAL=false to stop the debugger running the program's code, whether to
show a value or because an expression asks it to. Fields, locals and arguments are read as usual. A
property is listed as [not evaluated: function evaluation is off], an object shows as its type name in
braces, and an expression that calls anything - a getter, a method, a constructor - fails. The agent has
no way to turn it back on. Two things still run code:
get_exception_infocalls the exception'sMessageandInnerExceptiongetters to report them.- Reading a static field of a type that has not been initialized yet runs that type's static
constructor, in
evaluate_expressionand when static members are expanded alike.
A breakpoint condition is an expression too, so one that calls a getter or a method - items.Count > 3
- cannot be evaluated with this off. Such a breakpoint stops at every hit, as if it had no condition, and nothing in the stop says why. Compare fields instead, or leave the condition out and check after the stop.
This narrows what debugging can run; it does not make the server safe to hand to an agent you do not
trust. launch_program still starts any .NET program.
Attaching to other users' processes
A debugger can read and change everything in the process it attaches to, so by default this server
attaches only to processes belonging to the user it runs as. attach_to_process refuses anything
else before it looks at the process at all, and list_dotnet_processes marks each entry with an
owner of current_user, other_user or unknown.
unknown is refused as well. On Windows that is what a system or elevated process looks like, since
its token cannot be opened, and treating it as your own would make the check decorative wherever the
lookup does not work.
DOTNET_DEBUGGER_MCP_ALLOW_OTHER_USER_PROCESSES=true lifts the restriction. The operating system still has its
own say: on Linux and macOS a normal user cannot attach to another user's process even with this
enabled, so in practice it matters when the server runs elevated or as root.
Debugging more than one process
By default the server debugs one process at a time, and DOTNET_DEBUGGER_MCP_MAX_SESSIONS raises that. Each
session has its own process, breakpoints and stops.
attach_to_process and launch_program return a session_id. While only one session is open you
can ignore it, because every tool defaults to the only session. Taking on a second process opens a
second session rather than failing, and from then on session_id becomes required: with two
processes open, guessing which one a continue_execution was meant for would be worse than asking.
detach_from_process leaves the session open and free, so the next attach or launch reuses it rather
than taking another slot.
The default of one is deliberate. Every attach carries a risk of a native crash inside the debugging shim, so more sessions means more exposure. What such a crash costs is bounded: each session drives its own debug adapter in a process of its own, so the one that crashes takes its session with it and leaves the server and any other session running.
Debugging a .NET MAUI app
A MAUI app is debugged the same way a desktop program is - prepare, set breakpoints, start - but two things have to be true before it can be, and neither is true of an app built the ordinary way.
It has to run on CoreCLR. This debugger attaches to CoreCLR and nothing else, while a MAUI app
still builds against Mono by default. CoreCLR is there from net10.0-android, and from net11.0 for
-ios and -maccatalyst; below those versions the app would build, start, and never connect back,
so build_mobile_app refuses them and says which version would work.
It has to carry the remote debugging library. Debugging a runtime on a phone takes a native library inside the app, which opens the connection the debugger attaches through, and a matching one on this side. Both are open source, part of clrdbg, and ship in this package from the clrdbg release the debugger is built from, so there is nothing to install or set up:
To use a copy built yourself instead - one with tracing compiled in, say - point
DOTNET_DEBUGGER_MCP_REMOTE_CORECLR_HOST at a remote-host directory, DOTNET_DEBUGGER_MCP_REMOTE_CORECLR_TARGET at a
remote-target one, or both. Either half left unset comes from the bundled copy.
Visual Studio's own remote debugger libraries (vsdbg*) are not used, wherever they come from: a
directory holding a file with vsdbg in its name is refused, bundled or configured.
Then the session looks like this:
build_mobile_app adds an MSBuild file of its own to the build - it ships beside the server as
Resources/CopyRemoteCoreclrTargetLibrary.targets, and is readable - which puts the target library
into the app bundle or the Android package. Nothing in your project changes.
Some notes on what each platform does:
- Android. Pick an emulator by its AVD name; it does not have to be running, because the debugger
boots a cold one itself. A phone is picked by its adb serial. The app is built for every ABI at
once, so there is no runtime identifier to choose. The app's logcat output arrives in
get_program_output.uninstall_app: trueclears a previous install first, which is what to reach for when a signature or a permission has changed. - iOS. A simulator is picked by its UDID and booted if it is not running. A physical device has to be provisioned for the app the usual way - the debugger installs and launches it, it does not sign it.
- Mac Catalyst. The device id is
maccatalyst; there is nothing to boot or install, which makes it the quickest way to check that the setup works at all.
process_id stays null throughout: the app runs on the device, so its pid is not one this machine
could be pointed at. Everything else - breakpoints, stepping, locals, expressions, exceptions -
behaves exactly as it does locally.
How failures are reported
Every tool reports a failure the same way:
error is whatever the debugger said, kept verbatim. explanation says what the failure means and
what to do about it, for the CORDBG_E_* results the debugger raises: a process that has exited, an
operation that needs the debuggee stopped, a variable that is not live at this instruction, a frame id
from an earlier stop, another debugger already attached. It is null for failures that are not the
debugger's, such as invalid arguments.
Configuration
Set these as environment variables in your client's configuration:
Troubleshooting
The server does not appear in the client. Check that the path in the configuration is absolute
and correct, then fully quit and restart the client. Claude Desktop logs to ~/Library/Logs/Claude/
on macOS and %APPDATA%\Claude\logs\ on Windows.
Attaching fails. The usual causes are that the process is owned by another user (see above), has
already exited, is not a .NET process, or already has a debugger attached. list_dotnet_processes
shows what the server can see and who owns it.
A breakpoint is not hit. Check that it came back verified: true. If not, the PDB is the first
thing to look at. If it is verified and still not hit, confirm the line is actually reached and that
the file path matches the one the PDB records.
list_dotnet_processes comes back empty on macOS or Linux. Module enumeration needs permissions
there, and the server falls back to detection by process name, which misses programs whose apphost is
renamed.
A launch or attach hangs on macOS with no error. See the entitlement section above.
A MAUI app starts and never stops at a breakpoint. It is almost certainly running on Mono rather
than CoreCLR - which happens when it was built by something other than build_mobile_app, since an
ordinary dotnet build produces neither the runtime nor the library the debugger needs. Rebuild with
build_mobile_app and launch the app it reports.
list_mobile_devices shows no Android devices. It reads emulators from the AVD directory and
connected phones from adb, so it needs the Android SDK: set ANDROID_HOME or ANDROID_SDK_ROOT if it
is somewhere unusual. The warnings in the response say which source could not be read and why.
To see what the server is doing, set DOTNET_DEBUGGER_MCP_LOG_LEVEL=Trace and
DOTNET_DEBUGGER_MCP_ENABLE_DIAGNOSTICS=true, or run it directly and watch stderr:
Development
The build takes the debug adapter from the clrdbg release ClrdbgVersion names, checks its hash and
puts it next to the server, so there is no separate step. To build the adapter from a clrdbg checkout
instead - a fork carrying a fix, say - point ClrdbgSourcePath at it:
The integration tests drive a real debuggee with real breakpoints, so they are slower than the rest
and are separated by TestCategory=Integration.
To point a client at your working copy instead of the published package:
CONTRIBUTING.md covers the layout and conventions. docs/RELEASING.md covers cutting a release, including the nuget.org trusted-publishing policy that the workflow depends on but does not show.
Related projects
- clrdbg — the .NET debugger this server drives
- SharpDbg — the debugger it ran on before the move
- ClrDebug — ICorDebug API wrapper
- Model Context Protocol — the specification and SDKs
License
来源:README.md,提交 9dfb79c
工具
0版本历史
5- v0.7.1最新Oct 22, 2026
- v0.6.3Oct 18, 2026
- v0.6.2Oct 18, 2026
- v0.6.0Oct 15, 2026
- v0.5.0Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分