Elasticsearch MCP server

Enables natural language interaction with Elasticsearch clusters for listing indices, inspecting field mappings, and executing Query DSL searches with automatic text highlighting
Back to servers
Provider
Elastic
Release date
Dec 17, 2024
Language
TypeScript
Package
Stats
1.9K downloads
131 stars

Elasticsearch MCP Server allows you to interact with your Elasticsearch data through natural language conversations using the Model Context Protocol (MCP). This server connects MCP clients like Claude Desktop to your Elasticsearch indices, enabling you to query your data using everyday language.

Available Tools

  • list_indices: List all available Elasticsearch indices
  • get_mappings: Get field mappings for a specific Elasticsearch index
  • search: Perform an Elasticsearch search with the provided query DSL
  • get_shards: Get shard information for all or specific indices

Prerequisites

  • An Elasticsearch instance
  • Elasticsearch authentication credentials (API key or username/password)
  • MCP Client (e.g. Claude Desktop)

Installation & Setup

Using the Published NPM Package

  1. Configure MCP Client

    • Open your MCP Client (e.g., Claude Desktop)
    • Go to Settings > Developer > MCP Servers
    • Click Edit Config and add a new MCP Server with the following configuration:
    {
      "mcpServers": {
        "elasticsearch-mcp-server": {
          "command": "npx",
          "args": [
            "-y",
            "@elastic/mcp-server-elasticsearch"
          ],
          "env": {
            "ES_URL": "your-elasticsearch-url",
            "ES_API_KEY": "your-api-key"
          }
        }
      }
    }
    
  2. Start a Conversation

    • Open a new conversation in your MCP Client
    • The MCP server should connect automatically
    • You can now ask questions about your Elasticsearch data

Configuration Options

The Elasticsearch MCP Server supports the following configuration options:

Environment Variable Description Required
ES_URL Your Elasticsearch instance URL Yes
ES_API_KEY Elasticsearch API key for authentication No
ES_USERNAME Elasticsearch username for basic authentication No
ES_PASSWORD Elasticsearch password for basic authentication No
ES_CA_CERT Path to custom CA certificate for Elasticsearch SSL/TLS No

Note: You must provide either an API key or both username and password for authentication.

Usage Examples

Example Questions

Here are some natural language queries you can try with your MCP Client:

  • "What indices do I have in my Elasticsearch cluster?"
  • "Show me the field mappings for the 'products' index."
  • "Find all orders over $500 from last month."
  • "Which products received the most 5-star reviews?"

Security Best Practices

It's recommended to create a dedicated Elasticsearch API key with minimal permissions to control access to your data:

POST /_security/api_key
{
  "name": "es-mcp-server-access",
  "role_descriptors": {
    "mcp_server_role": {
      "cluster": [
        "monitor"
      ],
      "indices": [
        {
          "names": [
            "index-1",
            "index-2",
            "index-pattern-*"
          ],
          "privileges": [
            "read",
            "view_index_metadata"
          ]
        }
      ]
    }
  }
}

Troubleshooting

If you encounter issues:

  • Ensure your MCP configuration is correct
  • Verify that your Elasticsearch URL is accessible from your machine
  • Check that your authentication credentials have the necessary permissions
  • If using SSL/TLS with a custom CA, verify that the certificate path is correct
  • Look at the terminal output for error messages

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