An MCP (Model Context Protocol) server that enables AI assistants to query and analyze logs from Betterstack. Supports querying across multiple sources and source groups with intelligent source selection.
- Multi-source querying: Query individual sources or source groups
- Source management: Discover and inspect available sources and groups
- Query tools: Execute custom ClickHouse SQL or use simplified search interfaces
- Historical data: Access both recent and archived logs
- Metrics support: Query performance metrics alongside logs
- AI-friendly: Intelligent source selection based on query context
- Clone this repository
- Install dependencies:
npm install
- Build the project:
npm run build
- Configure environment variables (see Configuration section)
Betterstack requires two different authentication methods:
Copy .env.example
to .env
and configure:
# ClickHouse Database Credentials (for log queries)
BETTERSTACK_CLICKHOUSE_USERNAME=your_clickhouse_username
BETTERSTACK_CLICKHOUSE_PASSWORD=your_clickhouse_password
BETTERSTACK_CLICKHOUSE_QUERY_ENDPOINT=your_clickhouse_endpoint_url
# API Token (for source management)
BETTERSTACK_API_TOKEN=your_api_token_from_betterstack_dashboard
# Optional
BETTERSTACK_DEFAULT_SOURCE_GROUP=production
Getting Your Credentials:
-
ClickHouse Credentials (for log queries):
- In Betterstack dashboard: Dashboards → Connect remotely → Create connection
- Save the generated username, password, and endpoint URL
-
API Token (for source management):
- Go to Betterstack API Tokens
- Select your team
- Create or copy an existing Telemetry API token
Add to your claude_desktop_config.json
:
{
"mcpServers": {
"betterstack-logs": {
"command": "node",
"args": ["path/to/betterstack-logs-mcp/dist/index.js"],
"env": {
"BETTERSTACK_CLICKHOUSE_USERNAME": "your_clickhouse_username",
"BETTERSTACK_CLICKHOUSE_PASSWORD": "your_clickhouse_password",
"BETTERSTACK_CLICKHOUSE_QUERY_ENDPOINT": "your_clickhouse_endpoint_url",
"BETTERSTACK_API_TOKEN": "your_api_token_here",
"BETTERSTACK_DEFAULT_SOURCE_GROUP": "production"
}
}
}
}
list_sources
: Get all available log sourceslist_source_groups
: Get configured source groupsget_source_info
: Get details about a specific sourceget_source_group_info
: Get details about a source group
query_logs
: Execute custom ClickHouse SQL queriessearch_logs
: Simple text search across logsget_recent_logs
: Fetch recent logs with filtersget_historical_logs
: Query archived logsquery_metrics
: Access performance metrics
analyze_errors
: Find and analyze error patternsexport_logs
: Export logs in JSON/CSV formats
# List available sources
AI: What sources do we have?
# Search recent errors in production
AI: Show me recent errors from the production environment
# Query specific source
AI: Show me website logs from the last hour
# Get source group details
AI: What's included in our production source group?
npm run dev # Watch mode
npm run build # Build for production
MIT