Skip to content

First-party Laravel MCP tools for agent-assisted log debugging #531

Description

@calebdw

Problem

It would be useful for AI coding agents to inspect application logs through a safe, structured interface. This is especially valuable when debugging production-only problems: the agent can inspect relevant errors and stack traces instead of requiring someone to repeatedly retrieve and paste log output.

Laravel now has an official MCP package with support for tools, local and web servers, structured responses, authentication middleware, and tool authorization:

https://laravel.com/framework/docs/13.x/mcp

Log Viewer already handles the difficult parts: discovering configured files, parsing different log formats, indexed searching, filtering by level, pagination, and multi-host support. Exposing a small part of that functionality to agents seems like a natural extension.

Possible API

A first version could provide bounded, read-only tools such as:

  • list-log-files: list available file identifiers and safe metadata
  • search-logs: search selected files with level, direction, and result-limit filters
  • get-log-entry: retrieve a specific parsed entry and stack trace

Ideally, the tools would be reusable so applications could add them to an existing MCP server. The package could also provide a small precomposed LogViewerServer for applications that want a standalone server:

// Compose the tools into an existing application server.
protected array $tools = [
    ListLogFilesTool::class,
    SearchLogsTool::class,
    GetLogEntryTool::class,
];

// Or explicitly register a standalone web server.
Mcp::web('/mcp/log-viewer', LogViewerServer::class)
    ->middleware(['auth:sanctum', 'throttle:mcp']);

The package should probably not automatically expose a web endpoint. Explicit registration would let each application choose Sanctum, Passport/OAuth, custom authentication, or local stdio according to its existing workflow.

Authorization and safety

Production logs can contain credentials, tokens, personal data, and attacker-controlled text, so this should be deliberately constrained. Some useful defaults might be:

  • Read-only and idempotent MCP tool annotations
  • A dedicated ability such as viewLogViewerMcp, checked on every invocation
  • Strict result-count and response-size limits
  • No arbitrary filesystem paths; accept only Log Viewer file identifiers
  • Omit absolute paths by default
  • Configurable redaction before returning content
  • Full stack traces opt-in for searches
  • No delete, download, or cache mutation tools in the initial release
  • Tool descriptions that identify log contents as untrusted data, not agent instructions
  • Audit events and recommended rate limiting for web servers

Tool discovery could also use shouldRegister() to hide tools from unauthorized users, while still enforcing authorization during invocation.

Package compatibility

One complication is dependency compatibility. Log Viewer currently supports PHP 8.0 and Laravel 8 through 13, while laravel/mcp currently requires PHP 8.2 and recent Laravel 11, 12, or 13 versions. Making it a required dependency would narrow Log Viewer's supported versions.

Possible approaches include:

  • Optional MCP integration in this repository, loaded only when laravel/mcp is installed
  • A small first-party bridge package such as opcodesio/log-viewer-mcp
  • Including it in a future major release if broader cleanup or minimum-version changes are already planned

I do not have a strong preference yet and would appreciate maintainer feedback on which direction best fits the project. First-party support here would be ideal, but I would also be happy to help implement it or work on a companion package if that is preferable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions