
Xdebug
io.github.kpanuragh由 GitHub 帳號 kpanuragh 發布v1.2.1更新於 Oct 24, 2026
MCP server for PHP Xdebug debugging with breakpoints, stepping, and variable inspection
概覽
一個 MCP 伺服器,讓 AI 助理透過 Xdebug 的 DBGp 協定除錯 PHP 應用程式,支援中斷點、單步執行與變數檢視。
- 可以做什麼
- 管理除錯工作階段:列出、檢視狀態、切換使用中的工作階段與關閉工作階段,可同時處理多個工作階段。
- 設定、修改、移除與列出中斷點,包含行中斷點、條件中斷點、例外中斷點與函式呼叫中斷點,也支援待套用中斷點。
- 控制執行:繼續、逐步進入、逐步跳過、逐步跳出、停止或分離。
- 檢視狀態:呼叫堆疊、變數內容、變數、原始碼,並可求值 PHP 運算式或修改變數值。
- 加入監看運算式與記錄點,並擷取 GET、POST、工作階段、Cookie 與請求標頭等請求內容。
- 進行記憶體與耗時分析、追蹤程式碼涵蓋率、儲存與載入除錯設定,並將工作階段匯出為 JSON 或 HTML。
- 適用情境
- 適合在開發或排查 PHP 程式時,讓助理直接操作真實的除錯工作階段,而不是只憑原始碼推測;也適用於執行在 Docker 容器中或經 DBGp 代理的 PHP。
- 執行需求
- 以 npm 套件 xdebug-mcp 透過 stdio 在本機執行,需要 Node.js。PHP 需安裝 Xdebug 並啟用單步除錯,且指向伺服器的主機與連接埠。選用環境變數可設定連接埠、主機、Unix 通訊端路徑、路徑對應、逾時與記錄層級;代理模式需要 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 分