Log MCP Server
A Model Context Protocol (MCP) server that enables AI assistants to intelligently inspect and analyze runtime log files for debugging and troubleshooting.
What is this?
This MCP server bridges the gap between your application logs and AI assistants like Claude. When you encounter errors or unexpected behavior in your code, the AI can automatically inspect your runtime logs to diagnose the problem - no more copying and pasting log files back and forth!
The workflow:
Your applications write logs to a configured directory (e.g.,
$XDG_RUNTIME_DIR/logor custom paths)This MCP server gives your AI assistant read access to those logs
When you report a problem, the AI proactively checks the logs to find the root cause
Get faster, more accurate debugging assistance based on actual runtime data
Use Cases
Development debugging: AI analyzes application logs when tests fail or errors occur
Service monitoring: Quickly diagnose issues with background services and daemons
Multi-project debugging: Monitor logs from multiple applications simultaneously
Learning & training: Understand what your code is doing at runtime by having AI explain the logs
Features
Multiple Directory Support: Monitor logs from multiple directories simultaneously
Automatic AI Guidance: When activated, the AI is informed about log inspection capabilities and will proactively check logs when users report errors
list_log_files: Lists all log files across all configured directories
get_log_content: Reads and returns the content of a specific log file
read_log_paginated: Read large files in chunks with line numbers
search_log_file: Regex search with context lines and pagination
runtime-logs prompt: Provides context to the AI about when and how to use log inspection
Installation
From source (development)
From PyPI (when published)
Usage
With Claude Desktop
Add to your Claude Desktop config (~/.config/claude/claude_desktop_config.json):
Default directory ($XDG_RUNTIME_DIR/log):
Single custom directory:
Multiple directories:
Using environment variable (colon-separated):
Or using uvx (recommended):
Standalone
Log Directory Priority
The server determines log directories in this order (highest priority first):
--log-dircommand-line arguments (can be specified multiple times)LOG_MCP_DIRenvironment variable (colon-separated paths, likePATH)$XDG_RUNTIME_DIR/log(default)
Multiple Directories
When multiple directories are configured:
list_log_filesscans all directories and returns all found filesOther tools accept either:
Just the filename (searches all directories for the file)
Full absolute path (must be within one of the allowed directories)
How It Works
When the MCP server connects to Claude, it automatically informs the AI that:
Runtime logs are available for inspection
These logs should be checked whenever users report errors or problems
The logs contain valuable diagnostic information for troubleshooting
The AI will proactively use the log inspection tools when appropriate.
Tools
list_log_files
Lists all log files found in $XDG_RUNTIME_DIR/log.
Parameters: None
Returns: List of full paths to all log files found
When to use: First step when investigating any error or problem
get_log_content
Reads and returns the complete content of a specific log file.
Parameters:
filename(string, required): Name of the log file to read
Returns: The full content of the specified log file
When to use: For small log files; for large files, use read_log_paginated instead
read_log_paginated
Reads a specific portion of a log file with pagination support.
Parameters:
filename(string, required): Name of the log file to readstart_line(integer, optional): Starting line number (1-based, default: 1)num_lines(integer, optional): Number of lines to read (default: 100, max: 1000)
Returns: Specified range of lines with line numbers
When to use: For large log files where you need to read specific sections
Example: Read lines 1000-1100 from a large log file
search_log_file
Searches a log file using regex patterns and returns matching lines with surrounding context.
Parameters:
filename(string, required): Name of the log file to searchpattern(string, required): Regex pattern to search forcontext_lines(integer, optional): Lines to show before/after each match (default: 2, max: 10)case_sensitive(boolean, optional): Case-sensitive search (default: false)max_matches(integer, optional): Maximum matches to return (default: 50, max: 500)skip_matches(integer, optional): Number of matches to skip for pagination (default: 0)
Returns: Matching lines with context, marked with >>> for the match line
When to use: Searching for specific errors, patterns, or events in log files
Example: Search for all "ERROR" entries with 3 lines of context
Prompts
runtime-logs
A prompt that explains to the AI how and when to use log inspection capabilities. This is automatically available when the server connects.
Example Workflow
Configure your application to log to
$XDG_RUNTIME_DIR/log/myapp.logAdd log-mcp to Claude Desktop config
Run your application - it writes logs as it runs
Ask Claude for help: "My application is crashing when I click the submit button"
Claude automatically:
Calls
list_log_filesto see available logsCalls
search_log_fileto find error messagesAnalyzes the error context
Provides a solution based on the actual error
No more manual log copy-pasting! The AI has direct, intelligent access to your runtime diagnostics.
Configuring Your Applications to Log
For the AI to help debug your applications, they need to write logs to a directory the MCP server monitors. Here are common configuration patterns:
Default Location: $XDG_RUNTIME_DIR/log
On most Linux systems, $XDG_RUNTIME_DIR is /run/user/<UID> (e.g., /run/user/1000). Create the log directory:
Application-Specific Configuration
Node.js / JavaScript
Using Winston:
Using Pino:
Python
Using logging module:
Java / Spring Boot
application.properties:
Rust
Using
Go
IDE Configuration
VSCode (for tasks/debugging)
Create .vscode/tasks.json:
IntelliJ IDEA / PyCharm
Edit Run Configuration
Add VM options or Environment Variables:
Set log file path to
$XDG_RUNTIME_DIR/log/myapp.log
Or modify logging configuration file (logback.xml, log4j.properties, etc.)
Multiple Log Directories
You can monitor logs from different locations simultaneously:
Or use the environment variable:
Requirements
Python 3.10+
MCP SDK
$XDG_RUNTIME_DIRenvironment variable (or specify custom directories)