mcp-server-elasticsearch-ai

byviz/mcp-server-elasticsearch-ai

3.3

If you are the rightful owner of mcp-server-elasticsearch-ai and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The Elasticsearch MCP Server is a Model Context Protocol server that allows AI assistants to interact with Elasticsearch clusters using natural language, providing advanced APM and metrics support.

Tools
3
Resources
0
Prompts
0

๐Ÿ” Elasticsearch MCP Server AI

A Model Context Protocol (MCP) server that transforms your Elasticsearch cluster into an AI-powered observability engine.
Enables natural language interaction for analyzing logs, APM traces (with waterfall and RCA), and system metrics โ€” delivering deep performance and troubleshooting insights with minimal effort.

๐Ÿ’ก Demo Examples Elasticsearch MCP Server AI

  • Demo APM Waterfall Trace Performance Analysis, how to analyze application traces using waterfall visualization for in-depth performance insights. Quickly identify bottlenecks, latency issues, and service dependencies in real APM data.

  • Demo RCA APM (Root Cause Analysis), Demonstrates how to automatically identify the underlying causes of errors and performance issues in APM traces, providing actionable insights for rapid troubleshooting.

  • Demo Perform performance analysis by APM service, Analyze and compare the performance metrics for each APM service, identifying latency, throughput, and resource bottlenecks across your architecture.

๐ŸŽฏ Core Value: Advanced APM Analysis

This MCP server transforms your Elasticsearch cluster into a powerful AI-driven APM analysis platform. The key differentiator is our specialized APM analysis tools that provide automated insights impossible with basic Elasticsearch queries:

๐Ÿ”ฌ APM Waterfall Analysis - analyzeTracePerformance

  • Complete waterfall analysis of APM traces with visual timeline reconstruction
  • Automatic correlation with system errors and infrastructure metrics
  • Performance optimization recommendations based on detected patterns
  • Deep bottleneck detection across microservices and dependencies
  • Perfect for: Latency debugging, performance optimization, dependency analysis

๐ŸŽฏ APM Root Cause Analysis (RCA) - findErrorPatterns

  • Temporal error analysis with automatic aggregations and pattern detection
  • Intelligent Root Cause Analysis with specific, actionable recommendations
  • Anomaly detection in error frequency, types, and service impact
  • Automated correlation between error spikes and system events
  • Perfect for: Proactive troubleshooting, stability analysis, incident prevention

๐Ÿ”— Business Event Correlation - correlateBusinessEvents

  • Complete user journey reconstruction across all system touchpoints
  • Cross-index correlation (APM + logs + metrics + business events)
  • Timeline analysis of related events with business impact assessment
  • End-to-end transaction tracking from user action to system response
  • Perfect for: Business impact analysis, critical flow debugging, customer experience optimization

๐Ÿ’ก These tools implement specialized logic that's impossible with basic Elasticsearch queries, providing deep insights and automated analysis for SRE and DevOps teams. They represent the core value proposition of this MCP server.

๐ŸŽฏ What is this MCP Server?

This MCP server converts your Elasticsearch cluster into a powerful tool for AI assistants, enabling:

  • ๐Ÿ” Intelligent searches in logs, metrics, and documents
  • ๐Ÿ“Š APM analysis to detect errors and performance issues
  • ๐Ÿ–ฅ๏ธ System monitoring with CPU, memory, and disk metrics
  • ๐Ÿ”ง Automatic diagnosis of application problems

๐Ÿ› ๏ธ Available Tools (25 Tools)

๐Ÿ”ง Optimized APM Tools โญ CORE VALUE

ToolDescriptionMain Parameters
analyzeTracePerformanceComplete performance analysis with waterfall and correlationstrace_id (required), include_errors, include_metrics
findErrorPatternsError pattern detection with temporal analysis and RCAtime_range, service_name, error_type, min_frequency
correlateBusinessEventsBusiness event correlation to reconstruct user journeyscorrelation_id (required), time_window, include_user_journey

๐Ÿ” Search and Queries

ToolDescriptionMain Parameters
searchAllIndicesSearch documents across all indices with query stringq (query), size (limit), from (offset), sort (ordering)
searchDocumentsSearch documents in specific indicesindex (index), q (query), size, from, sort
countDocumentsCount documents globally with optional filtersq (query), index (specific indices)
countDocumentsInIndexCount documents in a specific indexindex (required), q (optional query)
getDocumentGet a specific document by its IDindex (required), id (required), _source (fields)

๐Ÿ“Š Cluster Information

ToolDescriptionMain Parameters
getClusterInfoBasic cluster information (name, version, UUID)None
getClusterHealthCluster health status with detailed metricslevel (cluster/indices/shards), wait_for_status, timeout
getClusterStatsComplete cluster statistics for monitoringNone
getNodeStatsStatistics of all nodes (CPU, memory, disk)metric (indices/os/process/jvm/etc.)
getHotThreadsActive threads and JVM statistics for troubleshootingmetric (JVM metrics type)

๐Ÿ—‚๏ธ Index Management

ToolDescriptionMain Parameters
getCatIndicesCompact list of indices with status informationformat (json/yaml/text), v (verbose), h (columns), s (sort)
getIndexDetailed information of a specific indexindex (required)
getMappingField mapping and data types of an indexindex (required)
getSettingsConfiguration and settings of an indexindex (required)

๐Ÿšจ APM and Monitoring

ToolDescriptionMain Parameters
searchAPMDataSearch traces, transactions, and spans in APM dataq (query), size, from, sort, _source, timeout
countAPMDocumentsCount documents in APM indices (errors, traces, metrics)q (filter query)
searchAPMErrorsSearch errors and exceptions specifically in APMq (temporal query), size, from, sort, _source, timeout
searchAPMPerformanceAnalyze performance metrics and slow transactionsq (query), size, from, sort, _source, timeout
searchSystemMetricsSystem metrics (CPU, memory, disk) from Metricbeatq (temporal query), size, from, sort, _source, timeout
searchLogDataSearch application logs from Filebeat and other sourcesq (query), size, from, sort, _source, timeout
searchFilebeatLogsSearch logs specifically from Filebeat indicesq (advanced query), size, from, sort, _source, timeout
searchWatcherAlertsElasticsearch Watcher alert historyq (temporal query), size, from, sort, _source, timeout

๐Ÿ“ Common Parameters

๐Ÿ” Search Parameters

  • q (query): Elasticsearch query string (e.g., "error AND @timestamp:>now-1h")
  • size: Number of results (default: 10, recommended max: 100)
  • from: Offset for pagination (default: 0)
  • sort: Sorting (e.g., "@timestamp:desc", "_score:desc")
  • _source: Specific fields to include (e.g., "@timestamp,message,service.name")
  • timeout: Search timeout (default: "30s")

๐Ÿ“Š Temporal Parameters

  • time_range: Time range (e.g., "now-1h", "now-24h", "now-7d")
  • time_window: Time window (e.g., "30m", "1h", "5m")
  • @timestamp: Temporal filter in query (e.g., "@timestamp:>now-2h")

๐Ÿท๏ธ Filtering Parameters

  • index: Specific index or pattern (e.g., "logs-2024", "logs-apm.error-*")
  • service_name: APM service name (e.g., "api-users", "servicio-local")
  • error_type: Error type (e.g., "ConnectionError", "TimeoutError")
  • level: Detail level (e.g., "cluster", "indices", "shards")

๐Ÿ”ง Format Parameters

  • format: Output format (e.g., "json", "yaml", "text")
  • v: Verbose output with headers (true/false)
  • h: Specific columns to display (e.g., "index,health,status")
  • s: Columns to sort by (e.g., "index:desc")

๐Ÿš€ Installation

๐Ÿ“ฆ From Source Code (Recommended)

Option 1: Simple Installation (Recommended for users)
# Clone repository
git clone https://github.com/byviz/mcp-server-elasticsearch-ai.git
cd elasticsearch-mcp

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install ALL dependencies (production + development)
pip install -r requirements-all.txt

# Install package in development mode
pip install -e .
Option 2: Minimal Installation (Run only)
# If you only want to run the server (no development)
pip install -r requirements.txt
pip install -e .
Option 3: Using pyproject.toml (Advanced)
# Clone repository
git clone https://github.com/byviz/elasticsearch-mcp-ai.git
cd elasticsearch-mcp

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install directly from pyproject.toml
pip install -e .

๐Ÿ“‹ Dependencies Files Summary

FileDescriptionWhen to use
requirements-all.txtAll dependencies (production + development)โœ… Recommended for most users
requirements.txtOnly minimal dependencies to runOnly if you want very lightweight installation
requirements-dev.txtOnly development dependenciesFor contributors who already have basics
pyproject.tomlModern Python configurationFor advanced users with modern tools

๐Ÿ“‹ Verify Installation

# Verify package was installed correctly
python -c "import elasticsearch_mcp; print('โœ… Installation successful')"

# Check version
python -m elasticsearch_mcp --version

โš™๏ธ Configuration

๐Ÿ“‹ Required Environment Variables

Elasticsearch
# Cluster connection
ELASTICSEARCH_URL="https://your-cluster.es.io:9243"

# Authentication (choose one option)
ELASTICSEARCH_USERNAME="your-username"
ELASTICSEARCH_PASSWORD="your-password"
# Or alternatively:
# ELASTICSEARCH_API_KEY="your-api-key"

๐Ÿ”ง Optional Variables

Advanced Elasticsearch
ELASTICSEARCH_TIMEOUT=30                     # Timeout in seconds
ELASTICSEARCH_VERIFY_CERTS=true              # Verify SSL certificates
ELASTICSEARCH_CA_CERTS="/path/to/ca.crt"     # CA certificates
ELASTICSEARCH_CLIENT_CERT="/path/to/client.crt"  # Client certificate
ELASTICSEARCH_CLIENT_KEY="/path/to/client.key"   # Private key
MCP Server
MCP_TRANSPORT=stdio                          # Transport (stdio/http/sse)
MCP_PORT=8000                               # Port for HTTP/SSE
MCP_LOG_LEVEL=INFO                          # Logging level
MCP_ENABLE_SECURITY_FILTERING=true          # Security filtering

๐Ÿš€ Usage

๐Ÿ“ Quick Configuration

  1. Create configuration file:
cp config.env.example .env
  1. Edit variables:
# Elasticsearch
ELASTICSEARCH_URL=https://your-cluster.es.io:9243
ELASTICSEARCH_USERNAME=your-username
ELASTICSEARCH_PASSWORD=your-password
  1. Run the server:
source .env
python -m elasticsearch_mcp

๐ŸŽฏ Integration with Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/claude/claude_desktop_config.json
{
  "mcpServers": {
    "elasticsearch": {
      "command": "python",
      "args": ["-m", "elasticsearch_mcp"],
      "env": {
        "ELASTICSEARCH_URL": "https://your-cluster.es.io:9243",
        "ELASTICSEARCH_USERNAME": "your-username",
        "ELASTICSEARCH_PASSWORD": "your-password"
      }
    }
  }
}

๐Ÿ”’ Security

By default, the server runs with security filtering enabled (MCP_ENABLE_SECURITY_FILTERING=true), which restricts operations to read-only.

โœ… Allowed Operations

  • Searches and queries (GET, POST for searches)
  • Reading mappings, configurations, and statistics
  • APM analysis and metrics
  • Cluster and node information
  • Data visualization

โŒ Blocked Operations

  • Creating, modifying, or deleting indices
  • Indexing, updating, or deleting documents
  • Modifying cluster configurations
  • Any destructive operations

๐Ÿ“Š Usage Examples

๐Ÿ” Basic Search

"Search for documents containing 'error' in the last 30 minutes"
โ†’ Use searchAllIndices with q="error AND @timestamp:>now-30m"

"Count how many documents are in the 'logs-2024' index"
โ†’ Use countDocumentsInIndex with index="logs-2024"

๐Ÿ“Š Cluster Monitoring

"Is the cluster working well?"
โ†’ Use getClusterHealth to check status (green/yellow/red)

"How many nodes does the cluster have and how much memory do they use?"
โ†’ Use getNodeStats with metric="os,jvm" for detailed metrics

"Show basic cluster information"
โ†’ Use getClusterInfo for name, version, and UUID

๐Ÿ—‚๏ธ Index Management

"List all indices with their health status"
โ†’ Use getCatIndices with format="json" and v=true

"What fields does the 'products' index have?"
โ†’ Use getMapping with index="products" to see structure

"What is the configuration of the 'logs-app' index?"
โ†’ Use getSettings with index="logs-app"

๐Ÿšจ APM and Troubleshooting

"Search for errors in the 'api-users' service from the last 2 hours"
โ†’ Use searchAPMErrors with q="service.name:api-users AND @timestamp:>now-2h"

"What are the slowest transactions?"
โ†’ Use searchAPMPerformance with sort="transaction.duration.us:desc"

"Analyze trace ID '430dbab7a0e0322274f076569cdc0c3d'"
โ†’ Use analyzeTracePerformance with trace_id="430dbab7a0e0322274f076569cdc0c3d"

"Find ConnectionError patterns"
โ†’ Use findErrorPatterns with error_type="ConnectionError"

๐Ÿ–ฅ๏ธ System Metrics

"Show CPU usage from the last 5 minutes"
โ†’ Use searchSystemMetrics with q="metricset.name:cpu AND @timestamp:>now-5m"

"Search for ERROR level logs"
โ†’ Use searchLogData with q="log.level:ERROR"

"Check Watcher alerts from the last 24 hours"
โ†’ Use searchWatcherAlerts with q="@timestamp:>now-24h"

๐Ÿ”ง Advanced Analysis


"Find error patterns in servicio-local"
โ†’ Use findErrorPatterns with service_name="servicio-local" and time_range="now-1h"

๐Ÿ›ก๏ธ Troubleshooting

โŒ Connection Error

ERROR - Connection failed

Solution: Verify ELASTICSEARCH_URL and credentials

โŒ Authentication Error

ERROR - Authentication failed

Solution: Verify ELASTICSEARCH_USERNAME/PASSWORD or ELASTICSEARCH_API_KEY

โŒ Certificate Error

ERROR - SSL verification failed

Solution: Configure ELASTICSEARCH_VERIFY_CERTS=false or provide certificates

๐Ÿ“„ License

Apache 2.0 - see LICENSE file for details

๐Ÿค Contributions

Contributions are welcome! Please:

  1. Fork the project
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

๐Ÿ“ž Support

Need help, have questions, or want to suggest new features?
Join our growing community! Open an issue or contact us โ€” we're here to help you get the most out of AI-powered Elasticsearch.

Ivรกn Frรญas Molina
Elastic & Byviz

- ๐Ÿ“ง ivan.frias@elastic.co
- ๐Ÿ“ง ivan.frias@byviz.com