rutvikraut2001/mcp-log-search
If you are the rightful owner of mcp-log-search and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Model Context Protocol (MCP) server designed for searching and analyzing WhatsApp connector platform logs using natural language queries.
Log Search MCP Server
A Model Context Protocol (MCP) server for searching and analyzing microservice logs using natural language queries. Built with NestJS and designed to work with Claude Code and other MCP clients.
Features
- Natural Language Search: Query logs using plain English
- Multi-Service Support: Search across multiple microservices
- Request Journey Tracking: Trace requests across all services using request IDs
- Hourly Statistics: Performance analysis and peak time identification
- Status Aggregation: Count and analyze log entries by status
- Streaming Processing: Efficient handling of large gzipped log files
- Caching: 5-minute TTL caching for improved performance
System Architecture
This server is designed for microservices architectures. Default services include:
- api-gateway: Entry point for all API requests
- auth-service: Authentication and authorization
- user-service: User management and profiles
- notification-service: Email, SMS, and push notifications
You can customize the service list via the SERVICES environment variable.
Prerequisites
- Node.js >= 18.x
- npm or yarn
- Log files in gzipped JSON format (NDJSON)
Installation
# Clone the repository
git clone <repository-url>
cd log-search-mcp-server
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env and set LOG_DIRECTORY to your logs location
# Build the project
npm run build
Configuration
Environment Variables
Create a .env file:
LOG_DIRECTORY=/path/to/your/logs
SERVICES=api-gateway,auth-service,user-service,notification-service
CACHE_TTL=300
DEFAULT_SEARCH_LIMIT=100
Log File Structure
Logs should be organized as:
{LOG_DIRECTORY}/
├── api-gateway/
│ └── 2025-10-30.gz
├── auth-service/
│ └── 2025-10-30.gz
├── user-service/
│ └── 2025-10-30.gz
└── notification-service/
└── 2025-10-30.gz
Each log file should contain newline-delimited JSON (NDJSON):
{"level":"INFO","message":"Request processed","timestamp":"2025-10-30T10:30:00Z","requestId":"req-123","service":"api-gateway"}
Usage with Claude Code CLI
Global Installation
# Add MCP server globally
claude mcp add --scope user --transport stdio log-search \
--env LOG_DIRECTORY=/path/to/logs \
-- node /path/to/dist/src/main.js
# Verify installation
claude mcp list
Example Queries
✅ "show errors in api-gateway on 2025-10-30"
✅ "find logs with user-12345"
✅ "how many requests failed today"
✅ "track request req-abc-123"
✅ "authentication errors in auth-service"
✅ "hourly stats for api-gateway"
MCP Tools
The server exposes 4 MCP tools:
1. search_logs
Search logs with natural language queries.
Parameters:
query(required): Natural language search querystartDate(optional): Start date (YYYY-MM-DD)endDate(optional): End date (YYYY-MM-DD)service(optional): Service nameidentifier(optional): Filter by identifier (user ID, transaction ID, etc.)logLevel(optional): INFO, ERROR, WARN, DEBUGsource(optional): Source system namelimit(optional): Max results (default: 10, max: 100)
2. get_log_summary
Get statistical summary of logs.
Parameters:
startDate(required): Start dateendDate(required): End dateservice(required): Service name
3. track_request_journey
Track a request across all services.
Parameters:
requestId(required): Request ID to trackstartDate(optional): Start date
4. get_hourly_stats
Get hourly breakdown of log statistics.
Parameters:
date(required): Date (YYYY-MM-DD)service(required): Service name
Development
# Run tests
npm test
# Run tests with coverage
npm test -- --coverage
# Run tests in watch mode
npm test -- --watch
# Build with watch mode
npm run build -- --watch
Testing
Generate Test Logs
./scripts/setup-test-logs.sh
This creates a test-logs/ directory with sample gzipped JSON logs for testing.
Customization
Adding Custom Services
-
Set the
SERVICESenvironment variable:SERVICES=order-service,payment-service,inventory-service -
Create corresponding directories in your LOG_DIRECTORY
-
The server will automatically detect and search these services
Log Format Requirements
- Required fields:
level,message - Optional but recommended:
timestamp(or@timestamp),requestId,service - Format: Newline-delimited JSON (NDJSON), gzipped
Performance
- Streaming: Line-by-line processing (no full-file loading)
- Caching: 5-minute TTL on search results
- Early Termination: Stops when limit is reached
- Default Limits: 500k lines max to prevent timeouts
Troubleshooting
"No MCP servers configured"
Run from within the project directory or add with --scope user flag.
"LOG_DIRECTORY not found"
Ensure the path in .env is absolute and readable.
"Service type is required"
Either specify service in the query or use keywords like "gateway", "auth", etc.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
npm test - Submit a pull request
License
ISC
Author
Rutvik Raut