Laravel Monocle: a request profiler your AI agent can read

graphs of performance analytics on a laptop screen

Laravel Monocle is a dev-only request profiler built by Morten Harders that does one thing most profilers don’t: it exposes everything it captures through an MCP server so your AI coding agent can read it directly.

What It Records

Install Monocle and it starts capturing timing, middleware execution, database queries, cache hits and misses, rendered views, outgoing mail, HTTP calls, filesystem operations, and AI agent calls. It works across HTTP requests, queued jobs, and Artisan commands.

Every recorded response gets an X-Monocle-Id header. Every recorded row links back to the file:line in your codebase that triggered it.

The MCP Tool Set

Monocle exposes seven tools your agent can call:

  • monocle-list: recent captures with duration, status, per-section counts, errors, and warnings
  • monocle-show: time breakdown, totals, exceptions, failed calls, slow queries, N+1 detections, and duplicates
  • monocle-rows: any section, filterable, sortable, and paginated
  • monocle-queries: queries grouped by shape, caller, table, or transaction
  • monocle-trace: a request and every job it dispatched
  • monocle-compare: two captures side by side to confirm whether a change helped
  • monocle-clear: wipe the slate and start fresh

Setup

Two commands get you running:

composer require --dev exeque/laravel-monocle
php artisan monocle:install

The install wizard asks what to record, where to store it, and which MCP clients to configure. It then writes config/monocle.php and registers the MCP server. Restart your MCP client after that.

Safety Rails

Monocle records only outside production and only when APP_DEBUG=true. It stays silent during test suite runs unless you explicitly enable it.

The same data available to your agent is also accessible from the terminal via Artisan commands and through a web dashboard at /_monocle. MIT licensed.

Stay on top of AI & Automation with BizStack Newsletter
BizStack  —  Entrepreneur’s Business Stack
Logo