mcp-pdb

v0.8.0
mcp-pdb Checked 4 days ago Published 1 month ago

MCP to use the python debugger, inspired by debug-gym

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

start_debug

Start a local debugging session on a Python file within its project. The runner is picked automatically: ``uv run`` for projects with a pyproject.toml (when uv is installed), else the project's virtualenv, else the system Python. Breakpoints tracked for this project from earlier sessions are restored. Args: file_path: Path to the Python file or test module to debug. use_pytest: If True, run under ``pytest --pdb`` (stops at the first failure). args: Extra arguments for the script or pytest, shell-quoted (e.g. ``-k "test_a or test_b" -…

ParameterTypeDescription
file_path *string
argsstring
caveman_modeboolean
use_pytestboolean

connect_remote_debug

Connect to a remote PDB session listening on a TCP socket. Success means "TCP connection established": the tool does not wait for a ``(Pdb)`` prompt, because with ``rpdb script.py`` the script only starts once the client connects. Commands sent before the remote side reaches a prompt queue on the socket. Works with ``rpdb script.py`` (dual terminal + agent session) and ``remote_pdb.RemotePdb().set_trace()``. Args: host: Hostname or IP of the remote pdb (default "localhost"). port: TCP port the remote pdb listens on (default 4444). timeout…

ParameterTypeDescription
caveman_modeboolean
hoststring
portinteger
timeoutinteger

send_pdb_command

Send a command to the running PDB instance. Returns as soon as pdb shows its next prompt. If the program is still running when the timeout expires, the partial output is returned with a note; call get_output to keep waiting, or interrupt to pause it. Examples: n (next), s (step into), c (continue), r (return), unt 42 (run to line 42) p expr, pp expr, w (stack), u / d (move up/down the stack) b 42, b file.py:42, b func, b 42, x > 3 (conditional), cl 3 l / ll (list source), a (function args), q (quit) Breakpoints set or cleared here are tra…

ParameterTypeDescription
command *string
timeout

get_output

Wait for more output from the debuggee without sending a command. Use after a command returned "still running", or for a remote session that has not reached a breakpoint yet. Returns when pdb prints its prompt, the program exits, or ``timeout`` seconds pass.

ParameterTypeDescription
timeoutnumber

interrupt

Pause a running program (like pressing Ctrl+C) and return to the prompt. Local sessions only. Under ``python -m pdb`` this stops at the line currently executing; under pytest it raises KeyboardInterrupt in the test.

set_breakpoint

Set a breakpoint at a line, optionally conditional. Tracked across restarts. Args: file_path: Path to the file (relative to the project root, or absolute). line_number: Line number for the breakpoint. condition: Optional Python expression; pdb stops only when it is true (e.g. ``i == 99`` or ``user is None``).

ParameterTypeDescription
file_path *string
line_number *integer
conditionstring

clear_breakpoint

Clear the breakpoint(s) at a specific line in a file. Args: file_path: Path to the file where the breakpoint exists. line_number: Line number of the breakpoint to clear.

ParameterTypeDescription
file_path *string
line_number *integer

list_breakpoints

List breakpoints known to PDB alongside those tracked for restarts.

restart_debug

Restart the session with the same file/args/pytest flag (or reconnect remote). Tracked breakpoints - in any file of the project - are restored, and caveman_mode is preserved.

examine_variable

Examine a variable or expression: type, length, value and (optionally) attributes. One round-trip; the expression is evaluated once in the current frame. Args: variable_name: Variable or expression (e.g. ``my_var``, ``self.data[0]``). include_attrs: Also list dir() attributes. Always on when caveman_mode is False. max_chars: Truncate the repr / pretty-print beyond this many characters.

ParameterTypeDescription
variable_name *string
include_attrsboolean
max_charsinteger

get_debug_status

Get the current status of the debugging session and tracked state.

end_debug

End the current debugging session (local process or remote connection).