Skip to main content
Glama
elasticsearch-mcp

elasticsearch-mcp

elasticsearch-mcp

Read-only Elasticsearch for any AI agent: plug it in as an MCP server, or as an Agent Skill where MCP isn't allowed.

License: MIT Python 3.10+ MCP server Agent Skill Elasticsearch 7 | 8 | 9 Read-only

Works with

Claude Code Codex Cursor OpenCode Gemini CLI VS Code Claude Desktop


Ask your agent "Which hosts logged the most errors today?" and it finds the index, reads the mappings and runs the query itself. One small Python package gives every agent the same six read-only tools, two ways:

flowchart LR
    agent["Your agent<br/>Claude Code · Codex · Cursor<br/>OpenCode · Gemini CLI · VS Code"]
    agent -- "MCP over stdio" --> mcp["elasticsearch-mcp<br/>MCP server"]
    agent -- "Agent Skill: shell commands" --> cli["elasticsearch-mcp COMMAND<br/>CLI"]
    mcp --> tools["6 read-only tools"]
    cli --> tools
    tools -- "REST API" --> es[("Elasticsearch<br/>7 · 8 · 9 · Elastic Cloud")]

Quick start

You need uv, your cluster's URL and an API key (here's a read-only key).

  1. Add the server to your agent. For Claude Code:

    claude mcp add --scope user elasticsearch -e ES_URL=https://your-cluster:9200 -e ES_API_KEY=your-key -- uvx --from git+https://github.com/aniketshukla1/elasticsearch-mcp elasticsearch-mcp

    Other agents: MCP setup. MCP not allowed: Agent Skill.

  2. Restart the agent.

  3. Ask: "What indices do I have, and which is the largest?"

No cluster yet? Develop locally starts one in Docker with sample data.

Related MCP server: Kibana MCP Server

Use it as an MCP server

Every client launches the same command and passes the settings as environment variables:

uvx --from git+https://github.com/aniketshukla1/elasticsearch-mcp elasticsearch-mcp
claude mcp add --scope user elasticsearch -e ES_URL=https://your-cluster:9200 -e ES_API_KEY=your-key -- uvx --from git+https://github.com/aniketshukla1/elasticsearch-mcp elasticsearch-mcp

Keep the name elasticsearch before the -e flags, or -e swallows it.

codex mcp add elasticsearch --env ES_URL=https://your-cluster:9200 --env ES_API_KEY=your-key -- uvx --from git+https://github.com/aniketshukla1/elasticsearch-mcp elasticsearch-mcp

Add this to ~/.cursor/mcp.json, ~/.gemini/settings.json or claude_desktop_config.json:

{
  "mcpServers": {
    "elasticsearch": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/aniketshukla1/elasticsearch-mcp", "elasticsearch-mcp"],
      "env": { "ES_URL": "https://your-cluster:9200", "ES_API_KEY": "your-key" }
    }
  }
}

Desktop apps may not see your shell's PATH. If the server doesn't start, use the full path from which uvx as command. Cursor asks you to approve the server the first time.

Add this to ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "elasticsearch": {
      "type": "local",
      "command": ["uvx", "--from", "git+https://github.com/aniketshukla1/elasticsearch-mcp", "elasticsearch-mcp"],
      "environment": { "ES_URL": "https://your-cluster:9200", "ES_API_KEY": "your-key" }
    }
  }
}
code --add-mcp '{"name":"elasticsearch","command":"uvx","args":["--from","git+https://github.com/aniketshukla1/elasticsearch-mcp","elasticsearch-mcp"],"env":{"ES_URL":"https://your-cluster:9200","ES_API_KEY":"your-key"}}'

If code opens Cursor (Cursor can install its own code command), run VS Code's CLI by its full path: "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code".

The server also ships an MCP prompt, elasticsearch(question). Clients that support MCP prompts, such as Claude Code and VS Code, list it as a slash command.

Use it as an Agent Skill

Some setups don't allow MCP servers. The skill in skills/elasticsearch teaches the agent to run the same six tools as shell commands, or as plain curl calls when uv isn't installed. It follows the open Agent Skills format, so one folder works in every agent that supports skills.

Install it for your user, in the agents you pick, with the skills installer (drop -g to install into the current project only):

npx skills add aniketshukla1/elasticsearch-mcp -g

Or copy the folder into one agent's skills directory:

Agent

Skills directory

Claude Code

~/.claude/skills/

Codex

~/.codex/skills/

Cursor

~/.cursor/skills/

OpenCode

~/.config/opencode/skills/

Gemini CLI

~/.gemini/skills/

GitHub Copilot

~/.copilot/skills/

git clone https://github.com/aniketshukla1/elasticsearch-mcp
cp -r elasticsearch-mcp/skills/elasticsearch ~/.claude/skills/

The skill reads the same environment variables as the server. Ask about your data and the agent loads it; in Claude Code you can also type /elasticsearch. The commands work by hand too:

uvx --from git+https://github.com/aniketshukla1/elasticsearch-mcp elasticsearch-mcp list-indices 'logs-*'
uvx --from git+https://github.com/aniketshukla1/elasticsearch-mcp elasticsearch-mcp esql 'FROM logs-* | STATS n = COUNT(*) BY host.name | LIMIT 5'

Tools

MCP tool

CLI command

Elasticsearch API

list_indices(pattern="*")

list-indices [PATTERN]

GET _cat/indices/{pattern}

get_mappings(index)

get-mappings INDEX

GET {index}/_mapping

search(index, body)

search INDEX [BODY]

POST {index}/_search: Query DSL, aggregations

esql(query)

esql QUERY

POST _query: ES|QL, Elasticsearch 8.11+

get_shards(index="*")

get-shards [PATTERN]

GET _cat/shards/{index}

cluster_health()

cluster-health

GET _cluster/health

Results are Elasticsearch's own compact JSON. Errors come back with Elasticsearch's reason, so the agent can fix its query.

Settings

Variable

Meaning

ES_URL

Cluster URL. Default http://localhost:9200

ES_API_KEY

Preferred. The encoded value from POST _security/api_key

ES_USERNAME, ES_PASSWORD

Basic auth, used when ES_API_KEY is empty

ES_CA_CERT

CA bundle path for self-signed TLS, such as http_ca.crt

Read-only by design

No tool or command writes, deletes or changes settings: there is nothing to call. To make sure nothing else can either (a curl from the skill's fallback, say), give the agent a key that can't write. This role covers all six tools; narrow names to the indices the agent should see:

POST /_security/api_key
{
  "name": "mcp-read-only",
  "role_descriptors": {
    "mcp_read_only": {
      "cluster": ["monitor"],
      "indices": [{ "names": ["*"], "privileges": ["read", "view_index_metadata", "monitor"] }]
    }
  }
}

Use the encoded value from the response as ES_API_KEY.

Develop locally

cp .env.example .env                       # then set ES_PASSWORD
docker compose up -d --wait                # Elasticsearch 9.5.5 on 127.0.0.1:9200
uv run --env-file .env tests/test_e2e.py   # end-to-end test of the MCP server and the CLI

The test seeds the mcp-demo-products index, then checks every tool and the prompt over MCP and every CLI command, once with a read-only API key and once with the password. To point an agent at your checkout instead of GitHub, use this command:

uv run --directory /path/to/elasticsearch-mcp --env-file .env elasticsearch-mcp
elasticsearch-mcp/
├── src/elasticsearch_mcp/
│   ├── server.py        MCP server: six read-only tools and the elasticsearch prompt
│   └── cli.py           the elasticsearch-mcp command: serves MCP, or runs one tool from the shell
├── skills/elasticsearch/
│   └── SKILL.md         Agent Skill for agents without MCP
├── tests/test_e2e.py    end-to-end test against a real cluster
├── assets/logo.svg
├── docker-compose.yml   local Elasticsearch
└── .env.example         settings template

License

MIT

Available Tools

6 tools
cluster_healthB
Read-only

Cluster health: status (green, yellow or red), node count and shard counts.

Inputs: no named parameters.

esqlA
Read-only

Run an ES|QL query (Elasticsearch 8.11+), for example 'FROM logs-* | STATS errors = COUNT(*) BY host.name | SORT errors DESC | LIMIT 10'. Returns columns and rows.

Inputs: query (required).

get_mappingsA
Read-only

Get the field names and types of an index or pattern. Read them before writing a search or ES|QL query.

Inputs: index (required).

get_shardsA
Read-only

Show shards for indices matching a pattern: primary or replica, state, docs, size and node.

Inputs: index.

list_indicesA
Read-only

List indices matching a pattern such as "logs-*" or "a,b", with health, status, doc count and size.

Inputs: pattern.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 6 tools

    Disambiguation4/5

    Each tool has a recognizable target: index metadata (list_indices, get_mappings), querying (search, esql), shard inspection (get_shards), and cluster status (cluster_health). The only mild overlap is search vs. esql, but the descriptions clearly differentiate Query DSL from ES|QL syntax, so an agent can pick correctly.

    Naming Consistency4/5

    The set follows a verb_noun convention (list_indices, get_mappings, get_shards, cluster_health is the only noun-only name). Minor deviation, but overall readable and predictable.

    Tool Count5/5

    Six tools is well-scoped for a read-only Elasticsearch inspection server; each tool covers a distinct aspect (indices, mappings, search, ES|QL, shards, cluster health) without redundancy.

    Completeness4/5

    Covers the core read/query lifecycle: discover indices, inspect schema, run DSL and ES|QL queries, and check shard/cluster status. Gaps exist (no fetch-document-by-id, no write/index/delete operations), but these are minor for a read-oriented toolset and workable via search.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      D
      maintenance
      Enables AI agents to interact with INFINI Easysearch (compatible with Elasticsearch/OpenSearch APIs) through 121 tools covering cluster management, index operations, document manipulation, search queries, snapshots, and monitoring.
      100
      4
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      Enables AI assistants to interact with Kibana dashboards, visualizations, and Elasticsearch data through read-only resources and executable tools for searching logs, exporting dashboards, and querying data.
      7
      4
      MIT
    • F
      license
      B
      quality
      Not graded
      maintenance
      Provides comprehensive tools for managing Elasticsearch clusters, including security management, search operations, and index administration. It enables users to monitor cluster health, handle InfoSec tasks, and execute complex queries using Elasticsearch Query DSL and ES|QL.
      37
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides tools to query Elasticsearch indices, retrieve mappings, execute searches, and get cluster health stats.
      4
      MIT