This repository demonstrates using mcp-debugpy to debug a Python application with an intentional bug using AI agents through the Model Context Protocol (MCP).
The shopping_cart.py application has a subtle bug in the calculate_total() method. When applying a discount:
- Expected behavior: A 10% discount on $100 should give $90
 - Actual behavior: The calculation multiplies incorrectly, giving $10 instead!
 
The bug is on line 45 of shopping_cart.py:
return subtotal * discount_amount  # BUG: Should subtract discount, not multiply!- Python 3.8 or higher
 - VS Code with the MCP extension (or Claude Desktop with MCP support)
 - Git
 
git clone https://github.com/YOUR_USERNAME/mcp-debugpy-demo.git
cd mcp-debugpy-demo
# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
# Install dependencies
pip install pytest
# Install mcp-debugpy from source (until published to PyPI)
pip install git+https://github.com/markomanninen/mcp-debugpy.gitpytest test_shopping_cart.py -vYou'll see test failures showing the discount calculation is wrong:
FAILED test_shopping_cart.py::test_calculate_total_with_discount
FAILED test_shopping_cart.py::test_complex_scenario
python shopping_cart.pyOutput will show:
Items in cart: 4
Subtotal: $1139.96
Total with 10% discount: $11.40
Expected total: $1025.96
WARNING: Total doesn't match expected value!
Notice how the total with discount ($11.40) is way off from the expected value ($1025.96)!
IMPORTANT: After installation, you need to configure your MCP client (VS Code or Claude Desktop) to use the mcp-debugpy server.
cd mcp-debugpy-demo
code .The repository includes .vscode/settings.json pre-configured. It uses the mcp-debug-server command that was installed by pip.
What it looks like:
{
  "mcp.servers.agentDebug": {
    "command": "${workspaceFolder}/.venv/bin/mcp-debug-server",
    "cwd": "${workspaceFolder}"
  }
}- Press 
Cmd+Shift+P(Mac) orCtrl+Shift+P(Windows/Linux) - Type "Developer: Reload Window"
 - Press Enter
 
- Open the AI chat panel
 - You should see "agentDebug" server available
 - Try asking: "What MCP tools are available?"
 
Ask the AI: "Debug the shopping_cart.py bug using breakpoints"
The AI agent can use these MCP tools:
dap_launch- Start debugging with breakpointsdap_locals- Inspect variable valuesdap_step_over/dap_step_in- Step through codedap_continue- Continue executionrun_tests_json- Run tests and analyze failures
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
Edit the config file and add (replace /absolute/path/to/ with your actual path):
{
  "mcpServers": {
    "agentDebug": {
      "command": "/absolute/path/to/mcp-debugpy-demo/.venv/bin/mcp-debug-server",
      "cwd": "/absolute/path/to/mcp-debugpy-demo"
    }
  }
}To get your absolute path:
cd mcp-debugpy-demo
pwd
# Copy this path and use it aboveCompletely quit and relaunch Claude Desktop.
In a new conversation, ask: "What MCP tools do you have available?"
You should see tools like dap_launch, dap_locals, run_tests_json, etc.
Ask: "Help me debug the shopping cart discount bug"
Claude Code automatically detects the .vscode/settings.json configuration. Just:
- Open the folder in VS Code
 - Make sure Claude Code extension is installed
 - Open Claude Code chat
 - Ask: "Debug shopping_cart.py using breakpoints"
 
The virtual environment isn't activated or mcp-debugpy isn't installed:
source .venv/bin/activate
pip install git+https://github.com/markomanninen/mcp-debugpy.git
which mcp-debug-server  # Should show path in .venv/bin/- Check the path in settings is correct (absolute paths work best)
 - Make sure the virtual environment exists
 - Try running the server manually to see errors:
.venv/bin/mcp-debug-server --help
 
- Reload VS Code window (Cmd/Ctrl+Shift+P → "Developer: Reload Window")
 - Check VS Code Output panel for MCP server errors
 - Verify the MCP extension is installed and enabled
 
If you prefer not to use the pre-configured .vscode/settings.json, you can configure manually:
- Open VS Code Settings (JSON)
 - Add the MCP server configuration manually
 - Use absolute paths for reliability
 
Once you've identified the bug on line 45, the fix is simple:
# WRONG (current):
return subtotal * discount_amount
# CORRECT:
return subtotal - discount_amount
# OR equivalently:
return subtotal * (1 - self.discount_rate)After fixing, run the tests again:
pytest test_shopping_cart.py -vAll tests should now pass!
mcp-debugpy-demo/
├── README.md                    # This file
├── .gitignore                   # Git ignore patterns
├── requirements.txt             # Python dependencies
├── shopping_cart.py             # Main application (with bug)
├── test_shopping_cart.py        # Test suite (exposes the bug)
└── .vscode/
    └── settings.json            # VS Code MCP configuration
This demo shows how AI agents can help with debugging by:
- Running tests automatically to identify failures
 - Setting breakpoints programmatically at relevant code locations
 - Inspecting variables to understand program state
 - Stepping through code to trace execution flow
 - Explaining the bug in natural language
 
Traditional debugging requires manual setup, but with MCP tools, an AI agent can orchestrate the entire debugging session!
Found a bug (a real one, not the intentional demo bug!)? Have suggestions? Open an issue or pull request!
MIT License - See LICENSE file for details.
- Built with mcp-debugpy by markomanninen
 - Uses Microsoft's debugpy debug adapter
 - Implements Model Context Protocol (MCP) by Anthropic