Elasticsearch MCP Server
Elasticsearch MCP servers enable AI models to interact with Elasticsearch, providing capabilities for searching documents, analyzing indices, and managing clusters.
Overview
The Elasticsearch MCP Server provides a robust bridge for AI models to interact with Elasticsearch and OpenSearch. It enables searching documents, analyzing indices, and managing clusters through a standardized set of tools, making it a crucial component for AI-driven data exploration and management.
Created by:
Developed by cr7258
Key Features
Document Search & Management
Search, index, get, and delete documents within Elasticsearch indices
Index & Cluster Operations
Manage indices (create, delete, get mappings) and monitor cluster health
Alias Management
Create, update, and delete index aliases for flexible data routing
Security & Control
Option to disable high-risk write operations for enhanced safety
Available Tools
Quick Reference
| Tool | Purpose | Category |
|---|---|---|
general_api_request | Perform general HTTP API requests | General |
list_indices | List all available indices | Index |
get_index | Get information about indices | Index |
create_index | Create a new index | Index |
delete_index | Delete an index | Index |
create_data_stream | Create a new data stream | Data Stream |
get_data_stream | Get information about data streams | Data Stream |
delete_data_stream | Delete data streams | Data Stream |
search_documents | Search for documents | Document |
index_document | Create or update a document | Document |
get_document | Get a document by ID | Document |
delete_document | Delete a document by ID | Document |
delete_by_query | Delete documents by query | Document |
get_cluster_health | Get cluster health information | Cluster |
get_cluster_stats | Get cluster statistics | Cluster |
list_aliases | List all aliases | Alias |
get_alias | Get alias information | Alias |
put_alias | Create or update an alias | Alias |
delete_alias | Delete an alias | Alias |
Detailed Usage
search_documents▶
Search for documents within specified indices using a query DSL.
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "search_documents",
arguments: {
index: "my_index",
query: {
match: {
message: "hello world"
}
}
}
});
Returns matching documents and their metadata.
index_document▶
Creates or updates a document in the specified index.
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "index_document",
arguments: {
index: "my_index",
id: "1",
document: {
user: "John Doe",
message: "Hello from MCP"
}
}
});
If ID is provided, updates existing document; otherwise, creates a new one.
get_cluster_health▶
Returns basic information about the health of the Elasticsearch cluster.
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "get_cluster_health",
arguments: {}
});
Provides status (green, yellow, red), node count, and shard information.
list_indices▶
List all available Elasticsearch indices.
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "list_indices",
arguments: {}
});
Returns a list of all indices in the cluster.
Installation
{
"mcpServers": {
"elasticsearch": {
"command": "uvx",
"args": [
"elasticsearch-mcp-server"
],
"env": {
"ELASTICSEARCH_HOSTS": "https://localhost:9200",
"ELASTICSEARCH_USERNAME": "elastic",
"ELASTICSEARCH_PASSWORD": "your_password"
}
}
}
}
API Key Authentication:
Alternatively, use ELASTICSEARCH_API_KEY for authentication:
{
"mcpServers": {
"elasticsearch": {
"command": "uvx",
"args": [
"elasticsearch-mcp-server"
],
"env": {
"ELASTICSEARCH_HOSTS": "https://localhost:9200",
"ELASTICSEARCH_API_KEY": "YOUR_ELASTICSEARCH_API_KEY"
}
}
}
}
Common Use Cases
1. Document Search
Search for specific documents based on keywords or complex queries:
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "search_documents",
arguments: {
index: "products",
query: {
bool: {
must: { match: { name: "laptop" } },
filter: { range: { price: { gte: 500, lte: 1500 } } }
}
}
}
});
2. Indexing New Data
Add new data to an Elasticsearch index:
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "index_document",
arguments: {
index: "logs",
document: {
timestamp: new Date().toISOString(),
level: "info",
message: "User logged in successfully"
}
}
});
3. Monitoring Cluster Health
Periodically check the health of the Elasticsearch cluster:
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "get_cluster_health",
arguments: {}
});
4. Managing Index Aliases
Create an alias for an index to simplify queries or manage reindexing:
use_mcp_tool({
server_name: "elasticsearch",
tool_name: "put_alias",
arguments: {
index: "products_v1",
name: "current_products"
}
});
Connection String Format
The Elasticsearch MCP server primarily uses environment variables for connection details, but the underlying Elasticsearch client supports various connection methods.
- Host:
ELASTICSEARCH_HOSTS(e.g.,https://localhost:9200) - Authentication:
ELASTICSEARCH_USERNAMEandELASTICSEARCH_PASSWORDfor basic auth.ELASTICSEARCH_API_KEYfor API key authentication.
- SSL Verification:
ELASTICSEARCH_VERIFY_CERTS(default:false)
Sources
Related Articles
Google Search MCP Server
An advanced Model Context Protocol (MCP) server that provides comprehensive Google search capabilities, webpage content extraction, and AI-powered research synthesis.
S3 MCP Server
S3 MCP servers enable AI models to interact with Amazon S3 object storage, providing capabilities for file operations, metadata management, and versioning in a secure and scalable environment.
Pinecone MCP Server
Integrate Pinecone with your AI assistants using the Model Context Protocol (MCP) for enhanced vector database interactions.