The Elasticsearch MCP Server connects agents to your Elasticsearch data using the Model Context Protocol, allowing natural language interactions with your Elasticsearch indices through compatible MCP clients like Claude Desktop.
Configure MCP Client
Edit Config
and add a new MCP Server:{
"mcpServers": {
"elasticsearch-mcp-server": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"-e", "ES_URL",
"-e", "ES_API_KEY",
"docker.elastic.co/mcp/elasticsearch", "stdio"
],
"env": {
"ES_URL": "<your-elasticsearch-url>",
"ES_API_KEY": "<your-api-key>"
}
}
}
}
Start a Conversation
Configure MCP Client
Edit Config
and add a new MCP Server:{
"mcpServers": {
"elasticsearch-mcp-server": {
"command": "npx",
"args": [
"-y",
"@elastic/mcp-server-elasticsearch"
],
"env": {
"ES_URL": "<your-elasticsearch-url>",
"ES_API_KEY": "<your-api-key>",
"OTEL_LOG_LEVEL": "none"
}
}
}
}
Start a Conversation
You must provide either an API key or both username and password for authentication.
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 |
ES_SSL_SKIP_VERIFY |
Set to '1' or 'true' to skip SSL certificate verification | No |
ES_PATH_PREFIX |
Path prefix for Elasticsearch instance exposed at a non-root path | No |
ES_VERSION |
Server assumes Elasticsearch 9.x. Set to 8 target Elasticsearch 8.x |
No |
The MCP server provides several tools for interacting with your Elasticsearch data:
Here are some natural language queries you can try with your MCP Client:
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"
]
}
]
}
}
}
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "elasticsearch-mcp-server" '{"command":"npx","args":["-y","@elastic/mcp-server-elasticsearch"],"env":{"ES_URL":"<your-elasticsearch-url>","ES_API_KEY":"<your-api-key>","OTEL_LOG_LEVEL":"none"}}'
See the official Claude Code MCP documentation for more details.
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.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"elasticsearch-mcp-server": {
"command": "npx",
"args": [
"-y",
"@elastic/mcp-server-elasticsearch"
],
"env": {
"ES_URL": "<your-elasticsearch-url>",
"ES_API_KEY": "<your-api-key>",
"OTEL_LOG_LEVEL": "none"
}
}
}
}
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.
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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"elasticsearch-mcp-server": {
"command": "npx",
"args": [
"-y",
"@elastic/mcp-server-elasticsearch"
],
"env": {
"ES_URL": "<your-elasticsearch-url>",
"ES_API_KEY": "<your-api-key>",
"OTEL_LOG_LEVEL": "none"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect