Skip to main content
Glama
mcp-php-debugbar
by movinginfo

mcp-php-debugbar

AI-powered PHP debugging via Model Context Protocol.

Connects PHP DebugBar and Laravel Debugbar to AI assistants. The AI sees exceptions, SQL queries, timelines and logs from your running app — reads the actual PHP source files and suggests concrete fixes with exact line numbers.

MCP PHP DebugBar Laravel Debugbar

Supported clients: Cursor  ·  VS Code  ·  Claude Desktop  ·  OpenAI Codex
Coming soon: Antigravity


How it works

Your PHP/Laravel app (localhost:8000)
        │  phpdebugbar-id header
        ▼
  mcp-php-debugbar  (Node.js MCP Server, stdio)
        │  37 tools
        ▼
  AI assistant (Cursor / VS Code / Claude / Codex)
        │  reads PHP files, analyzes issues, applies fixes
        ▼
  Developer gets: file:line + code context + ready-to-apply fix

One command:

Debug /users page

The AI calls debugbar_auto_debug → health score, every issue with the exact PHP file + line number + surrounding code + a concrete fix.


Related MCP server: Laravel AI MCP Server

Requirements

  • Node.js 18+

  • PHP 7.4+ with a running dev server

  • PHP DebugBar v3.5+ or Laravel Debugbar v4.1+


Step 1 — Install PHP DebugBar in your project

Laravel project

composer require fruitcake/laravel-debugbar --dev

In your Laravel .env:

APP_DEBUG=true
DEBUGBAR_ENABLED=true

In config/debugbar.php:

'storage' => [
    'enabled' => true,
    'open'    => true,   // enables the /_debugbar/open endpoint
    'driver'  => 'file',
    'path'    => storage_path('debugbar'),
],

Vanilla PHP project

composer require php-debugbar/php-debugbar
use DebugBar\DebugBar;
use DebugBar\Storage\FileStorage;

$debugbar = new DebugBar();
$debugbar->setStorage(new FileStorage(__DIR__ . '/storage/debugbar'));
$debugbar->sendDataInHeaders(); // sends the phpdebugbar-id header

Add /debugbar/open.php:

<?php
require __DIR__ . '/../vendor/autoload.php';
// ... initialize debugbar ...
$handler = new DebugBar\OpenHandler($debugbar);
$handler->handle();

Auto-detection: if PROJECT_ROOT points to a Laravel project (an artisan file is present), the server automatically uses /_debugbar/open and sets type to laravel. For vanilla PHP it uses /debugbar/open.


Step 2 — Install mcp-php-debugbar

git clone https://github.com/movinginfo/mcp-php-debugbar.git
cd mcp-php-debugbar
npm install
npm run build

Step 3 — Connect to your AI client


Cursor

Option A — per project (recommended)

Create or edit .cursor/mcp.json in the root of your PHP project:

{
  "mcpServers": {
    "php-debugbar": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-php-debugbar/dist/index.js"],
      "env": {
        "DEBUGBAR_BASE_URL": "http://localhost:8000",
        "DEBUGBAR_TYPE": "auto",
        "PROJECT_ROOT": "/absolute/path/to/your/php-project"
      }
    }
  }
}

Option B — global (all projects)

File: ~/.cursor/mcp.json

{
  "mcpServers": {
    "php-debugbar": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-php-debugbar/dist/index.js"],
      "env": {
        "DEBUGBAR_BASE_URL": "http://localhost:8000",
        "DEBUGBAR_TYPE": "auto",
        "PROJECT_ROOT": ""
      }
    }
  }
}

In the global setup you can pass PROJECT_ROOT at connect time:

Connect to http://localhost:8000, project root is /var/www/myapp

Verify:

Restart Cursor → Settings → MCP → php-debugbar should appear with status connected.

Windows example:

{
  "mcpServers": {
    "php-debugbar": {
      "command": "node",
      "args": ["C:/projects/mcp-php-debugbar/dist/index.js"],
      "env": {
        "DEBUGBAR_BASE_URL": "http://localhost:8000",
        "DEBUGBAR_TYPE": "auto",
        "PROJECT_ROOT": "C:/projects/my-laravel-app"
      }
    }
  }
}

VS Code

Requires VS Code 1.99+ with the GitHub Copilot Chat extension.

Step 1. Enable MCP support in VS Code settings:

// .vscode/settings.json
{
  "chat.mcp.enabled": true,
  "chat.agent.enabled": true
}

Step 2. Create .vscode/mcp.json in the root of your PHP project:

{
  "servers": {
    "php-debugbar": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/mcp-php-debugbar/dist/index.js"],
      "env": {
        "DEBUGBAR_BASE_URL": "http://localhost:8000",
        "DEBUGBAR_TYPE": "auto",
        "PROJECT_ROOT": "/absolute/path/to/your/php-project"
      }
    }
  }
}

If you cloned this repo and open it in VS Code, both .vscode/mcp.json and .vscode/settings.json are already included — ${workspaceFolder} resolves automatically.

Windows example:

{
  "servers": {
    "php-debugbar": {
      "type": "stdio",
      "command": "node",
      "args": ["C:/projects/mcp-php-debugbar/dist/index.js"],
      "env": {
        "DEBUGBAR_BASE_URL": "http://localhost:8000",
        "DEBUGBAR_TYPE": "auto",
        "PROJECT_ROOT": "C:/projects/my-laravel-app"
      }
    }
  }
}

Step 3. Restart VS Code → open GitHub Copilot Chat → switch to Agent mode → php-debugbar will appear in the tools list.

Note: VS Code uses the key "servers" in .vscode/mcp.json, while Cursor and Claude use "mcpServers".

Run the Example project from VS Code:

Ctrl+Shift+P → Tasks: Run Task → select:

Task

What it does

Start PHP Example Server

Runs php -S localhost:8000 from the Example folder

Run MCP Smoke Test

Runs the full test of all 37 tools

Run Direct DebugBar Test

Direct test without MCP — outputs data with code and fixes

Build MCP Server

Recompile TypeScript

Or press F5 → select a debug configuration:

  • Debug MCP Server — launches the MCP server with the Node.js debugger

  • Run Smoke Test

  • Run Direct DebugBar Test


Claude Desktop

macOS — open or create:

~/Library/Application Support/Claude/claude_desktop_config.json

Windows — open or create:

%APPDATA%\Claude\claude_desktop_config.json

Linux — open or create:

~/.config/Claude/claude_desktop_config.json

File contents:

{
  "mcpServers": {
    "php-debugbar": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-php-debugbar/dist/index.js"],
      "env": {
        "DEBUGBAR_BASE_URL": "http://localhost:8000",
        "DEBUGBAR_TYPE": "auto",
        "PROJECT_ROOT": "/absolute/path/to/your/php-project"
      }
    }
  }
}

If mcpServers already exists in your config, just add the "php-debugbar" block inside it.

Restart Claude Desktop. A 🔌 icon will appear in the bottom-left corner showing the number of connected MCP servers.

Windows example:

{
  "mcpServers": {
    "php-debugbar": {
      "command": "node",
      "args": ["C:/projects/mcp-php-debugbar/dist/index.js"],
      "env": {
        "DEBUGBAR_BASE_URL": "http://localhost:8000",
        "DEBUGBAR_TYPE": "auto",
        "PROJECT_ROOT": "C:/projects/my-laravel-app"
      }
    }
  }
}

Antigravity

🚧 Full native integration is in development. Will be added in the next release.

In the meantime you can use it via the standard stdio transport:

DEBUGBAR_BASE_URL=http://localhost:8000 \
PROJECT_ROOT=/path/to/your/php-project \
node /path/to/mcp-php-debugbar/dist/index.js

Step 4 — Start your server and connect

Laravel

# 1. Start Laravel
php artisan serve

# 2. In the AI chat:
# "Connect debugbar to http://localhost:8000"
# The server auto-detects Laravel via the artisan file
# and uses /_debugbar/open

Vanilla PHP

# 1. Start PHP dev server
php -S localhost:8000 -t public

# 2. In the AI chat:
# "Connect debugbar to http://localhost:8000"

Usage

Basic workflow

1. Start your PHP/Laravel server
2. In the AI chat: "Connect debugbar to http://localhost:8000"
3. Open your browser and visit the page you want to debug
4. Ask: "Debug the last request" or "Debug /users endpoint"

Example AI conversation

You:  Debug /users page

AI:   [calls debugbar_auto_debug(url="/users")]

      🐛 DEBUG REPORT: GET /users
      Health score: 35/100 [████░░░░░░]
      Duration: 245ms | SQL: 12 queries | Exceptions: 0

      ISSUE 1/2: 🔴 [N+1] "posts" queried 10×
      📍 app/Http/Controllers/UserController.php:34

         30 | $users = User::all();
         31 | foreach ($users as $user) {
      >>>  34 |     $posts = Post::where('user_id', $user->id)->get();
         35 | }

      💡 FIX:
         $users = User::with('posts')->get();

You:  Apply this fix

AI:   [opens UserController.php, edits line 34]
      ✅ Fixed: replaced N+1 loop with eager loading

Quick command reference

# Connect (run once at the start)
Connect debugbar to http://localhost:8000

# One-shot debug — the main tool
Debug /page-name
Debug the last request
Debug /users and fix all issues

# Specific problems
Show all exceptions
Show N+1 queries
Fix issue #1
Fix issue #2

# Read source files
Read file app/Http/Controllers/UserController.php line 45

# Status
Debugbar status
List captured requests
Performance summary

# Laravel
Show route info
Full Laravel report
Show auth info
Show cache operations

All 37 MCP tools

Connection

Tool

Description

debugbar_connect

Connect to a PHP/Laravel server

debugbar_disconnect

Disconnect

debugbar_status

Connection state and request count

debugbar_chrome_tabs

List Chrome tabs (CDP)

debugbar_start_chrome_monitor

Auto-capture via Chrome DevTools

Requests

Tool

Description

debugbar_list_requests

List all captured requests

debugbar_get_request

Full details for a specific request

debugbar_fetch_url

Make an HTTP request and capture debug data

debugbar_refresh_requests

Pull latest requests from the server

debugbar_clear

Clear the request cache

Database

Tool

Description

debugbar_get_queries

SQL queries with duration and bindings

debugbar_get_duplicate_queries

N+1 detection — repeated queries

debugbar_compare_queries

Compare query counts between two requests

Logs & Exceptions

Tool

Description

debugbar_get_logs

Log messages filtered by level

debugbar_get_exceptions

Exceptions with full stack traces

Performance

Tool

Description

debugbar_get_timeline

Timeline measurements

debugbar_performance_summary

Request table sorted by duration / SQL count

Laravel-specific

Tool

Description

debugbar_get_route

Route URI, action, middleware

debugbar_get_views

Blade templates rendered

debugbar_get_events

Events fired and their listeners

debugbar_get_auth

Auth guards and user info

debugbar_get_models

Eloquent model instances

debugbar_get_cache

Cache hit / miss / write / delete

debugbar_get_session

Session data

debugbar_laravel_report

Full combined Laravel report

AI analysis — the key tools

Tool

Description

debugbar_analyze

Analyze: N+1, slow queries, exceptions, memory

debugbar_analyze_all

Health report across all captured requests

debugbar_suggest_fixes

Prioritized fix list for the latest request

debugbar_auto_debug

One-shot: fetch URL → load data → read source files → report with code and fixes

debugbar_fix_issue

Focus on issue #N: source code + exact line + concrete fix

debugbar_read_source

Read any PHP file from PROJECT_ROOT around a specific line

IDE integration

Tool

Description

debugbar_open_preview

Open Cursor built-in preview

debugbar_start_polling

Poll for new requests periodically

debugbar_stop_polling

Stop polling

debugbar_watch_and_debug

Auto-analyze new requests as they arrive

debugbar_auto_analyze

Analyze the last N requests

debugbar_webhook_start

Start a webhook listener

debugbar_preview_modes

Show available preview connection modes


Environment variables (.env)

# PHP/Laravel dev server URL (required)
DEBUGBAR_BASE_URL=http://localhost:8000

# Open handler path
# Laravel:      /_debugbar/open
# Vanilla PHP:  /debugbar/open
DEBUGBAR_OPEN_HANDLER=/_debugbar/open

# Project type: laravel | php | auto  (auto checks for artisan file)
DEBUGBAR_TYPE=auto

# Absolute path to your PHP project (enables source file reading and AI fixes)
# Examples: /var/www/myapp   C:/projects/myapp   /home/user/laravel-app
PROJECT_ROOT=

# Chrome remote debugging (optional — enables auto-capture on page visit)
CHROME_HOST=localhost
CHROME_PORT=9222
CHROME_AUTO_CONNECT=false

# Other
MAX_REQUESTS=100
REQUEST_TIMEOUT=10000
LOG_LEVEL=info

Example project

The Example/ folder contains a ready-to-use PHP DebugBar demo:

  • Home page with an intentional N+1 problem and a caught exception

  • /users.php — standard SQL queries

  • /error.php — 4 different exception types

  • /slow.php — simulated slow page (~850 ms timeline)

  • /api.php — JSON API endpoint

# Start the example server
php -S localhost:8000 -t Example/public Example/public/router.php

# Direct test (no MCP needed)
node test/direct-debugbar.mjs

# Full MCP smoke test (all 37 tools)
node test/smoke-test.mjs

Development

npm run dev      # run without building (tsx)
npm run build    # TypeScript → dist/
npm run watch    # watch mode
npm run inspect  # MCP Inspector UI in the browser

Publish to GitHub

cd mcp-php-debugbar
git init
git add .
git commit -m "feat: initial release"

# GitHub CLI:
gh repo create mcp-php-debugbar --public --push

# or manually:
git remote add origin https://github.com/YOUR_USERNAME/mcp-php-debugbar.git
git branch -M main
git push -u origin main

.env is in .gitignore — your local paths and secrets will not be committed.


Roadmap

  • PHP DebugBar v3.5

  • Laravel Debugbar v4.1

  • Auto-detection of Laravel via artisan file

  • PROJECT_ROOT — source file reading

  • debugbar_auto_debug — one-shot debug with code context

  • debugbar_fix_issue — code + fix for a specific issue

  • N+1 detection, slow query analysis, exception analysis

  • Cursor support

  • Claude Desktop support

  • OpenAI Codex support

  • VS Code — stable support (GitHub Copilot MCP)

  • Antigravity — native integration

  • npm publish — npx mcp-php-debugbar

  • Auto-apply fixes (write to file)

  • EXPLAIN analysis (missing index detection)

  • Xdebug integration


License

MIT

Available Tools

37 tools
debugbar_analyze_allB

Run auto-analysis across ALL cached requests and show a prioritized list of issues, ranked by severity. Perfect for identifying the most critical problems across your entire app.

Inputs: limit, min_severity.

debugbar_auto_analyzeB

Deeply analyze a captured request with the smart issue detection engine. Returns a health score, detected issues (N+1 queries, slow queries, exceptions, memory, performance), and concrete fix suggestions for each issue.

Inputs: id, slow_query_ms, slow_request_ms.

debugbar_auto_debugA

ONE-SHOT DEBUGGING TOOL. Fetches the latest request (or specified URL), loads full DebugBar data, runs analysis, reads ALL implicated PHP source files, and returns a complete developer report: every issue with exact code location, code context, and concrete fix. This is what you call to debug a PHP app — no manual steps needed.

Inputs: id, all, url, refresh.

debugbar_chrome_tabsB

List open tabs in Chrome browser (requires Chrome remote debugging port).

Inputs: chrome_host, chrome_port.

debugbar_clearA

Clear all locally cached debugbar requests from memory.

Inputs: no named parameters.

debugbar_compare_queriesA

Compare SQL query counts and total time between two captured requests to measure optimization impact.

Inputs: id1 (required), id2 (required).

debugbar_connectB

Connect to a running PHP/Laravel development server and optionally start monitoring Chrome browser for automatic debugbar data capture.

Inputs: base_url (required), type, chrome_host, chrome_port, +2 more.

debugbar_disconnectA

Disconnect from the PHP server and stop Chrome monitoring.

Inputs: no named parameters.

debugbar_fetch_urlA

Make an HTTP request to the connected PHP server, capture the debugbar data from the response, and store it. Great for testing specific endpoints.

Inputs: path (required), body, method, headers.

debugbar_fix_issueA

Analyze a specific issue (exception, N+1, slow query) from a DebugBar request, read the implicated PHP source file, and return the exact problematic code with a concrete fix. This is the primary tool for AI-driven bug fixing.

Inputs: id, issue_index.

debugbar_get_authB

Get authentication state for a Laravel request — which guards are active and the authenticated user details.

Inputs: id.

debugbar_get_cacheA

Get cache operations (hits, misses, writes, deletes) during a Laravel request.

Inputs: id, type.

debugbar_get_duplicate_queriesB

Detect duplicate/redundant SQL queries in a request — a common performance issue in Laravel (N+1 problem).

Inputs: id.

debugbar_get_eventsB

Get all Laravel events fired during a request with listener details and dispatch location.

Inputs: id, search.

debugbar_get_exceptionsB

Get all exceptions and errors thrown during a PHP/Laravel request, including full stack traces with file and line numbers.

Inputs: id, all_requests.

debugbar_get_logsC

Get log messages and debug output from a PHP/Laravel request. Supports filtering by level (debug, info, warning, error, etc.).

Inputs: id, level, search.

debugbar_get_modelsB

Get Eloquent model statistics for a Laravel request — which models were loaded and how many instances.

Inputs: id.

debugbar_get_queriesB

Get all SQL queries executed during a PHP/Laravel request. Shows query text, bindings, duration, row count, and slow queries warning.

Inputs: id, limit, search, slow_only, +1 more.

debugbar_get_requestB

Get detailed debugging information for a specific request by its ID. Shows timing, memory, route, queries summary, and more.

Inputs: id, load_data, full_report.

debugbar_get_routeC

Get Laravel route information for a request: URI, action, middleware, route name, and constraints.

Inputs: id.

debugbar_get_sessionC

Get session data stored during a Laravel request.

Inputs: id.

debugbar_get_timelineA

Get the performance timeline for a PHP/Laravel request. Shows measured code blocks, their duration, and relative start times.

Inputs: id, min_duration_ms.

debugbar_get_viewsA

Get all Blade views / templates rendered during a Laravel request, including component count and variable count.

Inputs: id.

debugbar_laravel_reportA

Generate a comprehensive Laravel debug report for a request: route, auth, queries, events, views, models, cache, exceptions, and timeline in one output.

Inputs: id.

debugbar_list_requestsB

List all captured PHP/Laravel debugbar requests, showing method, URI, timing, query count, and log count.

Inputs: max, refresh.

debugbar_open_previewB

Get the exact commands and steps to open a browser preview with PHP DebugBar integration in Cursor IDE or Chrome. Shows how to enable automatic debug data capture.

Inputs: url, mode, cdp_port.

debugbar_performance_summaryA

Show a performance summary across all captured requests — total time, query count, memory. Useful for spotting slow pages.

Inputs: limit, sort_by.

debugbar_preview_modesA

Show all available preview modes for Cursor + PHP DebugBar integration, with pros/cons for each approach.

Inputs: no named parameters.

debugbar_read_sourceA

Read a PHP source file from the project, optionally focusing on a specific line. File paths are resolved against PROJECT_ROOT in .env. Pass a file path from an exception stack trace or query backtrace to see the exact code.

Inputs: file (required), full, line, context.

debugbar_refresh_requestsA

Fetch the latest requests from the PHP server's debugbar storage and update the local cache.

Inputs: max.

debugbar_start_chrome_monitorA

Start or restart Chrome DevTools Protocol monitoring for automatic debugbar request capture.

Inputs: chrome_host, chrome_port.

debugbar_start_pollingA

Start polling the PHP DebugBar open handler for new requests. Use this when Chrome CDP is not available (e.g. Cursor Simple Browser mode). Every new request is captured automatically.

Inputs: interval_ms, auto_analyze.

debugbar_statusA

Show current connection status, Chrome monitoring state, and number of captured requests.

Inputs: no named parameters.

debugbar_stop_pollingA

Stop the request polling loop.

Inputs: no named parameters.

debugbar_suggest_fixesA

Get a prioritized, actionable list of code fixes for a request based on its debug data. Returns specific PHP/Laravel code suggestions the AI can apply directly.

Inputs: id, include_code.

debugbar_watch_and_debugB

Start continuous monitoring: poll for new requests AND automatically analyze each one. Shows a live debug dashboard in the MCP output. Best used with Cursor Simple Browser.

Inputs: alert_on, interval_ms, max_captures.

debugbar_webhook_startB

Start a local webhook server that receives PHP DebugBar IDs sent from an injected JavaScript snippet. Returns the JS snippet and PHP snippet to add to your project for zero-configuration capture.

Inputs: port.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 37 tools

    Disambiguation2/5

    Several clusters overlap heavily: auto_analyze vs analyze_all vs auto_debug vs laravel_report vs suggest_fixes vs fix_issue all produce 'analysis + suggestions' for a request, and start_chrome_monitor vs start_polling vs watch_and_debug vs webhook_start are four different ways to begin capture. An agent must read carefully to choose among them, and boundaries like analyze_all vs auto_analyze are only marginally distinct. The domain-data getters (queries, logs, views, events, auth, models, cache, session) are distinct, but the meta/analysis and monitoring families are confusingly redundant.

    Naming Consistency4/5

    Nearly all tools use the debugbar_ prefix with a verb_noun shape (get_queries, list_requests, start_polling, read_source), which is predictable and readable. A few are bare nouns or adjectives (debugbar_status, debugbar_clear, debugbar_performance_summary, debugbar_preview_modes), but these are minor deviations rather than a convention clash.

    Tool Count2/5

    37 tools is far more than needed for debugbar inspection; the surface is bloated by redundant analysis and monitoring variants (auto_analyze/analyze_all/auto_debug, three+ capture-start methods) and documentation-y tools (preview_modes, open_preview). A leaner set of ~15 would cover the same workflows without decision overhead.

    Completeness4/5

    Coverage of DebugBar data categories is thorough: connection lifecycle, capture (fetch/poll/CDP/webhook), per-request detail, queries, duplicates, logs, exceptions, timeline, route, views, events, auth, models, cache, session, source reading, and reporting. Minor gaps exist (no per-request export, no cache-clearing of a single request, no config/environment inspection), but agents can work around them.

    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
      254 npm
      29
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Provides AI assistants with direct access to Laravel documentation, coding rules, and implementation templates stored locally. It enables searching documentation, retrieving design system guides, and accessing domain-specific code examples to streamline Laravel development.
      8
      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.
      583
      MIT