Integrates with GitHub Copilot in VS Code to provide breakpoint-based Python debugging capabilities, allowing AI assistants to set breakpoints, inspect local variables, and perform step execution through natural language commands.
Provides advanced Python debugging capabilities using debugpy and the Debug Adapter Protocol (DAP), enabling breakpoint management, step execution (step-in, step-over, step-out), variable inspection, and isolated process debugging for Python scripts.
Debug-MCP: Python Debugging via Model Context Protocol
A Python debugging tool that exposes breakpoint-based debugging capabilities through a clean API and CLI, designed for integration with AI assistants and development tools.
English | 日本語
Features
Advanced Debugging via DAP: Production-ready debugging using Microsoft's debugpy
Breakpoint Debugging: Set breakpoints and inspect local variables at runtime
Step Execution: True step-in, step-over, step-out operations
No Corruption: Isolated process execution prevents sys.modules issues
Environment-aware: Automatically uses target project's Python interpreter
Session Management: Isolated debug sessions with timeout protection
Dual Interface:
CLI: Interactive debugging with beautiful table output
MCP Server: Official MCP SDK-based integration for AI assistants
Safe Execution: Sandboxed subprocess execution with configurable limits
Type Safety: Pydantic v2 schemas for request/response validation
Async Support: Built on MCP SDK with full async/await support
Comprehensive Testing: 254 tests (119 unit + 122 integration + 13 exploration) covering DAP workflows, session management, and edge cases
Legacy Compatibility: Optional bdb mode for backward compatibility
Quick Start
Installation
VS Code Copilot Integration
To use this tool with GitHub Copilot in VS Code, set up the MCP server configuration.
See
Quick Setup (Using from Debug-MCP repository):
Create MCP config directory (macOS/Linux):
mkdir -p ~/Library/Application\ Support/Code/User/globalStorage/github.copilot-chatEdit
mcp.jsonfile:{ "mcpServers": { "python-debug": { "command": "uv", "args": ["run", "mcp-debug-server", "--workspace", "${workspaceFolder}"], "env": {"PYTHONUNBUFFERED": "1"} } } }Restart VS Code
Using from Another Repository:
When using this tool from a different repository, specify the Debug-MCP installation path:
Replace /absolute/path/to/Debug-MCP with the actual path to your Debug-MCP installation.
Using Copilot Chat:
See mcp-config-example.json for a complete configuration example.
CLI Usage (Recommended for Interactive Debugging)
See Quickstart Guide for more CLI examples.
API Usage (Python Integration)
Safety & Constraints
Execution Limits
Timeout: 20 seconds per breakpoint operation (configurable)
Output Capture: 10MB maximum per session
Variable Depth: Max 2 levels of nesting in local variable inspection
Collection Size: Max 50 items shown in lists/dicts
String Length: Max 256 characters before truncation
Security
Path Validation: Only project-relative paths allowed (no
..traversal)Subprocess Isolation: Debuggee runs in isolated subprocess
Working Directory: Locked to workspace root
No Network: Debuggee has no special network access (app code may still use network)
⚠️ Important: The debugger executes user code with minimal restrictions. Only debug trusted code.
Architecture
Current Implementation (v2 - DAP-based)
Debug-MCP now uses DAP (Debug Adapter Protocol) via debugpy for production debugging:
Why DAP (debugpy)?
✅ No sys.modules corruption - Runs in separate process
✅ True step execution - Maintains execution state across steps
✅ Automatic environment handling - Uses target Python interpreter
✅ Industry standard - Microsoft's battle-tested implementation
✅ Rich features - Step in/over/out, conditional breakpoints, watch expressions
✅ Future-proof - Easy to extend with advanced debugging features
Communication Flow:
MCP Client (VS Code Copilot) → MCP Server (tool call)
Server → SessionManager (sync method via async wrapper)
SessionManager → DAPSyncWrapper (manages DAP session)
DAPSyncWrapper ↔ debugpy Server (DAP protocol over socket)
debugpy captures locals → DAPSyncWrapper → SessionManager → Server → Client
Legacy bdb Mode
The bdb-based implementation is still available for compatibility (useDap=false):
However, DAP is now the default and recommended for all use cases. The bdb mode has known issues:
sys.modules corruption with multiple runs
No true step execution (replay-based)
Complex PYTHONPATH management
File Organization (2025-11-03)
Active Files (Production):
✅
server.py- MCP SDK server✅
sessions.py- Session lifecycle management✅
dap_wrapper.py- DAP synchronous wrapper (PRIMARY)✅
dap_client.py- Low-level DAP protocol client (PRIMARY)✅
schemas.py- Pydantic models✅
utils.py- Variable repr helpers and path utilities
Legacy Files (Compatibility):
⚠️
debugger.py- bdb-based engine (legacy, useuseDap=false)⚠️
runner_main.py- bdb subprocess runner (legacy)
Removed Files:
- Old multiprocessing approach (removed 2025-10-30)runner.py
Development
Setup
See docs/development.md for detailed setup instructions.
Quick commands:
Project Structure
Documentation
VS Code Setup Guide - How to use MCP tool with VS Code Copilot ⭐
Quickstart Guide - CLI and API usage examples
Specification - Complete feature specification
Data Model - Entity schemas and validation rules
Research - Design decisions and rationale
Development Guide - Setup and contribution guide
Performance Tuning - Timeout and resource configuration
Roadmap - Planned v2 features
Current Status
v2.0 Released! DAP Integration Complete 🎉
✅ Phase 1: Foundation (Complete - 6/6 tests passing)
✅ Phase 2: Core Logic (Complete - 28/28 tests passing)
✅ Phase 3: Session Lifecycle (Complete - 29/29 tests passing)
✅ Phase 4: Breakpoint Operations (Complete - 41/41 tests passing)
✅ Phase 5: Error Visibility (Complete - 71/71 tests passing)
✅ Phase 6: MCP SDK Migration (Complete - SDK-based server with async support)
✅ Phase 7: DAP Integration (Complete - Production-ready debugpy integration)
What's New in v2.0:
DAP (debugpy) is now the default - No more sys.modules corruption!
True step execution - Step in, step over, step out all working
Automatic environment handling - Uses target project's Python interpreter
Industry-standard protocol - Microsoft's battle-tested implementation
Enhanced reliability - Isolated process execution prevents crashes
Backward compatible - Legacy bdb mode still available with
useDap=false
Migration from v1.x:
Existing code works as-is (DAP is opt-in by default)
To explicitly use bdb:
StartSessionRequest(entry="...", useDap=False)Recommended: Let it default to DAP for best results
Limitations (v2)
Script entry only: No module (
python -m) or pytest target support (planned for v2.1)Single-threaded: No support for multi-threaded debugging (planned for v2.1)
Line breakpoints: Conditional breakpoints not yet exposed via MCP (DAP supports it)
✅ Resolved from v1:
No stepping→ Now available: Step in, step over, step outsys.modules corruption→ Fixed: DAP uses isolated processesPython environment mismatch→ Fixed: Uses target interpreter
See docs/roadmap.md for planned v2.1+ enhancements.
Contributing
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Make your changes with tests
Run tests and linting (
uv run pytest && uv run ruff check .)Commit changes (
git commit -m 'Add amazing feature')Push to branch (
git push origin feature/amazing-feature)Open a Pull Request
License
MIT License - see LICENSE file for details
Acknowledgments
Built with:
debugpy - Microsoft's Python debugger (DAP implementation)
MCP SDK - Model Context Protocol Python SDK
bdb/pdb - Python's standard debugger framework (legacy mode)
Pydantic - Data validation using Python type annotations
Typer - CLI framework built on Click
Rich - Beautiful terminal formatting
pytest - Testing framework