
Xdebug
io.github.kpanuragh由 GitHub 账号 kpanuragh 发布v1.2.1更新于 Oct 24, 2026
MCP server for PHP Xdebug debugging with breakpoints, stepping, and variable inspection
概览
让 AI 助手通过 Xdebug 的 DBGp 协议调试 PHP 应用,可设置断点、单步执行并检查变量。
- 可以做什么
- 在本地运行一个 MCP 服务器,监听来自 PHP 的 Xdebug 连接,并提供约 41 个调试工具。支持行断点、条件断点、异常断点和函数调用断点,执行控制(步入、步过、步出、继续、停止、分离),变量与调用栈检查,表达式求值,监视表达式,日志点,内存分析,代码覆盖率,请求上下文捕获,步进过滤,调试配置文件和会话导出。
- 适用场景
- 当你希望 AI 助手协助交互式调试 PHP 代码时使用:设置断点、单步执行、检查变量或对运行中的脚本做性能分析。主要面向本地 PHP 开发,也支持运行在 Docker 容器中的 PHP。
- 运行要求
- 需要本地 Node.js 运行时来运行 npm 包 xdebug-mcp(或使用 npx)。PHP 需安装 Xdebug 扩展并配置为步进调试,指向服务器的主机和端口。可选环境变量包括 XDEBUG_PORT、XDEBUG_HOST、XDEBUG_SOCKET_PATH、PATH_MAPPINGS、COMMAND_TIMEOUT、MAX_DEPTH、MAX_CHILDREN、MAX_DATA 和 LOG_LEVEL;代理模式还会用到 DBGP_PROXY_HOST、DBGP_PROXY_PORT 和 DBGP_IDEKEY。
安装
在 SourceWeft 中
- 打开 控制台中的 Xdebug,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
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}placeholders - Memory 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 automatically - Step 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:
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_PORT DBGP_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)
Docker Compose
Using 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):
PHP/Xdebug Configuration:
Socket File Permissions:
The socket file is created with default permissions. To restrict access, you can:
Automatic 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
Breakpoints
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
Inspection
Watch Expressions
Logpoints
Profiling
Code Coverage
Debug Profiles
Additional Tools
Usage Examples
Setting a Breakpoint
Conditional Breakpoint
Watch Expression
Logpoint
Inspecting Variables
Capture Request Context
Environment Variables
Connection Modes: TCP vs Unix Socket
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
Connection Options:
- TCP (Default):
xdebug.client_host=127.0.0.1+XDEBUG_PORT=9003 - Unix 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 Xdebug - Verify Xdebug config:
php -i | grep xdebug - Ensure
xdebug.client_hostpoints to the MCP server - For TCP: Check firewall allows connections on port 9003
- For Unix socket: Verify socket path exists and has correct permissions:
ls -la /tmp/xdebug.sock - Check 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:9003 - Check 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.sock - MCP server will clean up automatically on next start
- Remove manually:
- "Permission denied": Check socket file permissions
- List socket:
ls -la /tmp/xdebug.sock - Run as same user as PHP:
ps aux | grep php
- List socket:
- Socket path in php.ini:
- Correct:
xdebug.client_host=unix:///tmp/xdebug.sock - Wrong:
xdebug.client_host=unix:/tmp/xdebug.sock(missing one/)
- Correct:
Breakpoints not hitting
- Ensure file paths match exactly (use container paths for Docker)
- Check breakpoint is resolved:
list_breakpoints - Verify script execution reaches that line
- Check that
xdebug.start_with_request=yesis set - Try 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 :9003 - Kill it:
kill -9 <pid>
- Find process:
- Bad config:
- Validate environment variables:
echo $XDEBUG_SOCKET_PATH - Check for typos in path names
- Validate environment variables:
- 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
来源:README.md,提交 8e7b574
工具
0版本历史
1- v1.2.1最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分