Elasticsearch MCP server

Enables natural language interaction with Elasticsearch clusters for querying, indexing, and management operations via Docker-deployed infrastructure.
Back to servers
Provider
cr7258
Release date
Jan 09, 2025
Language
Python
Stats
126 stars

The Elasticsearch/OpenSearch MCP Server enables seamless interaction with Elasticsearch and OpenSearch databases through the Model Context Protocol. It provides tools for searching documents, analyzing indices, and managing clusters directly from AI assistants like Claude.

Features and Capabilities

General Operations

  • Perform general HTTP API requests for any Elasticsearch/OpenSearch API
  • Execute specialized operations for indices, documents, clusters, and aliases

Index Management

  • List all indices
  • Get index information (mappings, settings, aliases)
  • Create new indices
  • Delete existing indices

Document Operations

  • Search documents with complex queries
  • Create or update documents
  • Retrieve documents by ID
  • Delete documents individually or by query

Cluster and Alias Management

  • Monitor cluster health and statistics
  • List and manage aliases
  • Create, update, and delete aliases for specific indices

Installation

Prerequisites

  • Docker and Docker Compose installed
  • Node.js (for Smithery installation method)
  • Python with uv/uvx available

Starting Elasticsearch/OpenSearch

  1. Create an environment configuration file:

    cp .env.example .env
    
  2. Start the database using Docker Compose:

    # For Elasticsearch
    docker-compose -f docker-compose-elasticsearch.yml up -d
    
    # For OpenSearch
    docker-compose -f docker-compose-opensearch.yml up -d
    

    Default credentials:

    • Elasticsearch: username elastic, password test123
    • OpenSearch: username admin, password admin

    Access the dashboard at http://localhost:5601

Configuring with Claude Desktop

Method 1: Installing via Smithery

npx -y @smithery/cli install elasticsearch-mcp-server --client claude

Method 2: Using uvx

Add the following to your Claude Desktop configuration file:

// For Elasticsearch
{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uvx",
      "args": [
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_USERNAME": "elastic",
        "ELASTICSEARCH_PASSWORD": "test123"
      }
    }
  }
}

// For OpenSearch
{
  "mcpServers": {
    "opensearch-mcp-server": {
      "command": "uvx",
      "args": [
        "opensearch-mcp-server"
      ],
      "env": {
        "OPENSEARCH_HOSTS": "https://localhost:9200",
        "OPENSEARCH_USERNAME": "admin",
        "OPENSEARCH_PASSWORD": "admin"
      }
    }
  }
}

Method 3: Using uv with local source code

// For Elasticsearch
{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "path/to/src/elasticsearch_mcp_server",
        "run",
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_USERNAME": "elastic",
        "ELASTICSEARCH_PASSWORD": "test123"
      }
    }
  }
}

Configuration file locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json

Remember to restart Claude Desktop after configuration changes.

Using the MCP Server

Once configured, you can interact with Elasticsearch/OpenSearch using natural language commands in Claude:

  • "List all indices in the cluster"
  • "How old is the student Bob?" (to search for student data)
  • "Show me the cluster health status"
  • "Create a new index called customers with a field for email addresses"
  • "Search for documents containing the word 'error' in the logs index"

The MCP server translates these natural language requests into the appropriate Elasticsearch/OpenSearch API calls and returns the results.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later