Elasticsearch MCP Server

Elasticsearch MCP servers enable AI models to interact with Elasticsearch, providing capabilities for searching documents, analyzing indices, and managing clusters.

May 10, 2025
MCP ServerDatabases & StorageElasticsearch MCP Server
GitHub starsnpm versionnpm downloads

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

ToolPurposeCategory
general_api_requestPerform general HTTP API requestsGeneral
list_indicesList all available indicesIndex
get_indexGet information about indicesIndex
create_indexCreate a new indexIndex
delete_indexDelete an indexIndex
create_data_streamCreate a new data streamData Stream
get_data_streamGet information about data streamsData Stream
delete_data_streamDelete data streamsData Stream
search_documentsSearch for documentsDocument
index_documentCreate or update a documentDocument
get_documentGet a document by IDDocument
delete_documentDelete a document by IDDocument
delete_by_queryDelete documents by queryDocument
get_cluster_healthGet cluster health informationCluster
get_cluster_statsGet cluster statisticsCluster
list_aliasesList all aliasesAlias
get_aliasGet alias informationAlias
put_aliasCreate or update an aliasAlias
delete_aliasDelete an aliasAlias

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

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_USERNAME and ELASTICSEARCH_PASSWORD for basic auth.
    • ELASTICSEARCH_API_KEY for API key authentication.
  • SSL Verification: ELASTICSEARCH_VERIFY_CERTS (default: false)

Sources