Home / MCP / Elasticsearch MCP Server

Elasticsearch MCP Server

Provides Elasticsearch/OpenSearch MCP endpoints for indexing, searching, and managing clusters.

python
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "mcpServers": {
        "elasticsearch": {
            "command": "uvx",
            "args": [
                "elasticsearch-mcp-server"
            ],
            "env": {
                "ELASTICSEARCH_HOSTS": "https://localhost:9200",
                "ELASTICSEARCH_USERNAME": "elastic",
                "ELASTICSEARCH_PASSWORD": "test123",
                "ELASTICSEARCH_API_KEY": "YOUR_API_KEY",
                "OPENSEARCH_HOSTS": "https://localhost:9200",
                "OPENSEARCH_USERNAME": "admin",
                "OPENSEARCH_PASSWORD": "admin"
            }
        }
    }
}

You can run an MCP server that exposes Elasticsearch/OpenSearch functionality to clients. It lets you search documents, manage indices and data streams, and inspect cluster health through a defined set of tools. This guide shows practical steps to run the server, connect with an MCP client, and secure your setup.

How to use

Connect to the MCP server from your client to perform common Elasticsearch/OpenSearch operations. You can search documents, index or update documents, manage indices and data streams, and inspect cluster health and statistics. Use dedicated tools for each operation, or fall back to a general API request tool for any API call that isn’t covered by a specific tool.

How to install

Prerequisites: you need either Node.js/UVX tooling or Python-based runtime tooling as described below. Choose one of the two deployment methods that matches your workflow.

# Prereqs: ensure you have a runtime capable of running MCP servers
# Option A: Run MCP server config with uvx (Node environment)
# You will configure environment vars for Elasticsearch/OpenSearch endpoints.

# Option B: Run MCP server config with uv (local development)

Option A: Run with uvx (remote MCP runner)

Use uvx to run the MCP server configuration directly. This approach installs and runs the MCP server package from the registry and uses your environment variables to connect to Elasticsearch or OpenSearch.

# Example: Elasticsearch with username/password using uvx
{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uvx",
      "args": [
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_USERNAME": "elastic",
        "ELASTICSEARCH_PASSWORD": "test123"
      }
    }
  }
}

Elasticsearch with API key using uvx

{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uvx",
      "args": [
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_API_KEY": "<YOUR_ELASTICSEARCH_API_KEY>"
      }
    }
  }
}

OpenSearch with username/password using uvx

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

OpenSearch with API key using uvx

If you are using API keys for OpenSearch, the same pattern applies by providing OPENSEARCH_HOSTS and OPENSEARCH_API_KEY in the environment.

Option B: Run with uv for local development

If you prefer development on your machine, clone the MCP server sources and run uv with the directory path to the server. This requires you to point to your local server source when starting.

# Example: Elasticsearch with username/password using uv
{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "path/to/elasticsearch-mcp-server",
        "run",
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_USERNAME": "elastic",
        "ELASTICSEARCH_PASSWORD": "test123"
      }
    }
  }
}

Elasticsearch with API key using uv

{
  "mcpServers": {
    "elasticsearch-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "path/to/elasticsearch-mcp-server",
        "run",
        "elasticsearch-mcp-server"
      ],
      "env": {
        "ELASTICSEARCH_HOSTS": "https://localhost:9200",
        "ELASTICSEARCH_API_KEY": "<YOUR_ELASTICSEARCH_API_KEY>"
      }
    }
  }
}

OpenSearch with username/password using uv

{
  "mcpServers": {
    "opensearch-mcp-server": {
      "command": "uv",
      "args": [
        "--directory",
        "path/to/elasticsearch-mcp-server",
        "run",
        "opensearch-mcp-server"
      ],
      "env": {
        "OPENSEARCH_HOSTS": "https://localhost:9200",
        "OPENSEARCH_USERNAME": "admin",
        "OPENSEARCH_PASSWORD": "admin"
      }
    }
  }
}

OpenSearch with API key using uv

If you are using API keys for OpenSearch, provide OPENSEARCH_HOSTS and OPENSEARCH_API_KEY in the environment.

Available tools

general_api_request

Perform a general HTTP API request for Elasticsearch/OpenSearch API calls that do not have a dedicated tool.

list_indices

List all indices in the cluster.

get_index

Return mappings, settings, and aliases for one or more indices.

create_index

Create a new index.

delete_index

Delete an index.

create_data_stream

Create a new data stream (requires matching index template).

get_data_stream

Get information about one or more data streams.

delete_data_stream

Delete one or more data streams and their backing indices.

search_documents

Search for documents in an index.

index_document

Create or update a document in an index.

get_document

Retrieve a document by its ID.

delete_document

Delete a document by its ID.

delete_by_query

Delete documents that match a given query.

get_cluster_health

Return basic health information about the cluster.

get_cluster_stats

Provide a high-level overview of cluster statistics.

list_aliases

List all index aliases.

get_alias

Get information about an alias for a specific index.

put_alias

Create or update an alias for a specific index.

delete_alias

Delete an alias for a specific index.