datomatic / laravel-log-mcp
Read-only MCP server to let AI assistants safely read and search a Laravel application's logs.
Requires
- php: ^8.3
- datomatic/laravel-mcp-support: ^1.0
- illuminate/contracts: ^12.41.1|^13.0
- illuminate/support: ^12.41.1|^13.0
- laravel/mcp: ^1.0
- monolog/monolog: ^3.0
Requires (Dev)
- driftingly/rector-laravel: ^2.0
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- rector/rector: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel Log MCP
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/mcp1.0+- Channels writing to local files:
single,daily, ormonologwith aStreamHandler/RotatingFileHandler. Monolog's defaultLineFormatterand theJsonFormatterare 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:
describe_logs→ channels and files.summarize_logswithmin_level: errorandfrom: "-2 hours"→ most frequent errors.query_logs/get_log_entrywith thesample_id→ the full entry and stack trace.
Security model
- Authentication + authorization. The route uses the configured middleware
(
auth:sanctum) and theaccess-log-mcpgate (local-only fallback). - No arbitrary paths. Only files written by the channels in
config/logging.phpcan be read. Files are resolved withrealpathand must be regular files inside the channel's directory; afileoridargument is matched by exact name against that list. - Channel allow/deny lists (
allowed_channels,denied_channels,*wildcards). The audit log channel is always hidden. - 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, sosearchandregexcannot be used to guess a redacted value. - Bounded work. Files are read backwards in chunks, never loaded whole. Every call stops
at
max_bytes_scanned/max_scan_secondsand returns a cursor to continue. Results are capped (max_limit) and long messages, context and stack traces are truncated. - Regex opt-in.
regexis disabled by default (LOG_MCP_ALLOW_REGEX=trueto enable); patterns are length-capped and run with a low PCRE backtrack limit. - 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,papertrailand similar channels (Laravel Cloud and Vapor log tostderr) are listed but not readable. - Compressed (
.gz) rotated files are not read yet.
Testing
composer test
composer analyse
composer lint
License
MIT.