Xdebug MCP Server
The Xdebug MCP Server enables AI assistants to debug PHP applications through Xdebug's DBGp protocol, providing comprehensive debugging and profiling capabilities.
Core Debugging
Session Management: List, monitor, switch between, and close multiple active debug sessions
Execution Control: Continue, step into/over/out, stop, or detach from execution
Breakpoint Management: Set line, conditional (with conditions and hit counts), exception, and function call breakpoints, including pending breakpoints that activate before sessions start
Variable Inspection: View all variables in scope, get specific variables with nested properties, set values, and switch between contexts (local, superglobals, constants)
Stack Analysis: View complete call stacks with frame navigation
Expression Evaluation: Evaluate arbitrary PHP expressions in the current debugging context
Source Code Access: Retrieve source code from files or specific line ranges
Advanced Features
Watch Expressions: Persistent watch expressions that auto-evaluate on each break with change detection
Logpoints: Output messages with
{$var}placeholders without stopping execution, with viewable historyMemory Profiling: Track memory usage and execution time between breakpoints with timeline visualization
Code Coverage: Start/stop tracking and generate coverage reports showing which lines were executed
Request Context: Automatically capture
$_GET,$_POST,$_SESSION,$_COOKIE, and headersStep Filters: Skip vendor/library code during stepping operations
Debug Profiles: Save and restore complete debugging configurations (breakpoints, watches, filters)
Session Export: Export sessions as JSON or HTML reports with snapshots
Function History: View history of function calls during debugging
Connection Options
TCP Mode: Network-based debugging (default port 9003)
Unix Socket Mode: High-performance local debugging
Docker Support: Works with containerized PHP using path mappings
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.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Xdebug MCP Server set a breakpoint at line 42 in index.php and continue execution"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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
Related MCP server: MCP Debugger
Installation
From npm (Recommended)
npm install -g xdebug-mcpFrom Source
git clone https://github.com/kpanuragh/xdebug-mcp.git
cd xdebug-mcp
npm install
npm run buildMCP Server Configuration
For Claude Code
Add the xdebug-mcp server to your MCP configuration (.mcp.json or Claude settings):
Using npm global install:
{
"mcpServers": {
"xdebug": {
"command": "xdebug-mcp",
"env": {
"XDEBUG_PORT": "9003",
"LOG_LEVEL": "info"
}
}
}
}Using npx:
{
"mcpServers": {
"xdebug": {
"command": "npx",
"args": ["-y", "xdebug-mcp"],
"env": {
"XDEBUG_PORT": "9003",
"LOG_LEVEL": "info"
}
}
}
}With Path Mappings (for Docker)
When debugging PHP in Docker containers, you need path mappings to translate container paths to host paths:
{
"mcpServers": {
"xdebug": {
"command": "xdebug-mcp",
"env": {
"XDEBUG_PORT": "9003",
"PATH_MAPPINGS": "{\"/var/www/html\": \"/home/user/projects/myapp\"}",
"LOG_LEVEL": "info"
}
}
}
}With DBGp Proxy Registration
If you already use a DBGp proxy, keep mcp-config.example.json as the default direct-listener example and start from mcp-config.proxy.example.json for proxy registration.
Proxy mode requires:
TCP listener mode for
xdebug-mcp(notXDEBUG_SOCKET_PATH)a unique callback port such as
9006,9007, or9008forXDEBUG_PORTDBGP_PROXY_HOST,DBGP_PROXY_PORT, andDBGP_IDEKEY
See the DBGp Proxy Registration Guide for the full setup, multi-agent examples, and PHP/Xdebug proxy configuration.
PHP/Xdebug Configuration
php.ini (or xdebug.ini)
[xdebug]
zend_extension=xdebug
; Enable step debugging
xdebug.mode=debug
; Start debugging on every request
xdebug.start_with_request=yes
; Host where MCP server is running
; For Docker: use host.docker.internal
; For local PHP: use 127.0.0.1
xdebug.client_host=host.docker.internal
; Port where MCP server listens
xdebug.client_port=9003
; IDE key (optional, for filtering)
xdebug.idekey=mcpDocker Compose
version: '3.8'
services:
php:
image: php:8.2-apache
volumes:
- ./src:/var/www/html
- ./xdebug.ini:/usr/local/etc/php/conf.d/99-xdebug.ini
extra_hosts:
- "host.docker.internal:host-gateway" # Required for Linux
environment:
- XDEBUG_MODE=debug
- XDEBUG_CONFIG=client_host=host.docker.internal client_port=9003Using Unix Domain Sockets
For improved performance and simplified setup on local systems, you can use Unix domain sockets instead of TCP. Unix sockets eliminate network stack overhead and are ideal for debugging on the same machine.
Benefits:
⚡ Lower latency (no TCP/IP stack overhead)
🔒 Better security (file permissions instead of port binding)
📦 Simpler setup (no port management)
🚀 Faster communication for local debugging
MCP Configuration (Unix Socket):
{
"mcpServers": {
"xdebug": {
"command": "xdebug-mcp",
"env": {
"XDEBUG_SOCKET_PATH": "/tmp/xdebug.sock",
"LOG_LEVEL": "info"
}
}
}
}PHP/Xdebug Configuration:
[xdebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=unix:///tmp/xdebug.sockSocket File Permissions:
The socket file is created with default permissions. To restrict access, you can:
# After MCP server starts
chmod 600 /tmp/xdebug.sock
# Or use a secure directory
mkdir -p ~/.xdebug && chmod 700 ~/.xdebug
# Then set XDEBUG_SOCKET_PATH=$HOME/.xdebug/xdebug.sockAutomatic Cleanup:
When XDEBUG_SOCKET_PATH is set, the server will:
Listen on the specified Unix socket instead of TCP port
Automatically clean up stale socket files on startup (prevents "address in use" errors)
Automatically clean up socket files on shutdown
Use the same debugging tools and features as TCP mode
When to Use Unix Sockets:
✅ Local PHP development (best performance)
✅ Same-machine debugging
✅ High-frequency breakpoint hits
❌ Remote debugging (use TCP instead)
Unix socket support requested in Issue #1 by @dkd-kaehm
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
Use set_breakpoint with file="/var/www/html/index.php" and line=25Conditional Breakpoint
Use set_breakpoint with file="/var/www/html/api.php", line=42, condition="$userId > 100"Watch Expression
Use add_watch with expression="$user->email"
Use add_watch with expression="count($items)"Logpoint
Use add_logpoint with file="/var/www/html/api.php", line=50, message="User {$userId} accessed {$endpoint}"Inspecting Variables
Use get_variables to see all local variables
Use get_variable with name="$user" to inspect a specific variable
Use evaluate with expression="count($items)" to evaluate an expressionCapture Request Context
Use capture_request_context to see $_GET, $_POST, $_SESSION, cookies, and headersEnvironment Variables
Variable | Default | Description |
|
| Port to listen for Xdebug connections (TCP mode) |
|
| Host to bind (TCP mode) |
| - | Unix domain socket path (e.g., |
|
| 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 |
Connection Modes: TCP vs Unix Socket
Feature | TCP | Unix Socket |
Setup | Easy (default) | Simple (one env var) |
Performance | Good | Excellent (lower latency) |
Security | Port accessible to network | File-based permissions |
Remote Debugging | ✅ Supported | ❌ Local only |
Docker | ✅ Works with host.docker.internal | ❌ Requires volume mount |
Stale Socket | Manual port cleanup | Auto-cleanup |
Default |
| Disabled (use TCP) |
Quick Decision Guide:
🏠 Local development? → Use Unix socket for best performance
🐳 Docker on same machine? → Use Unix socket with volume mount
🌐 Remote server? → Use TCP
🚀 Maximum speed? → Use Unix socket
📝 Don't know? → Start with TCP (default), switch to Unix socket if needed
How It Works
MCP Server starts and listens for Xdebug connections (TCP port 9003 or Unix socket)
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
┌─────────────┐ MCP/stdio ┌─────────────┐ DBGp/TCP or ┌─────────────┐
│ Claude │ ◄────────────────► │ xdebug-mcp │ ◄─ Unix Socket ──► │ Xdebug │
│ (AI Agent) │ │ Server │ │ (in PHP) │
└─────────────┘ └─────────────┘ └─────────────┘Connection Options:
TCP (Default):
xdebug.client_host=127.0.0.1+XDEBUG_PORT=9003Unix Socket:
xdebug.client_host=unix:///tmp/xdebug.sock+XDEBUG_SOCKET_PATH=/tmp/xdebug.sock
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 serverFor TCP: Check firewall allows connections on port 9003
For Unix socket: Verify socket path exists and has correct permissions:
ls -la /tmp/xdebug.sockCheck MCP server logs:
LOG_LEVEL=debugfor verbose output
Connection issues with Docker
For Linux, add
extra_hosts: ["host.docker.internal:host-gateway"]Verify container can reach host:
curl host.docker.internal:9003Check xdebug logs in container:
docker logs <container-id> | grep xdebug
Unix socket issues
"Address already in use": Socket file wasn't cleaned up
Remove manually:
rm -f /tmp/xdebug.sockMCP server will clean up automatically on next start
"Permission denied": Check socket file permissions
List socket:
ls -la /tmp/xdebug.sockRun as same user as PHP:
ps aux | grep php
Socket path in php.ini:
Correct:
xdebug.client_host=unix:///tmp/xdebug.sockWrong:
xdebug.client_host=unix:/tmp/xdebug.sock(missing one/)
Breakpoints not hitting
Ensure file paths match exactly (use container paths for Docker)
Check breakpoint is resolved:
list_breakpointsVerify script execution reaches that line
Check that
xdebug.start_with_request=yesis setTry a simple file to verify basic setup works
Performance issues
If experiencing slow stepping, increase
COMMAND_TIMEOUT:Default: 30000ms (30 seconds)
Try:
COMMAND_TIMEOUT=60000for slower systems
For Unix sockets, verify socket is on fast filesystem (not network mount)
Check system load:
top- excessive context switching slows debugging
Server won't start
Port in use (TCP):
Find process:
lsof -i :9003Kill it:
kill -9 <pid>
Bad config:
Validate environment variables:
echo $XDEBUG_SOCKET_PATHCheck for typos in path names
Permission denied:
For Unix socket, ensure write permission to parent directory
Example:
mkdir -p ~/.xdebug && chmod 700 ~/.xdebug
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Available Tools
46 toolsadd_logpointC
Add a logpoint that logs messages without stopping execution. Use {varName} placeholders for variables.
Inputs: file (required), line (required), message (required), condition.
add_step_filterB
Add a step filter to skip certain files/directories during stepping (e.g., vendor code)
Inputs: type (required), pattern (required), description.
add_watchA
Add a watch expression that will be evaluated on each break. Watch expressions persist across steps.
Inputs: expression (required).
capture_request_contextC
Capture the current HTTP request context ($_GET, $_POST, $_SESSION, $_COOKIE, headers)
Inputs: session_id.
capture_snapshotC
Capture a snapshot of the current debug state for the export report
Inputs: session_id.
close_sessionC
Close and terminate a debug session
Inputs: session_id.
continueB
Continue script execution until the next breakpoint or end of script
Inputs: session_id.
detachB
Detach from the debug session and let the script continue running without debugging
Inputs: session_id.
evaluateA
Evaluate a PHP expression in the current context. Returns the result of the expression. Use for calculations, method calls, or inspecting computed values.
Inputs: expression (required), session_id, stack_depth.
evaluate_watchesC
Evaluate all watch expressions and return their current values
Inputs: session_id.
export_sessionC
Export the current debug session as a report
Inputs: format, session_id.
get_contextsB
Get available variable contexts (Local, Superglobals, User-defined constants) at the current position
Inputs: session_id, stack_depth.
get_coverage_reportB
Get the current code coverage report
Inputs: no named parameters.
get_function_historyC
Get the history of function calls made during debugging
Inputs: limit, search.
get_logpoint_historyC
Get the log output history from logpoints
Inputs: limit, logpoint_id.
get_memory_timelineB
Get memory usage timeline from profiling
Inputs: no named parameters.
get_profile_statsC
Get current profiling statistics
Inputs: no named parameters.
get_session_stateC
Get detailed state of a specific debug session including current position and status
Inputs: session_id.
get_sourceC
Get the source code of a file or a specific line range
Inputs: file (required), end_line, begin_line, session_id.
get_stack_traceC
Get the current call stack showing all function calls leading to the current position
Inputs: session_id.
get_variableC
Get a specific variable by name, including nested properties. Use PHP syntax for nested access (e.g., '$user->name', '$array[0]', '$obj->items[2]->value')
Inputs: name (required), max_depth, context_id, session_id, +1 more.
get_variablesA
List all variables in scope with metadata (names, types, child counts). Use get_variable() to inspect specific variable values. Returns lightweight metadata for browsing the variable tree.
Inputs: context_id, session_id, stack_depth.
list_breakpointsB
List all breakpoints including both active session breakpoints and pending breakpoints
Inputs: session_id, include_pending.
list_debug_profilesB
List all saved debug profiles
Inputs: no named parameters.
list_sessionsA
List all active PHP debug sessions with their current state
Inputs: no named parameters.
list_step_filtersB
List all step filter rules
Inputs: no named parameters.
list_watchesB
List all active watch expressions
Inputs: no named parameters.
load_debug_profileC
Load a saved debug profile
Inputs: name (required).
remove_breakpointA
Remove a breakpoint by its ID. Works for both active session breakpoints and pending breakpoints.
Inputs: breakpoint_id (required), session_id.
remove_logpointC
Remove a logpoint
Inputs: logpoint_id (required).
remove_watchC
Remove a watch expression
Inputs: watch_id (required).
save_debug_profileA
Save the current debug configuration (breakpoints, watches, filters) as a named profile
Inputs: name (required), description.
set_active_sessionA
Set which debug session should be the active/default session for subsequent commands
Inputs: session_id (required).
set_breakpointA
Set a breakpoint in PHP code. Supports line breakpoints and conditional breakpoints with hit counts. Can be set before a debug session starts - breakpoints will be applied when a session connects.
Inputs: file (required), line (required), condition, hit_value, +2 more.
set_call_breakpointB
Set a breakpoint that triggers when a specific function is called. Can be set before a debug session starts.
Inputs: function_name (required), session_id.
set_exception_breakpointA
Set a breakpoint that triggers when a specific exception is thrown. Can be set before a debug session starts.
Inputs: exception, session_id.
set_variableC
Set the value of a variable in the current scope
Inputs: name (required), value (required), context_id, session_id, +1 more.
start_coverageB
Start tracking code coverage during debugging
Inputs: no named parameters.
start_profilingB
Start profiling to track memory usage and execution time
Inputs: no named parameters.
step_intoA
Step into the next function call, or to the next line if not a function call. This follows execution into called functions.
Inputs: session_id.
step_outA
Step out of the current function. Execution continues until the current function returns.
Inputs: session_id.
step_overA
Step over to the next line in the current scope. Function calls are executed but not stepped into.
Inputs: session_id.
stopA
Stop the debug session and terminate script execution immediately
Inputs: session_id.
stop_coverageB
Stop tracking code coverage and get the report
Inputs: no named parameters.
stop_profilingC
Stop profiling and get the results
Inputs: no named parameters.
update_breakpointB
Update a breakpoint (enable/disable or change hit conditions). Works for both active session and pending breakpoints.
Inputs: breakpoint_id (required), state, hit_value, session_id, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 46 tools
Most tools have clearly distinct purposes, but there is some overlap in the variable inspection/evaluation trio (get_variables, get_variable, evaluate) and session termination trio (stop, detach, close_session) where users may need to read carefully to pick the right one. Overall, however, the tool names and descriptions are specific enough to disambiguate.
The majority of tools follow a consistent verb_noun snake_case pattern (e.g., set_breakpoint, get_variable, add_watch). A few exceptions like continue, detach, evaluate, and stop break the pattern, and there is mild inconsistency between profile vs profiling terminology (start_profiling vs get_profile_stats). These are minor deviations rather than chaotic naming.
At 46 tools, the surface is very large and exceeds the point where users can easily hold the toolset in mind. While Xdebug is a feature-rich debugger with many legitimate operations, many of these tools (e.g., separate snapshot/export/profile tools) could be consolidated or exposed as optional sub-commands.
The tool set covers the main debugging workflow well: sessions, breakpoints, stepping, variables, watches, logpoints, source, profiling, and coverage. There are a few gaps such as no remove_step_filter or delete_debug_profile, but these are edge operations rather than core workflow blockers.
Maintenance
Related MCP Connectors
Live browser debugging for AI assistants — DOM, console, network via MCP.
Build, run, debug, test and ship Chrome, Firefox, Edge and Safari extensions from your AI agent.
Flutter in-app bug tracking, visual pin annotations, and device logs directly into your AI IDE.
Debug webhooks from your AI agent: inspect and replay captured webhooks on localhost.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to debug Node.js applications using Chrome DevTools Protocol. Provides comprehensive debugging capabilities including breakpoints, stepping, variable inspection, expression evaluation, and console monitoring.4,585 npm351MIT
- AlicenseAqualityAmaintenanceEnables AI agents to perform step-through debugging of Python, JavaScript/Node.js, and Rust programs using the Debug Adapter Protocol, with support for breakpoints, variable inspection, and stack traces.29194MIT
- AlicenseAqualityDmaintenanceEnables AI assistants to debug JavaScript and TypeScript applications by connecting to Chrome DevTools Protocol-compatible debuggers, allowing them to set breakpoints, step through code, inspect variables, and evaluate expressions with full source map support.182Apache 2.0
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to debug code inside VS Code by setting breakpoints, stepping through execution, inspecting variables, and evaluating expressions across multiple languages.583MIT