Supports debugging PHP applications running in Docker containers with path mapping capabilities to translate container paths to host paths for seamless debugging experience.
Provides comprehensive PHP debugging capabilities through Xdebug's DBGp protocol, including breakpoint management, step debugging, variable inspection, expression evaluation, watch expressions, logpoints, memory profiling, and code coverage tracking.
Xdebug MCP Server
An MCP (Model Context Protocol) server that provides PHP debugging capabilities through Xdebug's DBGp protocol. This allows AI assistants like Claude to directly debug PHP applications.
Features
Core Debugging
Full Debug Control: Step into, step over, step out, continue, stop
Breakpoints: Line breakpoints, conditional breakpoints, exception breakpoints, function call breakpoints
Variable Inspection: View all variables, get specific variables, set variable values
Expression Evaluation: Evaluate PHP expressions in the current context
Stack Traces: View the full call stack
Multiple Sessions: Debug multiple PHP scripts simultaneously
Docker Support: Works with PHP running in Docker containers
Advanced Features
Watch Expressions: Persistent watches that auto-evaluate on each break with change detection
Logpoints: Log messages without stopping execution using
{$var}placeholdersMemory Profiling: Track memory usage and execution time between breakpoints
Code Coverage: Track which lines were executed during debugging
Request Context: Capture
$_GET,$_POST,$_SESSION,$_COOKIE, headers automaticallyStep Filters: Skip vendor/library code during stepping
Debug Profiles: Save and restore breakpoint configurations
Session Export: Export debug sessions as JSON or HTML reports
Installation
From npm (Recommended)
From Source
MCP Server Configuration
For Claude Code
Add the xdebug-mcp server to your MCP configuration (.mcp.json or Claude settings):
Using npm global install:
Using npx:
With Path Mappings (for Docker)
When debugging PHP in Docker containers, you need path mappings to translate container paths to host paths:
PHP/Xdebug Configuration
php.ini (or xdebug.ini)
Docker Compose
Available MCP Tools (41 Total)
Session Management
Tool | Description |
| List all active debug sessions |
| Get detailed state of a session |
| Set which session is active |
| Close a debug session |
Breakpoints
Tool | Description |
| Set a line or conditional breakpoint (supports pending breakpoints) |
| Break on exceptions (supports pending breakpoints) |
| Break on function calls (supports pending breakpoints) |
| Remove a breakpoint (works with pending breakpoints) |
| Enable/disable or modify a breakpoint |
| List all breakpoints including pending |
Pending Breakpoints: You can set breakpoints before a debug session starts. These are stored as "pending breakpoints" and automatically applied when a PHP script connects with Xdebug. This is useful for setting up breakpoints before triggering a page load or script execution.
Execution Control
Tool | Description |
| Continue to next breakpoint |
| Step into function calls |
| Step over (skip function internals) |
| Step out of current function |
| Stop debugging |
| Detach and let script continue |
Inspection
Tool | Description |
| Get the call stack |
| Get available variable contexts |
| Get all variables in scope |
| Get a specific variable |
| Set a variable's value |
| Evaluate a PHP expression |
| Get source code |
Watch Expressions
Tool | Description |
| Add a persistent watch expression |
| Remove a watch expression |
| Evaluate all watches and detect changes |
| List all active watches |
Logpoints
Tool | Description |
| Add a logpoint with message template |
| Remove a logpoint |
| View log output and hit statistics |
Profiling
Tool | Description |
| Start memory/time profiling |
| Stop profiling and get results |
| Get current profiling statistics |
| View memory usage over time |
Code Coverage
Tool | Description |
| Start tracking code coverage |
| Stop and get coverage report |
| View coverage statistics |
Debug Profiles
Tool | Description |
| Save current configuration as a profile |
| Load a saved debug profile |
| List all saved profiles |
Additional Tools
Tool | Description |
| Capture HTTP request context |
| Add filter to skip files during stepping |
| List step filter rules |
| View function call history |
| Export session as JSON/HTML report |
| Capture debug state snapshot |
Usage Examples
Setting a Breakpoint
Conditional Breakpoint
Watch Expression
Logpoint
Inspecting Variables
Capture Request Context
Environment Variables
Variable | Default | Description |
|
| Port to listen for Xdebug connections |
|
| Host to bind |
|
| Command timeout in milliseconds |
| - | JSON object mapping container to host paths |
|
| Max depth for variable inspection |
|
| Max children to return for arrays/objects |
|
| Max data size per variable |
|
| Log level: debug, info, warn, error |
How It Works
MCP Server starts and listens for Xdebug connections on port 9003
PHP script runs with Xdebug enabled
Xdebug connects to the MCP server via DBGp protocol
AI uses MCP tools to control debugging (set breakpoints, step, inspect)
DBGp commands are sent to Xdebug, responses parsed and returned
Troubleshooting
No debug sessions appearing
Check that Xdebug is installed:
php -vshould show XdebugVerify Xdebug config:
php -i | grep xdebugEnsure
xdebug.client_hostpoints to the MCP serverCheck firewall allows connections on port 9003
Connection issues with Docker
For Linux, add
extra_hosts: ["host.docker.internal:host-gateway"]Verify container can reach host:
curl host.docker.internal:9003
Breakpoints not hitting
Ensure file paths match exactly (use container paths for Docker)
Check breakpoint is resolved:
list_breakpointsVerify script execution reaches that line
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT