
用于 PHP Xdebug 调试的 MCP 服务器——通过支持 Unix 套接字和 TCP 的模型上下文协议实现 AI 辅助的 PHP 调试
概览
一台MCP(模型上下文协议)服务器,通过Xdebug的DBGp协议提供PHP调试功能。这使得像Claude这样的AI助手能够直接调试PHP应用。 - : 步入、步入、退出、继续、停止 - : 行断点、条件断点、异常断点、函数调用断点 - : 查看所有变量,获取特定变量,设置变量值 - : 在当前上下文中评估 PHP 表达式 - : 查看完整调用栈 - : 同时调试多个 PHP 脚本 - : 适用于运行于 Docker 容器中的 PHP - : 持久的观察,每次中断自动评估并带有变更检测 - : 使用 {$var} 占位符记录消息而不停止执行 - : 跟踪断点之间的内存使用和执行时间 - : 跟踪调试时执行的行 - 自动捕获 $_GET、$_POST、$_SESSION、$_COOKIE 头部 - : 在步进过程中跳过厂商/库代码 - : 保存并恢复断点......
概述(AI 翻译)
一台MCP(模型上下文协议)服务器,通过Xdebug的DBGp协议提供PHP调试功能。这使得像Claude这样的AI助手能够直接调试PHP应用。
特色
核心调试
- 全调试控制:步入、步入、步出、继续、停止
- 断点:行断点、条件断点、异常断点、函数调用断点
- 变量检查:查看所有变量,获取特定变量,设置变量值
- 表达式评估:在当前上下文中评估PHP表达式
- 堆栈跟踪:查看完整的调用栈
- 多个会话:同时调试多个PHP脚本
- Docker 支持:支持 Docker 容器中的 PHP 运行
高级功能
- Watch Expressions:持续的观察,在每次中断时自动评估并检测变更
- 日志点:使用
{$var}占位符记录不停止执行的消息 - 内存分析:跟踪断点之间的内存使用和执行时间
- 代码覆盖率:跟踪调试过程中执行的行
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 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)
npm install -g xdebug-mcp
From Source
git clone https://github.com/kpanuragh/xdebug-mcp.git
cd xdebug-mcp
npm install
npm run build
MCP 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
安装
npx -y xdebug-mcp配置
{
"mcpServers": {
"xdebug": {
"command": "xdebug-mcp",
"env": {
"XDEBUG_PORT": "9003",
"LOG_LEVEL": "info"
}
}
}
}