Search by

datomatic / laravel-log-mcp

trippo

Read-only MCP server to let AI assistants safely read and search a Laravel application's logs.

Package info

github.com/datomatic/laravel-log-mcp

pkg:composer/datomatic/laravel-log-mcp

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-30 15:11 UTC

This package is auto-updated.

Last update: 2026-11-30 15:23:32 UTC


README

Laravel Log MCP

Laravel Log MCP

Latest Version on Packagist GitHub CI Action Status Total Downloads

A read-only MCP server that lets an AI assistant (Claude Code, Cursor, …) read and search your Laravel application's logs — production included — through safe, structured parameters. Secrets are redacted before anything leaves the server.

Tool Purpose
describe_logs List the logging channels (driver, level, readability) and their files
query_logs Read entries newest first, filtered by level, time range, text, regex or exception class
get_log_entry Read one entry in full, with its whole stack trace
summarize_logs Count entries per level and per hour/day, and group the most frequent errors

It is the companion of datomatic/laravel-database-mcp: with both installed the assistant can read the failing log entry and the rows behind it.

Requirements

  • PHP 8.3+
  • Laravel 12.41.1+ or 13
  • laravel/mcp 1.0+
  • Channels writing to local files: single, daily, or monolog with a StreamHandler / RotatingFileHandler. Monolog's default LineFormatter and the JsonFormatter are parsed.

Quick start

1. Install the package. The service provider is auto-discovered.

composer require datomatic/laravel-log-mcp
php artisan vendor:publish --tag=log-mcp-config   # optional

2. Decide who may access the server — in a service provider:

use Illuminate\Support\Facades\Gate;

Gate::define('access-log-mcp', fn ($user) => $user->isSuperAdmin());

Without this gate, access is allowed in the local environment only.

3. Register the server in your MCP client, using a project-specific name. The route is protected by auth:sanctum by default:

claude mcp add acme-logs --transport http https://acme.com/log-mcp \
  --header "Authorization: Bearer <token>"

Then ask: "What errors happened in production in the last 2 hours? Show me the stack trace of the most frequent one."

The assistant typically works like this:

  1. describe_logs → channels and files.
  2. summarize_logs with min_level: error and from: "-2 hours" → most frequent errors.
  3. query_logs / get_log_entry with the sample_id → the full entry and stack trace.

Security model

  1. Authentication + authorization. The route uses the configured middleware (auth:sanctum) and the access-log-mcp gate (local-only fallback).
  2. No arbitrary paths. Only files written by the channels in config/logging.php can be read. Files are resolved with realpath and must be regular files inside the channel's directory; a file or id argument is matched by exact name against that list.
  3. Channel allow/deny lists (allowed_channels, denied_channels, * wildcards). The audit log channel is always hidden.
  4. Redaction. Values of sensitive keys (password, *_token, *_secret, authorization, …) are replaced with [REDACTED] in JSON context and query strings, together with bearer tokens, JWTs, password hashes and API keys (redact_keys, redact_patterns). Redaction runs before filtering, so search and regex cannot be used to guess a redacted value.
  5. Bounded work. Files are read backwards in chunks, never loaded whole. Every call stops at max_bytes_scanned / max_scan_seconds and returns a cursor to continue. Results are capped (max_limit) and long messages, context and stack traces are truncated.
  6. Regex opt-in. regex is disabled by default (LOG_MCP_ALLOW_REGEX=true to enable); patterns are length-capped and run with a low PCRE backtrack limit.
  7. Audit log of every tool call (LOG_MCP_AUDIT_LOG=true).

Configuration

Key Default Purpose
register_route / path / middleware true / log-mcp / auth:sanctum HTTP endpoint
gate access-log-mcp Ability checked before access (null disables)
name / instructions "{APP_NAME} Logs" Server identity advertised to clients
allowed_channels / denied_channels null / [] Which channels are exposed
channel_descriptions [] What each channel holds, shown by describe_logs
default_limit / max_limit 20 / 100 Entries per query_logs call
max_bytes_scanned / max_scan_seconds 50 MB / 5 s Budget per call
max_message_length / max_context_length / max_stacktrace_lines 1000 / 2000 / 15 Truncation in query_logs
max_entry_length 100 000 Cap for get_log_entry
allow_regex / regex_max_length / regex_backtrack_limit false / 200 / 100 000 Regex filtering
redact_keys / redact_patterns see config Redaction
audit_log.enabled / audit_log.channel false / null Audit log

OAuth client deduplication and MCP token lifetimes are shared with the other Datomatic MCP servers and configured in datomatic/laravel-mcp-support (MCP_DEDUPE_OAUTH_CLIENTS, MCP_OAUTH_TOKEN_TTL, MCP_OAUTH_REFRESH_TOKEN_TTL).

Tools reference

Common filters (query_logs, summarize_logs)

Argument Example Meaning
channel "daily" Required. A stack with a single readable channel resolves to it
file "laravel-2026-11-30.log" Only this file of the channel
level "error" Exactly this level
min_level "warning" This level or more severe
from / to "2026-11-30 08:00", "-2 hours" Time range, application timezone
search "A-10293" Case-insensitive text, stack trace included
regex "order [A-Z]-\\d+" Case-insensitive PCRE without delimiters (if enabled)
exception "QueryException" Exception class contains this text
cursor "laravel.log@10342" next_cursor of a previous call

Pagination

Entries are returned newest first. Each has an id (file@byte-offset). When next_cursor is not null there are (or may be) older entries: pass it back as cursor. A note tells when a call stopped at its budget rather than at the limit.

summarize_logs

Extra arguments: period (hour or day) and top (default 10, max 50). Errors are grouped by level, exception class and message, with numbers, UUIDs, long hex ids and quoted values replaced by placeholders (Order {n} has no VAT number). Each group has a sample_id for get_log_entry.

Limitations

  • Multiple servers. Each server behind a load balancer has its own log files: the MCP server only reads the logs of the node that handles the request. Ship logs to a shared volume, or use a single dedicated node.
  • No local file, nothing to read. stderr, syslog, errorlog, slack, papertrail and similar channels (Laravel Cloud and Vapor log to stderr) are listed but not readable.
  • Compressed (.gz) rotated files are not read yet.

Testing

composer test
composer analyse
composer lint

License

MIT.