Back to list
koriym

xdebug

by koriym

Enable AI to debug PHP with Xdebug

29🍴 5📅 Jan 22, 2026

SKILL.md


name: xdebug description: PHP debugging and analysis tools using Xdebug. Use when asked to trace, debug, profile, or analyze coverage of PHP code.

Xdebug MCP Tools

Non-invasive PHP debugging and analysis tools. No var_dump() or code modification needed.

Tool Paths

Tools are installed globally via composer. Use absolute paths:

ToolPath
xtrace~/.composer/vendor/bin/xtrace
xstep~/.composer/vendor/bin/xstep
xprofile~/.composer/vendor/bin/xprofile
xcoverage~/.composer/vendor/bin/xcoverage
xback~/.composer/vendor/bin/xback

Tool Selection Guide

User RequestTool
Trace, execution flow, show function callsxtrace
Step debugging, breakpoints, inspect variables, track variable changesxstep
Profile, performance, bottlenecks, slow codexprofile
Coverage, test coverage, which lines testedxcoverage
Backtrace, call stack, how did we get herexback

"Trace" Ambiguity

The word "trace" can mean different things:

  • Forward Tracextrace (records execution from start to finish)
  • Backtrace / Stack Tracexback (shows call stack at a point)
  • Step through / Debugxstep (interactive with breakpoints)

xtrace - Forward Trace (Full)

Trace execution forward from start to finish. Captures complete execution flow, function calls, parameters, and timing data.

Output: JSON with $schema URL for semantic details and AI analysis strategies. Key fields: {lines, functions, max_depth, db_queries}

~/.composer/vendor/bin/xtrace [--json] [--context=TEXT] [--include-vendor=PATTERNS] -- command

Examples

~/.composer/vendor/bin/xtrace --context="Debug login" -- php login.php
~/.composer/vendor/bin/xtrace --context="Test analysis" -- vendor/bin/phpunit tests/UserTest.php
~/.composer/vendor/bin/xtrace --include-vendor="bear/*" -- php app.php

When to Use

  • "Trace this code"
  • "Show execution flow"
  • "What functions are called?"
  • General PHP debugging (default choice)

xstep - Forward Trace (Step-by-Step)

Stop at breakpoint, step forward N times, record variable changes at each step. See how variable values affect branching ("this variable was X, so it went into this branch").

Output: JSON with $schema URL for semantic details. Key fields: {breaks: [{step, location, variables}]} - Variables show diff only (changed values).

~/.composer/vendor/bin/xstep --break=file.php:line --steps=N [--context=TEXT] [--include-vendor=PATTERNS] -- command

Options

  • --break=file.php:line - Single breakpoint location
  • --break=file.php:line:condition - Conditional (e.g., $user==null)
  • --steps=N - Step forward N times from breakpoint

Examples

# Step 20 times from line 42
~/.composer/vendor/bin/xstep --break="user.php:42" --steps=20 --context="Track auth" -- php user.php

# Conditional breakpoint
~/.composer/vendor/bin/xstep --break="user.php:15:\$id==null" --steps=10 -- php user.php

Workflow Tips

  • Need more steps? Set new breakpoint at where you stopped, run again
  • Too much variable info? Use xtrace first to see flow, then xstep for details

When to Use

  • "Track how variable changes step by step"
  • "Why did it branch this way?"
  • "What's the variable value at line X?"

xprofile - Performance Profiler

Identify performance bottlenecks with precision data.

Output: JSON with $schema URL for semantic details and AI analysis strategies. Key fields: {time_ms, memory_mb, bottlenecks} - Bottlenecks auto-identified.

~/.composer/vendor/bin/xprofile [--json] [--context=TEXT] [--include-vendor=PATTERNS] -- command

Examples

~/.composer/vendor/bin/xprofile --context="Optimize processing" -- php process.php
~/.composer/vendor/bin/xprofile --json -- php script.php
~/.composer/vendor/bin/xprofile --include-vendor="doctrine/*" -- php app.php

When to Use

  • "Profile this code"
  • "Find bottlenecks"
  • "Why is this slow?"
  • "Memory usage analysis"

xcoverage - Code Coverage

Collect code coverage data for PHPUnit or any PHP script. Shows only uncovered lines (compact output).

Output: JSON with $schema URL for semantic details. Key fields: {summary: {coverage_percent, covered_lines, uncovered_lines}, uncovered: {file: [lines]}}

~/.composer/vendor/bin/xcoverage [--include-vendor=PATTERNS] -- command
~/.composer/vendor/bin/xcoverage -- vendor/bin/phpunit        # PHPUnit
~/.composer/vendor/bin/xcoverage -- php script.php            # Any PHP script

Examples

~/.composer/vendor/bin/xcoverage -- vendor/bin/phpunit
~/.composer/vendor/bin/xcoverage --include-vendor="bear/*,ray/di" -- vendor/bin/phpunit
~/.composer/vendor/bin/xcoverage -- vendor/bin/phpunit --filter testMethod

When to Use

  • "Check test coverage"
  • "Which lines are tested?"
  • "Find untested code"

xback - Backtrace Capture

Get call stack (backtrace) at a specific line. Shows "who called this?" - the chain of function calls that led to this point.

Output: JSON with $schema URL for semantic details. Key fields: {backtrace: [{file, line, function, args}]}

~/.composer/vendor/bin/xback [--break=SPEC] [--depth=N] [--context=TEXT] -- command

Examples

~/.composer/vendor/bin/xback -- php script.php                    # First line
~/.composer/vendor/bin/xback --break=app.php:50 -- php app.php    # At breakpoint
~/.composer/vendor/bin/xback --depth=20 -- php main.php           # Deep trace

When to Use

  • "Get backtrace at line X"
  • "Show call stack"
  • "How did execution reach this line?"

Common Options

OptionDescription
--jsonAI-optimized JSON output
--context=TEXTAdd description for AI analysis
--include-vendor=PATTERNSInclude vendor packages

Vendor Filtering

By default, vendor code is excluded to focus on your code. Use --include-vendor when needed:

--include-vendor="bear/*"           # Include specific framework
--include-vendor="bear/*,ray/di"    # Multiple packages
--include-vendor="*/*"              # Include all vendor (framework debugging)

JSON Schemas

Score

Total Score

50/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon