README.md | Raw
dbgeng-mcp
An MCP server for dynamic analysis on Windows. It drives dbgeng, the engine behind WinDbg and cdb, so an MCP client can launch a program, attach to a process, or open a crash dump, then step, read memory and registers, set breakpoints, and run any WinDbg command.
How it is built
Three layers:
MCP client <--stdio--> server.py <--JSON over a pipe--> worker.py --ctypes--> dbgeng.dll
(MCP) (WSL or Win) (Windows Python)
server.pyholds no debugger state. It exposes the MCP tools and forwards each call to the worker.worker.pyowns one dbgeng engine and runs one target at a time. It lives in its own process because dbgeng is stateful and blocking, and because a target under analysis is code that runs. A separate process is one the server can kill and respawn._engine.pybinds dbgeng directly through ctypes. No pykd, no compiled extension.
Why a direct ctypes binding and not pykd
pykd is the usual way to script dbgeng from Python, but its newest published build targets Python 3.7. On a current Python it is not an option. A direct binding has no such constraint: it runs on whatever Python is installed and needs nothing beyond the Debugging Tools.
The cost is that the COM vtable layout is written out by hand. To keep that honest, _abi.py is generated from the Windows SDK's DbgEng.h by tools/gen_abi.py, so the method order and interface IDs match the dll that ships with that SDK. Regenerate it against your own header if the SDK moves:
python3 tools/gen_abi.py "/mnt/c/Program Files (x86)/Windows Kits/10/Include/<ver>/um/DbgEng.h"
Requirements
- Windows 10 or 11, 64 bit.
- The Debugging Tools for Windows, which provide
dbgeng.dll. Install the WinDbg package (winget install Microsoft.WinDbg) or the Windows SDK's Debugging Tools component. The engine is found underC:\Program Files (x86)\Windows Kits\10\Debuggers\x64, or setDBGENG_DIR. - Python 3.10 or newer on the Windows side for the worker. Pure standard library, no packages.
- The
mcppackage (2.3 or newer) for the server. The server runs under WSL Python or Windows Python.
The Debugging Tools binaries are not redistributed here. Install them separately.
Install
python3 -m venv .venv && . .venv/bin/activate
pip install -e .
Run
As a standalone MCP stdio server:
python -m dbgeng_mcp.server
From WSL the server spawns the worker with python.exe (Windows Python) and translates the worker path to its \\wsl.localhost form on its own. Override the interpreter or the worker path if needed:
DBGENG_MCP_PYTHONthe Windows Python to run the worker (defaultpython.exe).DBGENG_MCP_WORKERthe worker script path (default the installedworker.py).
Wire it into an MCP client
Point the client at the server command. Most clients take a command and its arguments, for example:
{
"command": "/home/you/dev/dbgeng-mcp/.venv/bin/python",
"args": ["-m", "dbgeng_mcp.server"]
}
Tools
| Tool | What it does |
|---|---|
open_target |
Launch a command line, attach to a pid, or open a dump. Stops at the first instruction |
execute |
Run any WinDbg command and return its text (lm, k, bp, dx, !peb, ...) |
go |
Continue until the next breakpoint, exception, or exit |
step |
Single step one instruction, into or over |
read_memory |
Read bytes at an address, returned as hex |
registers |
The target's register values |
close |
End the session |
execute is the escape hatch. Anything the structured tools do not cover, a raw command does.
Checking the binding
tools/smoke.py launches a throwaway target and exercises the engine directly. tools/test_worker.py drives the worker over the same JSON protocol the server uses. Both run against the live engine:
python.exe tools/smoke.py # engine, Windows Python
python3 tools/test_worker.py # worker over its pipe
Limits
- One target at a time. Opening a new one replaces the current.
registersreturns the engine's register text. Structured per register values are not exposed yet.- Symbols follow
_NT_SYMBOL_PATH. Set it to a local cache plus the Microsoft symbol server for names. - Running an untrusted target runs its code. For real samples, run the worker in a disposable VM.