Skip to main content

MCP-PDB: Python Debugger Interface for Claude/LLMs

Python License

MCP-PDB provides tools for using Python's debugger (pdb) with Claude and other LLMs through the Model Context Protocol (MCP). This was inspired by debug-gym by Microsoft, which showed gains in various coding benchmarks by providing a coding agent access to a python debugger.

⚠️ Security Warning

This tool executes Python code through the debugger. Use in trusted environments only.

Installation

Works best with uv

Claude Code

# Install the MCP server
claude mcp add mcp-pdb -- uv run --with mcp-pdb mcp-pdb

# Alternative: Install with specific Python version
claude mcp add mcp-pdb -- uv run --python 3.13 --with mcp-pdb mcp-pdb

# Note: The -- separator is required for Claude Code CLI

Windsurf

{
  "mcpServers": {
    "mcp-pdb": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp-pdb",
        "mcp-pdb"
      ]
    }
  }
}

Available Tools

Tool Description
start_debug(file_path, use_pytest, args, caveman_mode) Start a local debugging session for a Python file
connect_remote_debug(host, port, timeout, caveman_mode) Connect to a remote PDB session over TCP
send_pdb_command(command, timeout) Send a command to the running PDB instance (local or remote)
get_output(timeout) Wait for more output without sending a command (e.g. after a long c)
interrupt() Pause a running local program, like Ctrl+C
set_breakpoint(file_path, line_number, condition) Set a (optionally conditional) breakpoint
clear_breakpoint(file_path, line_number) Clear the breakpoint(s) at a line
list_breakpoints() List breakpoints in PDB and those tracked for restarts
restart_debug() Restart/reconnect, restoring breakpoints and caveman_mode
examine_variable(variable_name, include_attrs, max_chars) Type, length, value and attributes of an expression in one round-trip
get_debug_status() Show the current state of the debugging session
end_debug() End the session (kills the debuggee's whole process group; closes the socket for remote)

How waiting works

Every command returns as soon as pdb prints its (Pdb) prompt, so ordinary commands come back in milliseconds. The timeout is only a ceiling (30 s for commands that run code such as c/r/unt, 10 s otherwise). If the program is still running when it expires, you get the partial output plus a note; call get_output to keep waiting or interrupt to pause it. Output that arrives between calls is never dropped — it is returned with the next response.

Breakpoints set with set_breakpoint or raw b ... commands are tracked per project and restored (with their conditions) on restart_debug or the next start_debug in the same project. Tool results are capped at ~20k characters.

Set MCP_PDB_LOG_LEVEL=DEBUG for verbose server logs (written to stderr).

Remote Debugging

Connect to a Python process that exposes PDB over a TCP socket. All existing tools (send_pdb_command, set_breakpoint, examine_variable, etc.) work identically once connected.

rpdb is installed alongside mcp-pdb and is the easiest way to debug with both a local terminal and the MCP agent simultaneously.

Terminal ──→ stdin ──→ PDB ──→ stdout ──→ Terminal
                            └──→ socket ──→ mcp-pdb
mcp-pdb  ──→ socket ──┘  (local stdin takes priority)

Start a script under rpdb:

REMOTE_PDB_PORT=4444 rpdb script.py [args]
REMOTE_PDB_PORT=4444 rpdb -m mymodule [args]

rpdb prints waiting for mcp connection on 127.0.0.1:4444 ... and blocks until the MCP agent connects. All normal pdb flags (-c, --help, etc.) are supported.

Then connect from Claude / the MCP agent:

connect_remote_debug(host="127.0.0.1", port=4444)

All PDB output is now mirrored to both the terminal and the agent. Commands typed in the terminal take priority; the agent's commands are echoed to the terminal so you can follow along.

Environment variables:

Variable Default Description
REMOTE_PDB_HOST 127.0.0.1 Interface to listen on (0.0.0.0 for remote machines)
REMOTE_PDB_PORT 4444 TCP port

In-source one-liner (correct frame, all locals visible):

# Add at the line you want to break at:
from mcp_pdb.rpdb import set_trace; set_trace()

The process blocks here until the MCP agent (or any TCP client) connects.

Zero-code-change with breakpoint():

PYTHONBREAKPOINT=mcp_pdb.rpdb.set_trace python script.py

Python ≥ 3.11 with --pdbcls (remote only, no local terminal):

python -m pdb --pdbcls=mcp_pdb.rpdb:Debugger script.py
pytest --pdb --pdbcls=mcp_pdb.rpdb:Debugger

Manual remote-pdb setup

If you need to attach to an already-running process without using rpdb:

Option A – remote-pdb package

from remote_pdb import RemotePdb
RemotePdb("0.0.0.0", 4444).set_trace()

Option B – stdlib only

import io, socket, pdb

srv = socket.socket()
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("0.0.0.0", 4444))
srv.listen(1)
conn, _ = srv.accept()   # blocks until MCP connects
f = conn.makefile("rwb", buffering=0)
pdb.Pdb(stdin=io.TextIOWrapper(f), stdout=io.TextIOWrapper(f)).set_trace()

Connect from Claude / the LLM:

connect_remote_debug(host="192.168.1.10", port=4444)

timeout (default 30 s) controls how long to retry on ConnectionRefused— useful when the remote process has not yet reached set_trace().

restart_debug() reconnects to the same host/port. end_debug() closes the socket gracefully (sends q first).

Common PDB Commands

Command Description
n Next line (step over)
s Step into function
c Continue execution
r Return from current function
p variable Print variable value
pp variable Pretty print variable
b file:line Set breakpoint
cl num Clear breakpoint
l List source code
q Quit debugging

Features

  • Project-aware debugging with automatic virtual environment detection
  • Support for both direct Python debugging and pytest-based debugging
  • Automatic breakpoint tracking (including conditions and breakpoints in other files) and restoration between sessions
  • Works with UV package manager
  • Variable inspection with type information and attribute listing, without polluting the debugged frame
  • Prompt-driven I/O: no fixed sleeps, nothing lost on long-running commands

Troubleshooting

Claude Code Installation Issues

If you encounter an error like:

MCP server "mcp-pdb" Connection failed: spawn /Users/xxx/.local/bin/uv run --python 3.13 --with mcp-pdb mcp-pdb ENOENT

Make sure to include the -- separator when using claude mcp add:

# ✅ Correct
claude mcp add mcp-pdb -- uv run --with mcp-pdb mcp-pdb

# ❌ Incorrect (missing --)
claude mcp add mcp-pdb uv run --with mcp-pdb mcp-pdb

To verify your installation:

# Check if mcp-pdb is listed
claude mcp list | grep mcp-pdb

# Check server status in Claude Code
# Type /mcp in Claude Code to see connection status

License

MIT License - See LICENSE file for details.

Metadata

Release files for mcp-pdb 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-pdb 0.8.0
File Size Uploaded Provenance Actions
mcp_pdb-0.8.0.tar.gz 33.3 kB With provenance Details for mcp_pdb-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-pdb 0.8.0
File Interpreter ABI Platform Actions
mcp_pdb-0.8.0-py3-none-any.whl Python 3 none any Details for mcp_pdb-0.8.0-py3-none-any.whl

Total release size: 57.3 kB

Release files / mcp_pdb-0.8.0.tar.gz

Download URL mcp_pdb-0.8.0.tar.gz
Size 33.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2cc9f926607f82df237f1ca815cbe9a8800c06b0b1c8a57fc213643b2e3aa511
BLAKE2b-256 checksum
How to use checksums
dcce90b0465ccbc15669fb831fad604f98b8eeb47e4387071c4a3dd303ecea94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / mcp_pdb-0.8.0-py3-none-any.whl

Download URL mcp_pdb-0.8.0-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ec2f2f15b624c3002e62ee063e8c2839c6a5da6978947a3f6bba34da8bb5368
BLAKE2b-256 checksum
How to use checksums
1ce0a1c070e2b85ab01aa26c44cdf63cbb5a73f99303b6e375b24f28dbd33609
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Security for mcp-pdb 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mcp_pdb-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page