Elasticsearch MCP — Search & Analytics for AI Agents
MCP server connecting AI agents to Elasticsearch clusters. Run queries, manage indices, and analyze data through natural language via Claude Code or Cline.
What it is
Elasticsearch MCP is a Model Context Protocol server that connects AI agents to Elasticsearch clusters. It exposes search, indexing, and cluster management operations as MCP tools, letting agents like Claude Code run queries, manage indices, and analyze data through natural language instructions.
The server targets developers and data engineers who want their AI coding assistants to interact directly with Elasticsearch without writing raw REST calls.
How it saves time or tokens
Instead of manually constructing Elasticsearch DSL queries and copying results between terminal and editor, the MCP server lets your AI agent handle the full loop: build the query, execute it, and interpret results. This is especially useful for complex aggregations and index management tasks that require multiple API calls.
How to use
- Install the Elasticsearch MCP server package.
- Configure your Claude Code or other MCP client to connect to the server with your Elasticsearch cluster URL and credentials.
- Ask your AI agent to query, index, or manage your Elasticsearch data in natural language.
Example
{
"mcpServers": {
"elasticsearch": {
"command": "npx",
"args": ["@elastic/mcp-server-elasticsearch"],
"env": {
"ES_URL": "https://localhost:9200",
"ES_API_KEY": "your-api-key"
}
}
}
}
Once configured, ask your agent: 'Search for error logs from the last hour in the app-logs index' and it constructs and executes the query.
Related on TokRepo
- MCP Integrations -- other MCP server integrations for AI agents
- AI Tools for Database -- database tools and search utilities
Common pitfalls
- The MCP server needs network access to your Elasticsearch cluster. Ensure firewall rules allow connections from your local machine.
- API key permissions scope what the agent can do. Use read-only keys for exploration and full-access keys only when you explicitly need write operations.
- Complex aggregation queries may exceed the agent's context window. Break large result sets into paginated requests.
Frequently Asked Questions
The MCP server works with Elasticsearch 7.x and 8.x clusters. It uses the official Elasticsearch client library, so compatibility follows the Elastic versioning policy.
OpenSearch compatibility depends on the specific MCP server implementation. Since OpenSearch forked from Elasticsearch 7.10, basic operations may work but advanced features may differ.
Yes. The MCP server works with any MCP-compatible client including Claude Code, Claude Desktop, and Cursor. Configuration is done through the client's MCP settings file.
Query results pass through the MCP protocol to your AI agent, which means they enter the LLM context. For sensitive data, use field filtering to limit what the agent sees or run a local model.
Yes, if the API key has the necessary permissions. For safety, use read-only API keys during exploration and only grant write access when you specifically need index management.
Citations (3)
- Elasticsearch MCP GitHub— MCP server for Elasticsearch integration
- MCP Official Site— Model Context Protocol specification
- Elastic Docs— Elasticsearch REST API documentation
Related on TokRepo
Source & Thanks
Created by Elastic. Licensed under Apache 2.0.