Back to Guides

How to Connect Elasticsearch to MCP for AI Agents

Connect Elasticsearch to AI agents via MCP. Search, query, and analyze data through natural language using AnythingMCP's REST connector.

Elasticsearch with AI Agents

Elasticsearch's powerful search and analytics capabilities make it ideal for AI agent access. Since Elasticsearch exposes a REST API natively, you can connect it to MCP using AnythingMCP's REST connector.

Step-by-Step Guide

Step 1: Deploy AnythingMCP

git clone https://github.com/HelpCode-ai/anythingmcp.git
cd anythingmcp && docker compose up -d

Step 2: Create a REST Connector

Open the AnythingMCP dashboard at http://localhost:3000 and create a new REST connector. Set the base URL to your Elasticsearch cluster endpoint (e.g., https://your-cluster.es.amazonaws.com or http://localhost:9200).

Step 3: Configure Authentication

In the connector settings, configure API key, Basic auth, or AWS IAM credentials depending on your Elasticsearch setup.

Step 4: Configure Search Endpoints

Set up endpoints for Elasticsearch's search, aggregation, and index management APIs in the dashboard. Customize tool names and descriptions.

Step 5: Test and Connect

{
  "mcpServers": {
    "elasticsearch": {
      "url": "http://localhost:4000/mcp"
    }
  }
}

AI Agent Use Cases

  • "Search for products matching 'wireless bluetooth headphones'"
  • "What are the top 10 most searched terms this week?"
  • "Show me error logs from the last hour"
  • "Aggregate sales data by category for this month"
  • "Find all documents related to customer onboarding"

Best Practices

  1. Read-only access — Use an Elasticsearch role with read-only index permissions
  2. Index aliases — Use aliases to abstract index names from AI agents
  3. Query DSL — Pre-configure common search patterns as tool endpoints
  4. Cluster health — Monitor cluster health and avoid overwhelming it with requests

Next Steps