Elasticsearch MCP server tools: what the API key really limits, and how to make your agent ask
All 5 tools of Elastic's deprecated Elasticsearch MCP server (0.4.6), checked by running it against Elasticsearch 9.2.1 with security on: what each tool sends, how a key made by the elastic user read every API key's hash from .security-7, how ES|QL ENRICH handed over salaries from an index the key could not search, why its tools.exclude setting does nothing, and the Claude Code settings that make it ask.
Checked on by running Elasticsearch MCP server 0.4.6 (Docker image docker.elastic.co/mcp/elasticsearch, also its latest tag) from elastic/mcp-server-elasticsearch and reading its tools/list answer. Each tier is the tool risk checker’s reading, with our reason wherever we changed it. Written by the people who make VariantGate.
The short answer
Deprecated, and none of its 5 tools writes, but search and esql read as far as the API key reaches: a key made by the elastic user read every API key's hash. Give it a key with read on named indices and no cluster privileges, which refused everything else we tried, and make search and esql ask unless the key is that narrow.
- Can run on their own
- 3
- Should ask a person
- 2
Which Elasticsearch server this is
This page is about Elastic’s own MCP server, the Docker image docker.elastic.co/mcp/elasticsearch. It is deprecated: its README says it will only get critical security fixes and that it has been superseded by the MCP endpoint of Elastic Agent Builder, in Elastic 9.2.0 and later and in Serverless projects. The image prints the same notice to standard error each time it starts. The older npm package, @elastic/mcp-server-elasticsearch 0.3.1, is marked deprecated on npm as well. We ran 0.4.6, which was also the image’s latest tag, over stdio against Elasticsearch 9.2.1 in Docker, single node, with security and TLS on and a basic licence. It calls itself “rmcp” 0.2.1, the name and version of the MCP library it is built on, and offers five tools, all marked read-only.
What each tool sends
We read its Rust source at the v0.4.6 tag. Each tool makes one fixed request, and none of them can write:
list_indices:GET _cat/indices/<pattern>, keeping the name, status and document count.get_shards:GET _cat/shards, for one index or all of them.get_mappings:GET <index>/_mapping.search:POST <index>/_searchwith whatever body the agent writes. It returns each hit’s_sourceand any aggregations.esql:POST _querywith the ES|QL text.
The index name goes into the path escaped, so it cannot reach another endpoint. customers/_delete_by_query was sent as customers%2F_delete_by_query/_search and came back 404, and so did ../_security/api_key. ES|QL has no command that writes: INSERT INTO was refused by its parser, and so was a second statement after a semicolon.
With a key made by the elastic user
The README asks for an API key and says nothing about what it should allow. A key created by the elastic user with no role descriptors carries that user’s superuser role, and with it:
searchon index*returned the documents of every ordinary index, salaries included. The wildcard left out.security-7, but naming it did not: a search there returned the stored hash of every API key, its name, its creator and its roles.FROM .security-7inesqldid the same.- The body is passed on as it is. A
runtime_mappingsscript bucketed salaries into bands in an aggregation, and a script query looping 999,990 times per document ran. Elasticsearch’s own limits refused an endlesswhile (true)loop when compiling it, and asizeof 20,000, above the 10,000 result window. - We added a remote cluster called
selfthat points back at the same node, andself:.security-7read the security index through it too. ES|QL across clusters was refused: it needs an Enterprise licence. get_shardsandlist_indiceswith.*named the system indices.get_mappingson.security-7failed to decode.
What a scoped key stopped
A key with only read and view_index_metadata on customers and orders, and no cluster privileges, refused everything else we tried. search on hr-salaries and on .security-7 came back 403; on * it returned only the two allowed indices. ES|QL reported the others as unknown indices, and refused an ENRICH and a LOOKUP JOIN that would have pulled salaries in. Through the remote cluster it could read self:customers, while self:hr-salaries came back with no hits and the remote marked as skipped.
Two tools stop working with that key. list_indices and get_shards need the cluster privilege monitor, even for an allowed index. With cluster monitor added, and monitor on the two indices, list_indices on * listed only those two, but get_shards with no index listed every index in the cluster by name, hr-salaries and .security-7 among them. Tell the agent the index names instead.
Watch the enrich privileges. We gave the scoped key monitor_enrich, and an esql query FROM customers | ENRICH salary-by-name returned the salaries from hr-salaries, an index the same key could not search. An enrich policy copies fields into an index of its own, and the key’s lack of access to the source did not stop the lookup.
Its switches
- It has no read-only switch, and needs none: it has no tool that writes. The only limit is the key.
- Its config file accepts
tools.excludeandtools.include, which the example in the repository shows commented out as work in progress. 0.4.6 reads them and ignores them: withexclude: ["search", "esql"]both tools were still listed, andsearchstill ran. ES_SSL_SKIP_VERIFY=trueskips the whole certificate check: it connected with a host name the certificate did not name. The README says a custom CA is not supported yet. What worked for us was mounting the cluster’s CA and pointingSSL_CERT_FILEat it, which the image’s TLS library reads:-v ~/es-ca/http_ca.crt:/ca.crt:ro -e SSL_CERT_FILE=/ca.crt. With it, a wrong CA and a wrong host name were both refused. A cluster whose certificate comes from a public CA should need neither setting; we did not try one.- The HTTP transport listens on
127.0.0.1:8080by default, but the image setsCONTAINER_MODE, which makes it0.0.0.0:8080, and the README publishes it with-p 8080:8080, which Docker binds on every interface. It asks for no credentials: a request from another container with noAuthorizationheader read.security-7with the server’s own key. A request with a header used that header instead, and a wrong one got 401. Use stdio, or publish it as-p 127.0.0.1:8080:8080and start it without a key of its own.
Smaller things we saw
get_mappings on a pattern that matched no index panicked, and the call never got an answer; the server went on answering other calls. Errors reach the agent as a status and a URL, such as “400 Bad Request”, without Elasticsearch’s reason, so an ES|QL syntax error and an index the key may not read look alike. Its log on standard error held URLs and index names, never the key or a query body.
Give it a key that only reads named indices
Create the key as a user who can read those indices, with a role that names them and grants nothing on the cluster:
POST /_security/api_key
{
"name": "mcp-agent",
"expiration": "30d",
"role_descriptors": {
"mcp-agent-read": {
"cluster": [],
"indices": [
{
"names": ["customers", "orders"],
"privileges": ["read", "view_index_metadata"]
}
]
}
}
}Put the encoded value from the answer in ES_AGENT_KEY, and add the server pinned to the image we ran:
claude mcp add elasticsearch -e ES_URL=https://es.internal:9200 -e ES_API_KEY=$ES_AGENT_KEY -- docker run -i --rm -e ES_URL -e ES_API_KEY docker.elastic.co/mcp/elasticsearch@sha256:d57ea11dcb3451ca332cb6d3bb8c4bb1ea29f15e498937ad6c2eada9f88eb003 stdioLeave out ES_SSL_SKIP_VERIFY, and use an https address: the key travels in a header on every request. If the cluster uses the certificate authority Elasticsearch made for itself, as a default install does, add the CA mount from above, -v ~/es-ca/http_ca.crt:/ca.crt:ro -e SSL_CERT_FILE=/ca.crt, after docker run -i --rm; without it every call fails the certificate check. Keep monitor_enrich, and any privilege that includes it, off the key unless every enrich policy copies only what the agent may read.
Its tools
Not sure2 toolsAsk a person until you have checked what it does.
searchPerform an Elasticsearch search with the provided query DSL.
Server says: read-only
Our call: Only ever calls _search, and the index name is escaped, so customers/_delete_by_query went nowhere. But it takes any query body, painless scripts included, and reads whatever the key reads: named, .security-7 gave back API key hashes.
esqlPerform an Elasticsearch ES|QL query.
Server says: read-only
Our call: ES|QL has no command that writes, and INSERT was refused by its parser. But it reads whatever the key reads: FROM .security-7 returned API key hashes, and with monitor_enrich an ENRICH returned salaries from an index the key could not search.
Only looks3 toolsLet it run. It only looks.
list_indicesList all available Elasticsearch indices
Server says: read-only
get_shardsGet shard information for all or specific indices.
Server says: read-only
get_mappingsGet field mappings for a specific Elasticsearch index
Server says: read-only
Let the reads run in Claude Code
Claude Code asks before every MCP tool it has no rule for. Added as elasticsearch, this server’s tools are named mcp__elasticsearch__<tool>. These allow rules, in .claude/settings.json or ~/.claude/settings.json, let the tools that only look run without a prompt. Everything else keeps asking, including any tool a later version of the server adds.
{
"permissions": {
"allow": [
"mcp__elasticsearch__list_indices",
"mcp__elasticsearch__get_shards",
"mcp__elasticsearch__get_mappings"
]
}
}The command that adds the server:
claude mcp add elasticsearch -e ES_URL=https://es.internal:9200 -e ES_API_KEY=$ES_AGENT_KEY -- docker run -i --rm -e ES_URL -e ES_API_KEY docker.elastic.co/mcp/elasticsearch@sha256:d57ea11dcb3451ca332cb6d3bb8c4bb1ea29f15e498937ad6c2eada9f88eb003 stdioSend the rest to a person, not the terminal
A prompt in the terminal only works while someone is watching it. With this hook, every other tool of the server becomes a request in your VariantGate inbox, on your phone or in Slack, and Claude Code waits for the answer. The matcher names the look-only tools, so a tool added later is sent too. Put the key in VARIANTGATE_KEY, or run the one-command setup for Claude Code first.
{
"hooks": {
"PreToolUse": [
{
"matcher": "mcp__elasticsearch__(?!(list_indices|get_shards|get_mappings)$).*",
"hooks": [
{ "type": "command", "command": "variantgate hook claude-code", "timeout": 180 }
]
}
]
}
}Disagree with a tier, or run the server with other flags? Open these tools in the tool risk checker, change what you like, and copy the settings for your own setup. It runs in your browser and starts from its own reading, so a tool we marked as only looking by hand asks there until you change it.
Any MCP client: put the proxy in front
Claude Desktop, Cursor and most other MCP clients have no hook to send a call to a person. The VariantGate MCP proxy does it in the server’s place: it starts the server, lets the look-only tools above through, and holds every other call until someone approves it in the inbox. Run npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz login once to save a key, then use this in claude_desktop_config.json or ~/.cursor/mcp.json:
{
"mcpServers": {
"elasticsearch": {
"args": [
"-y",
"https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz",
"mcp-proxy",
"--name",
"elasticsearch",
"--look-only",
"list_indices,get_shards,get_mappings",
"--",
"docker",
"run",
"-i",
"--rm",
"-e",
"ES_URL",
"-e",
"ES_API_KEY",
"docker.elastic.co/mcp/elasticsearch@sha256:d57ea11dcb3451ca332cb6d3bb8c4bb1ea29f15e498937ad6c2eada9f88eb003",
"stdio"
],
"command": "npx",
"env": {
"ES_URL": "https://es.internal:9200",
"ES_API_KEY": "<ES_AGENT_KEY>"
}
}
}
}Already have it in Claude Desktop? One command rewrites the file for you, with these look-only tools filled in, and keeps the old one (setup vscode does the same for VS Code; how it works):
npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz setup claude-desktopThe same in Claude Code, instead of the hook. The proxy now asks about every call that matters, so an allow rule for the whole server, mcp__elasticsearch, keeps Claude Code from asking a second time in the terminal:
claude mcp add elasticsearch -e ES_URL=https://es.internal:9200 -e ES_API_KEY=$ES_AGENT_KEY -- npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz mcp-proxy --name elasticsearch --look-only list_indices,get_shards,get_mappings -- docker run -i --rm -e ES_URL -e ES_API_KEY docker.elastic.co/mcp/elasticsearch@sha256:d57ea11dcb3451ca332cb6d3bb8c4bb1ea29f15e498937ad6c2eada9f88eb003 stdioClaude Code’s allow rules match a tool’s name, never its arguments, so a rule cannot tell a harmless call of these tools from a risky one. With an API key limited to read and view_index_metadata on the indices the agent may see, no cluster privileges at all (monitor_enrich least of all), and only there, these rules also let search, esql run unasked:
{
"permissions": {
"allow": [
"mcp__elasticsearch__list_indices",
"mcp__elasticsearch__get_shards",
"mcp__elasticsearch__get_mappings",
"mcp__elasticsearch__search",
"mcp__elasticsearch__esql"
]
}
}What to use instead
Elastic points new setups to the Agent Builder MCP endpoint. We did not run it, so this page says nothing about its tools or limits. Whatever you use, the scoped key above is what held here: the server’s tools only read, so what the agent can see is exactly what its key can see.
See it before you decide.
The playground runs the whole approval loop in your browser, no account needed. When it fits, the free plan covers 100 requests a month.