Skip to main content
Glama
smart-xdebug-mcp

smart-xdebug-mcp

by wallter

Smart XDebug MCP Server

npm version npm downloads CI License: Apache-2.0 Node.js 18+

Let AI debug your PHP code.

Smart XDebug MCP connects Claude to your PHP application's debugger, enabling AI-assisted debugging that actually understands your code at runtime.

The Problem

Debugging PHP applications traditionally requires:

  • Manually setting breakpoints in an IDE

  • Stepping through code line by line

  • Remembering to check the right variables at the right time

  • Context-switching between your AI assistant and your debugger

When you ask an AI to help debug, it can only see your code statically. It can't see what's actually happening when your code runs—what values variables hold, where execution flows, or why that exception was thrown.

Related MCP server: DebugMCP

The Solution

Smart XDebug MCP gives Claude direct access to your PHP debugger. Instead of guessing what might be wrong, Claude can:

  • Set breakpoints at suspicious locations

  • Run your code and pause at those breakpoints

  • Inspect variables to see actual runtime values

  • Step through execution to understand the flow

  • Track variable changes over time with built-in history

It's like pair programming with a debugger expert who never gets tired and can analyze complex state instantly.

Why This Matters

For Developers

  • Faster debugging — Describe the bug, let AI investigate

  • Better insights — AI can correlate patterns across variables you might miss

  • Learning tool — Watch how an experienced debugger approaches problems

For AI

  • Runtime context — See actual values, not just code structure

  • Surgical precision — Request only the data needed, preventing context overload

  • Time-travel — Query what variables were at previous breakpoints

How It Works

You: "My /api/orders endpoint returns empty for user 42, but they have orders in the database"

Claude: *Sets breakpoint in OrderController*
        *Triggers the API request*
        *Inspects $user, $query, $results at the breakpoint*

Claude: "Found it. The query filters by user_id but $user->id is null here
         because the auth middleware isn't running on this route."

No manual stepping. No guessing. Just answers.

Quick Start

1. Install

npm install -g smart-xdebug-mcp

2. Configure Claude Code

Add to your MCP settings (~/.config/claude/settings.json or project .mcp.json):

{
  "mcpServers": {
    "xdebug": {
      "command": "npx",
      "args": ["smart-xdebug-mcp"]
    }
  }
}

3. Configure XDebug

Ensure your PHP environment has XDebug configured:

xdebug.mode = debug
xdebug.start_with_request = trigger
xdebug.client_host = host.docker.internal  ; For Docker
xdebug.client_port = 9003

4. Debug

Ask Claude to debug your PHP code:

"Set a breakpoint at app/Services/PaymentService.php line 127,
then run: curl 'http://localhost/api/checkout?XDEBUG_SESSION=mcp'"

Features

Feature

What It Does

Natural Language Debugging

Tell Claude what to debug in plain English

Smart Variable Inspection

AI requests only relevant data, not full dumps

Time-Travel Queries

See what variables were at previous steps

Automatic Path Mapping

Works with Docker without manual configuration

Exception Detection

Auto-pause when errors occur

Session History

Review what happened in past debug sessions

Use Cases

  • "Why is this returning null?" — Trace execution to find where values disappear

  • "This loop seems slow" — Set conditional breakpoints to inspect specific iterations

  • "The API works locally but fails in Docker" — Debug the containerized app directly

  • "I inherited this codebase" — Let AI explore and explain runtime behavior

Requirements

  • Node.js 18+

  • PHP with XDebug 3.x configured for remote debugging

  • Claude Code or another MCP-compatible AI assistant

Configuration

Environment variables for advanced configuration:

Variable

Default

Description

XDEBUG_MCP_PORT

9003

XDebug listener port

XDEBUG_MCP_TIMEOUT

30000

Connection timeout (ms)

XDEBUG_MCP_WATCHDOG_TIMEOUT

300000

Auto-terminate idle sessions (5 min)

Path mappings are auto-detected from .vscode/launch.json or docker-compose.yml.

Architecture

Smart XDebug MCP acts as a bridge:

Claude ←→ MCP Protocol ←→ Smart XDebug MCP ←→ DBGp Protocol ←→ XDebug ←→ PHP

The server translates high-level debugging intent into DBGp commands, handles the complexity of the protocol, and returns clean, AI-friendly responses.

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

License

Copyright 2026 Tyler Wall

Licensed under the Apache License, Version 2.0. See LICENSE for details.


Keywords: PHP debugging, AI debugging, Claude MCP, XDebug integration, autonomous debugging, Model Context Protocol, PHP development tools, AI-assisted development, remote debugging, Docker PHP debugging

Available Tools

6 tools
control_executionA

Controls the debugger's execution flow. Use to step through code or end sessions.

ACTIONS:

step_over: Execute current line, pause at next line in same scope. Use when: Line calls a function you don't need to debug. Example: Skip framework internals, focus on your logic.

step_into: Step INTO the function call on the current line. Use when: You need to debug inside a called function. Example: Debug why UserService::create() fails.

step_out: Run until current function returns to its caller. Use when: Done debugging a function, want to return to caller. Example: Finished debugging a helper, return to controller.

continue: Run until next breakpoint or exception. Use when: Skip to the next interesting point. Example: Jump from authentication to order processing.

stop: Terminate the debug session immediately. Use when: Done debugging, or session is stuck/errored. IMPORTANT: Always stop sessions when done to free the port.

REQUIRES:

  • Any action: Session must be active

  • step_over/step_into/step_out/continue: Session must be paused

AFTER STOP: You can start a new session with start_debug_session.

Inputs: action (required).

get_session_statusA

Returns the current debug session status. Call this FIRST before starting a new session.

WHEN TO USE:

  • Before start_debug_session: Check if a session is already active

  • During debugging: See current location and available actions

  • After errors: Diagnose session state

RETURNS:

  • active: Whether a session exists

  • status: Current state (see below)

  • location: Current file and line when paused

  • available_actions: Valid control_execution actions

  • breakpoints: List of registered breakpoints

SESSION STATES:

  • "initializing": Starting, waiting for XDebug connection

  • "listening": Listening for connections (XDebug not connected yet)

  • "connected": XDebug connected, execution starting

  • "paused": Stopped at breakpoint - can inspect variables and step

  • "running": Code executing, waiting for breakpoint

  • "stopped": Session ended

  • "error": Session in error state

STUCK SESSION RECOVERY: If status is "initializing" for >30 seconds, the connection likely failed. Use control_execution with action="stop" to reset, then check your XDebug configuration.

Inputs: no named parameters.

inspect_variableA

Inspects a PHP variable's value at the current breakpoint. Only works when session is PAUSED.

WHEN TO USE:

  • After hitting a breakpoint (status="paused")

  • To examine specific values causing bugs

  • To understand object structure before filtering

CONTEXT EFFICIENCY - Full dumps are expensive. Use JSONPath filters: BAD (returns thousands of lines): inspect_variable("$order") GOOD (returns only what you need): inspect_variable("$order", "$.total") inspect_variable("$order", "$.items[*].sku") inspect_variable("$request", "$.input.email")

Without a filter, returns structure only (keys/types, no values).

JSONPATH EXAMPLES:

  • '$.property' - Single property

  • '$.items[0]' - First array element

  • '$.items[*].id' - All IDs in items array

  • '$.user.profile.name' - Nested property

REQUIRES: Session must be paused. Call get_session_status to verify.

COMMON VARIABLES:

  • '$this' - Current object instance

  • '$request' - HTTP request (Laravel)

  • '$_GET', '$_POST', '$_SERVER' - PHP superglobals

Inputs: name (required), depth, filter.

query_historyA

Query past variable values from the session recorder (time-travel debugging).

WHEN TO USE:

  • To see how a variable changed over execution steps

  • To compare values between steps without re-running

  • To understand state progression leading to a bug

DOES NOT REQUIRE PAUSED STATE - can query history anytime during an active session.

RETURNS: Array of historical values with step numbers and timestamps, showing how the variable changed over time.

LIMITATION: Only variables that were inspected via inspect_variable are recorded. If you didn't inspect a variable at a step, it won't have history for that step.

EXAMPLE USAGE: "What was $user->status 3 steps ago?" query_history("$user->status", steps_ago=3)

"Show me the last 10 values of $total" query_history("$total", limit=10)

Inputs: variable_name (required), limit, steps_ago.

set_breakpointA

Sets a breakpoint at a specific file and line. Breakpoints persist until the session ends.

WHEN TO USE:

  • BEFORE calling start_debug_session to set initial breakpoints

  • DURING a paused session to add additional breakpoints

PATH FORMAT - Use LOCAL paths relative to your project root:

  • Correct: "app/Http/Controllers/UserController.php"

  • Correct: "src/Services/PaymentService.php"

  • Wrong: "/var/www/html/app/..." (don't use container paths)

The tool automatically translates local paths to container paths using mappings from .vscode/launch.json, docker-compose.yml, or XDEBUG_MCP_PATH_MAPPINGS env var.

CONDITIONAL BREAKPOINTS - For loops, ALWAYS use conditions:

  • '$i > 100' - Break when loop counter exceeds 100

  • '$user->id === 42' - Break for specific user

  • 'count($items) > 0' - Break when array has items

RETURNS:

  • breakpoint_id: Unique identifier

  • remotePath: The translated container path (verify this matches your container)

  • warning: Included if local file doesn't exist

AFTER SETTING: Call start_debug_session to begin debugging.

Inputs: file (required), line (required), condition.

start_debug_sessionA

Starts a new PHP debugging session by listening for XDebug connections and executing a trigger command.

WORKFLOW - Call tools in this order:

  1. get_session_status - Check if a session is already active

  2. set_breakpoint - Set breakpoints at locations you want to inspect

  3. start_debug_session - Start the session with your trigger command

  4. inspect_variable / control_execution - Debug at breakpoints

BEFORE CALLING:

  • Call get_session_status first. If a session is active, use control_execution with action="stop" to end it.

  • Set breakpoints BEFORE calling this (unless using stop_on_entry or stop_on_exception).

XDEBUG TRIGGERING: For xdebug.start_with_request=trigger (common in Docker), append the trigger to your URL:

HOW IT WORKS:

  1. Starts listening on port 9003 (or XDEBUG_MCP_PORT)

  2. Executes your trigger command in a subprocess

  3. Waits for XDebug to connect (timeout: 30s)

  4. Pauses when a breakpoint is hit, exception thrown, or entry reached

LIMITATIONS:

  • Only one session can be active at a time

  • Only listens on one port (cannot debug multiple services simultaneously)

COMMON ERRORS:

  • "SESSION_ALREADY_ACTIVE": Call control_execution with action="stop" first

  • Timeout: Ensure XDebug is configured and ?XDEBUG_SESSION=1 is in your URL

Inputs: command (required), stop_on_entry, stop_on_exception, working_directory.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.8/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool has a unique, non-overlapping purpose: session start, breakpoint setting, variable inspection, execution control, status checking, and history querying. No ambiguity between them.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun snake_case pattern (e.g., start_debug_session, set_breakpoint), making them predictable and easy to understand.

    Tool Count5/5

    With 6 tools, the set is well-scoped for a debugging server. Each tool is essential, covering the full debugging workflow without unnecessary bloat or shortage.

    Completeness4/5

    The tool set covers the core debugging lifecycle: start, breakpoints, inspect, control, status, and history. Minor gap is the lack of a tool to remove individual breakpoints without ending the session, but the set is otherwise complete.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      B
      maintenance
      Enables AI assistants to debug PHP applications through Xdebug's DBGp protocol, providing full debugging control including breakpoints, variable inspection, stack traces, and advanced features like watch expressions and code coverage.
      46
      282 npm
      28
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to debug code inside VS Code by setting breakpoints, stepping through execution, inspecting variables, and evaluating expressions across multiple languages.
      581
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      Enables AI assistants to deeply interact with the PHP ecosystem, including runtime, static analysis, security scanning, testing, Composer, and frameworks like Laravel and Symfony. It exposes over 30 tools, 8 resources, and 7 prompts via MCP, allowing natural language commands to run PHP linting, static analysis, audits, tests, and project initialization.
      41
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Bridges AI agents with VS Code's debugger, enabling breakpoint management, step execution, variable inspection, and stack tracing via CLI commands.
      24
      GPL 3.0