Skip to main content

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

Project description

MCP-PDB: Interactive Python Debugging with Claude

Python License

Inspired by microsoft's debug-gym and the way providing an LLM with PDB access improved it's performance on various benchmarks, I have found it helpful to give claude code/windsurf access to the python debugger.

MCP-PDB provides tools for interactive Python debugging with LLM through the Model Context Protocol (MCP).

Key Features

  • Interactive Debugging: Allows LLMs to step through code, inspect variables, and set breakpoints using MCP tools.
  • Conversational Interface: Debug with Claude or Windsurf's assistance without memorizing PDB commands
  • Context-Aware: Tracks your code structure and debugging session state
  • Smart Breakpoints: Easily manage breakpoints across files with tracking
  • Variable Inspection: Examine complex data structures with detailed insights

Getting Started

Installation in Claude Code

claude mcp add mcp-pdb uv run --with mcp-pdb mcp-pdb

Basic Usage

  1. Connect with LLMs and start debugging:
    You: Debug my Python script at ~/projects/myapp/main.py
    Claude: I'll start a debugging session for that file. What would you like to focus on?
    
    You: Set a breakpoint on line 42 and run until there
    Claude: [Sets breakpoint and runs] Execution paused at line 42. Here's the current context...
    
    You: What's the value of user_data?
    Claude: The variable user_data is a dictionary with 3 keys: 'name', 'age', and 'preferences'...
    

Example Commands

  • "Debug my Python file at path/to/file.py"
  • "Set a breakpoint at line 25"
  • "Step through the next 5 lines"
  • "What's the value of my_variable?"
  • "Show me all local variables"
  • "Continue execution until the next breakpoint"
  • "Explain what's happening in this function"
  • "Run pytest with debugging to fix test_<function_name>"

Advanced Features

Test Debugging

Debug tests easily with pytest integration:

You: Debug my test file tests/test_auth.py using pytest
Claude: Starting pytest with debugging for test_auth.py. What specific test are you interested in?

You: Run the test_login_failure test
Claude: [Runs test] Test paused at breakpoint in auth.py line 78. Here's what's happening...

Variable Analysis

Explore complex data structures with Claude's analysis:

You: Examine the user_session object
Claude: The user_session object is an instance of Session class with the following properties:
- id: "sess_12345"
- authenticated: True
- permissions: A list of 5 permission strings ["read", "write", ...]
- data: A deeply nested dictionary containing user preferences and state
  ...

Commands Reference

MCP-PDB supports all standard PDB commands through natural language, including:

  • Navigation: step, next, continue, until, return
  • Breakpoints: set, clear, list
  • Inspection: print, examine, where, locals, globals
  • Control: restart, quit

Use Cases

  • Debugging Complex Logic: Walk through intricate algorithms with step-by-step guidance
  • Learning New Codebases: Explore unfamiliar code with Claude's explanations
  • Teaching Programming: Perfect for mentoring as Claude explains what's happening
  • Finding Bugs: Easily track down elusive bugs with intelligent variable inspection

Development

For information about developing MCP-PDB, see CLAUDE.md.

License

MIT License - See LICENSE file for details.


Feedback and Contributions Welcome! Open an issue or PR to help improve MCP-PDB.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_pdb-0.4.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_pdb-0.4.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_pdb-0.4.0.tar.gz.

File metadata

  • Download URL: mcp_pdb-0.4.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_pdb-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9e0a91d53626811a917efc39c97e1a975a30f49b6f256e2b51adb4072eef5a67
MD5 73aad74066545d4d2dd7bf1425f338f9
BLAKE2b-256 f37bb8618a86eb72b9b67796d7a7e045b8600126ed27051acf5fe927572eceaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_pdb-0.4.0.tar.gz:

Publisher: python-publish.yml on samefarrar/mcp-pdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_pdb-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_pdb-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_pdb-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9664180e37f6db686b02473370767f13b9a66236fe705eb54a4f189e5721a761
MD5 b88c6953b2d26ce52566fc89da8870fc
BLAKE2b-256 523176689fd31391982f77fbb433e390dbd84ca70d00214e09fa6588abb4e625

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_pdb-0.4.0-py3-none-any.whl:

Publisher: python-publish.yml on samefarrar/mcp-pdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page