Xdebug MCP
Debug PHP with Runtime Data — No var_dump(), No Guesswork
Trace-based debugging for PHP, built on Xdebug. Drive the tools from the CLI, or let an AI assistant run the core tools through plugin, Skill, or MCP integration.
-NO-red)
Natural Language Debugging
Just tell your AI assistant what you want:
English:
"Debug script.php and find why $user is null at line 42"
"Profile api.php and find the performance bottleneck"
"Trace the authentication flow in login.php"
"Check test coverage for UserService"
日本語:
"script.phpをデバッグして、42行目で$userがnullになる原因を調べて"
"api.phpのパフォーマンスボトルネックを見つけて"
"login.phpの認証フローをトレースして"
"UserServiceのテストカバレッジを確認して"
When connected through the plugin, Skill, or an MCP-capable client, the AI can select the appropriate tool, execute it, and analyze the results.
Requirements
- PHP 8.2+
- Xdebug 3.x extension (installed, but not enabled by default)
- Optional: an AI assistant (Claude Code plugin, Codex Skill, or any MCP-capable client)
💡 Performance Tip: Keep Xdebug disabled in php.ini for daily use. This tool loads Xdebug on-demand only when needed.
Quick Start
1. Install
composer global require koriym/xdebug-mcp
2. Verify Xdebug
"$(composer global config bin-dir --absolute --quiet)/check-env"
3. (Optional) Wire up an AI assistant
Two integrations are available. We recommend the Skill: these tools are stateless one-shot CLI commands by design, so letting the agent run them directly — guided by the Skill's usage notes — is the simplest and most accurate path. Choose MCP when your client has no shell access or no Skill support.
| Skill (recommended) | MCP server |
|---|
| How it works | The agent reads SKILL.md and runs the CLI tools directly | The client calls the tools over JSON-RPC (stdio) |
| Setup | Plugin install, or copy one directory | Register in the client's MCP config |
| Best for | AI coding agents with shell access (Claude Code, Codex, ...) | MCP-capable clients without shell/Skill support (e.g. Claude Desktop) |
Claude Code — install the plugin (which bundles the Skill):
/plugin marketplace add koriym/xdebug-mcp
/plugin install xdebug@xdebug-mcp
Codex CLI — install the Skill:
tmp=$(mktemp -d) \
&& git clone --depth 1 https://github.com/koriym/xdebug-mcp.git "$tmp/xdebug-mcp" \
&& mkdir -p ~/.codex/skills \
&& cp -r "$tmp/xdebug-mcp/skills/xdebug" ~/.codex/skills/ \
&& rm -rf "$tmp"
Any MCP-capable client — see MCP Configuration below.
You can skip this step entirely and use the CLI tools directly.
4. Try it
# Download demo files
git clone --depth 1 https://github.com/koriym/xdebug-mcp.git /tmp/xdebug-demo
# Ask Claude to debug
"Debug /tmp/xdebug-demo/demo/buggy.php and find the bugs"
Or use the skill directly:
/xdebug
Try CLI Tools
Run the demo examples to see each tool in action:
# Debug buggy code with breakpoints (JSON output)
./bin/xstep --break="demo/buggy.php:22" -- php demo/buggy.php
# Trace execution flow
./bin/xtrace --json --context="Debug demo" -- php demo/buggy.php
# Profile performance bottlenecks
./bin/xprofile --json -- php demo/slow.php
# Analyze code coverage (raw mode for plain PHP scripts)
./bin/xcoverage --json --raw -- php demo/coverage.php
# Get stack trace at breakpoint
./bin/xback --break="demo/buggy.php:44" -- php demo/buggy.php
# Compare variable states with different inputs
./bin/xcompare --break="demo/buggy.php:22" --run-a="php demo/buggy.php 10" --run-b="php demo/buggy.php 0"
# Compare current code vs an earlier commit
./bin/xcompare --break="demo/buggy.php:22" --run="php demo/buggy.php 10" --compare-with=HEAD~1
Each command outputs structured JSON that AI can analyze to provide debugging insights. xtrace, xprofile, and xcoverage print text unless --json is given (xcoverage --raw --branch-coverage always prints JSON); the other tools print JSON by default.
How It Works
flowchart LR
A[You] -->|"Debug login.php"| B[AI Assistant]
B -->|CLI / MCP| C[xtrace, xstep, ...]
C -->|Runtime Analysis| D[Xdebug]
D -->|JSON| C
C -->|Results| B
B -->|Explanation| A
No var_dump(). No code modification. No guesswork.
Available Tools