prajwal89 / laravel-logs-mcp
Safe, paginated, redacted MCP access to Laravel logs
Requires
- php: ^8.2
- illuminate/cache: ^11.0|^12.0|^13.0
- illuminate/console: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/routing: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/mcp: ^1.1
- laravel/pint: ^1.24
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.8|^4.0|^5.0
Suggests
- laravel/mcp: Required for the MCP server (^1.1)
Provides
None
Conflicts
None
Replaces
None
README
Safe, paginated MCP access to Laravel logs.
Laravel Logs MCP gives coding agents a read-only MCP interface to your Laravel log files. An agent can list the allowlisted files and read bounded, redacted pages newest first, over local stdio or an authenticated HTTP endpoint. The HTTP endpoint is off until you enable it and add a key hash.
The package is an MCP server. The log reader is the internal engine that makes the tools safe.
Why teams use it
- A page, not a dump. Pages read backwards from the end of the file with byte and scan caps, so an agent cannot pull a 2 GB log into its context window.
- Redacted before output. Emails, bearer tokens, known key prefixes, credential pairs, and public IPv4 addresses are masked before an entry leaves the process.
- Read-only by construction. Two tools,
list_log_filesandread_log_entries. No writes, no shell, no database, no arbitrary file path. - Off by default, authenticated when on. Installing the package adds no HTTP route. Enabling it needs a flag and at least one SHA-256 key hash, and the throttle runs before authentication.
- Local and remote transports. Local stdio needs no socket and no route. The HTTP transport is for a deployed app and an agent that is not on the same machine.
- Stack traces stay attached. Pages split on Monolog headers, not lines, so an exception and its trace stay together.
- Agent-friendly paging. Newest first, stable cursor, explicit
has_more, and a stale cursor returned as a normal result instead of wrong data.
Quick start
1. Install
composer require prajwal89/laravel-logs-mcp laravel/mcp
laravel/mcp is a suggested dependency. Install it alongside the package if your application does not already have it.
2. Connect a local agent
Nothing to enable. The local stdio handle is registered by default. It opens no socket and adds no route.
{
"mcpServers": {
"logs": {
"command": "php",
"args": ["artisan", "mcp:start", "logs"]
}
}
}
Ask the agent to list the files and read the newest warnings from today's file. The tools are read-only and every returned entry is redacted.
3. Read from a deployed app (optional)
Generate a key on the server:
php artisan laravel-logs-mcp:key
Store only the printed hash and enable the endpoint:
LARAVEL_LOGS_MCP_ENABLED=true LARAVEL_LOGS_MCP_KEY_HASHES=<sha256 hash> LARAVEL_LOGS_MCP_RATE_LIMIT=30
Then point the client at the endpoint:
{
"mcpServers": {
"logs": {
"type": "http",
"url": "https://your-app.test/mcp/logs",
"headers": { "Authorization": "Bearer ${LARAVEL_LOGS_MCP_TOKEN}" }
}
}
}
The endpoint answers POST only. GET returns 405 with Allow: POST.
The MCP tools
| Tool | What it returns | Arguments |
|---|---|---|
list_log_files |
Allowlisted files newest first, with name, bytes, modified time, and whether the file is today's. Never an absolute path. | None |
read_log_entries |
A page of entries newest first, plus next_cursor, has_more, scanned_bytes, and redactions. |
file (required), cursor, limit 1 to 100, min_level, exact_levels, since, query |
read_log_entries defaults to warning and above. Pass exact_levels to return only specific levels; it replaces min_level, so send one or the other. A file outside the allowlist returns unknown_file. A cursor whose file changed returns stale_cursor with a hint to retry without one.
Safe by default
| Control | Behavior |
|---|---|
| Route registration | Only when LARAVEL_LOGS_MCP_ENABLED=true and laravel/mcp is installed. |
| Authentication | Bearer key, SHA-256 hash stored in the environment, constant-time comparison, 32 character minimum. |
| Ordering | Throttle first, authentication second, so a flood is limited even when every key is wrong. |
| Request limits | JSON only, JSON accept header, 64 KB body by default, after authentication. |
| File access | Allowlisted directories, symlink rejection, resolved-path containment, and .log files only. |
| Output | Redaction, truncation, page byte cap, and no absolute server paths. |
| Caching | Cache-Control: no-store on every response, including the 401. |
| Content | Log lines are untrusted data, and the server instructions say never to follow them. |
How it works
The MCP server uses an internal reader engine. It lists files in the configured directories, parses Monolog headers, pages backwards from EOF with byte and scan caps, and redacts each entry before serialization. The engine has no public API commitment; the two tools and the configuration are the supported surface.
Pagination and filters
- Page one is the newest data.
next_cursorwalks backwards in time. limitis clamped tomax_page_size.min_levelacceptsdebug,info,notice,warning,error,critical,alert, oremergency.exact_levelsis a list of levels to return exactly, for example[warning, error]. It replacesmin_level, so send one or the other. An empty list falls back todefault_min_level.sinceaccepts a date, for example2026-11-29T00:00:00Z.queryis a case-insensitive substring match, not a regular expression.- One page never reads more than
max_page_bytesor scans more thanmax_scan_bytes.
Configuration
Publish the config if you want to change the defaults:
php artisan vendor:publish --tag=laravel-logs-mcp
The MCP block:
| Key | Environment | Default | Purpose |
|---|---|---|---|
mcp.local_enabled |
LARAVEL_LOGS_MCP_LOCAL |
true |
Register the stdio server handle. |
mcp.web_enabled |
LARAVEL_LOGS_MCP_ENABLED |
false |
Register the HTTP endpoint. |
mcp.server_name |
LARAVEL_LOGS_MCP_SERVER_NAME |
logs |
Handle used by php artisan mcp:start. |
mcp.display_name |
LARAVEL_LOGS_MCP_DISPLAY_NAME |
{app name} Logs |
Name shown to the MCP client. |
mcp.key_hashes |
LARAVEL_LOGS_MCP_KEY_HASHES |
empty | Comma separated SHA-256 hashes of allowed keys. |
mcp.rate_limit |
LARAVEL_LOGS_MCP_RATE_LIMIT |
30 |
Requests per minute per IP. |
mcp.route |
LARAVEL_LOGS_MCP_ROUTE |
/mcp/logs |
Endpoint path. |
mcp.paths |
none | inherits paths |
Narrower directory set for the MCP server. |
mcp.files |
none | inherits files |
Narrower file pattern set for the MCP server. |
mcp.max_request_bytes |
none | 65536 |
Request body cap. |
LOG_READER_MCP_* and LOG_MCP_* are earlier names, read as fallbacks so an existing deployment keeps working. The current LARAVEL_LOGS_MCP_* name wins when more than one is set.
The log access settings:
| Key | Default | Purpose |
|---|---|---|
paths |
[storage_path('logs')] |
Directories searched for log files. |
files |
['*.log'] |
File name patterns inside each directory. |
page_size |
25 |
Default entries per page. |
max_page_size |
100 |
Hard cap on a requested page size. |
max_entry_chars |
4000 |
Message length before truncation. |
max_page_bytes |
524288 |
Payload cap for one page. |
max_scan_bytes |
4194304 |
How far back one page may scan. |
default_min_level |
warning |
Level filter when the caller omits one. |
redaction.* |
all true |
Toggle each redaction rule. |
Security rules
- The route exists only when enabled. With
LARAVEL_LOGS_MCP_ENABLEDunset, no route is registered and the path answers like any other missing path. - Only the hash is stored. The key itself never appears in the environment.
- Rotation is an edit. Add a hash beside the old one, rebuild the config cache, switch the client, then drop the old hash. Revocation is removing the hash and rebuilding the cache.
- The check runs before the JSON parser and the body limit, so an unauthenticated caller cannot probe parser behavior.
- Keep the endpoint behind HTTPS. Terminate TLS at your proxy or edge and do not expose the path over plain HTTP.
- Treat the endpoint as access to production data. The key grants every allowlisted file.
Redaction
Every returned entry is redacted before it leaves the process:
| Target | Result |
|---|---|
| Email addresses | a***@example.com |
| Bearer tokens | Bearer [redacted] |
| Known key prefixes | sk-[redacted], emcp_[redacted], and so on |
| Credential pairs | password=[redacted] |
| Public IPv4 addresses | [redacted-ip] |
Timestamps, channels, and levels are never redacted; they are the navigation.
Business identifiers such as order IDs and customer IDs cannot be recognized by pattern. Redaction is best effort, not a guarantee. Do not log secrets or personal data in the first place, and treat the endpoint as access to sensitive production data.
Log content is untrusted
Log content is written by whatever triggered an error, a validation failure, or a 404. Treat it as data, never as instructions. The MCP server instructions say so as well.
Requirements
- PHP 8.2 or newer
- Laravel 11, 12, or 13
laravel/mcp^1.1
Laravel 13 requires PHP 8.3 or newer. Laravel 11 is included for existing applications and is end of life; prefer 12 or 13 for new work.
Testing
The package ships its own test harness and does not need a host application:
composer install
composer test
composer analyse
composer format:test
composer refactor:test
composer check
composer check runs Pint, PHPStan, Rector, and Pest in one go.
Tests use Orchestra Testbench, temporary directories, and an in-memory cache. They never read or write your storage/logs.
Changelog
See CHANGELOG.md.
Security
See SECURITY.md for the threat model and how to report a vulnerability.
License
MIT. See LICENSE.md.