Sponsored by Deepsite.site

MCP Elasticsearch Server 🔍

Created By
sonirico7 months ago
MCP server connecting AI systems to Elasticsearch clusters
Content

MCP Elasticsearch Server 🔍

A Model Context Protocol (MCP) server that provides Elasticsearch integration capabilities to AI assistants and other MCP clients. This server enables querying Elasticsearch clusters through a standardized interface.

Features

  • 🔐 Multiple Authentication Methods: Supports both API key and username/password authentication
  • 📊 Index Management: List indices with health status and document counts
  • 🗺️ Schema Discovery: Retrieve field mappings to understand index structure
  • 🔍 Advanced Search: Execute complex Elasticsearch queries with aggregations and sorting
  • 📋 Structured Responses: JSON-formatted output with search metadata
  • ⚡ Performance Monitoring: Query execution time tracking
  • 🎯 Context Aware: Supports search execution with proper context cancellation

Tools

list_indices

List all Elasticsearch indices with optional pattern filtering.

Parameters:

  • pattern (string, optional): Index pattern filter (default: "*")

Returns:

  • Total index count
  • Index details (name, health, status, document count, size)

get_index_mappings

Get field mappings for one or more Elasticsearch indices.

Parameters:

  • index (string, required): Index name or pattern

Returns:

  • Complete field mappings for the specified indices

Execute Elasticsearch search queries with full DSL support.

Parameters:

  • index (string, required): Index name or pattern to search
  • query (string, optional): Elasticsearch query DSL as JSON (default: "{}")
  • size (number, optional): Maximum documents to return (default: 10, max: 10000)
  • sort (string, optional): Sort specification as JSON
  • track_total_hits (boolean, optional): Track total hit count (default: true)

Returns:

  • Search results with hits, aggregations, and metadata

Configuration

Environment Variables

Elasticsearch Configuration

  • ES_URL: Elasticsearch cluster URL (required)
  • ES_API_KEY: API key for authentication (optional)
  • ES_USERNAME: Username for basic authentication (optional)
  • ES_PASSWORD: Password for basic authentication (optional)

Server Configuration

  • MCP_ES_SERVER_NAME: Server name (default: "mcp-elasticsearch 🔍")

Logging Configuration

  • MCP_ES_LOG_LEVEL: Log level (debug, info, warn, error, fatal)
  • MCP_ES_LOG_FORMAT: Log format (json, console)
  • MCP_ES_LOG_OUTPUT: Log output (stdout, stderr)

Authentication

You must provide either:

  1. API Key authentication: Set ES_API_KEY
  2. Basic authentication: Set both ES_USERNAME and ES_PASSWORD

Installation

# Clone and build
git clone <repository>
cd mcp-elasticsearch
go mod download
go build -o bin/mcp-elasticsearch .

# Install to system
sudo install bin/mcp-elasticsearch /usr/local/bin/

Usage

Direct Execution

# With API key
ES_URL="https://your-cluster.com" ES_API_KEY="your-api-key" mcp-elasticsearch

# With basic auth
ES_URL="https://your-cluster.com" ES_USERNAME="user" ES_PASSWORD="pass" mcp-elasticsearch

# With custom logging
ES_URL="https://your-cluster.com" ES_API_KEY="key" MCP_ES_LOG_LEVEL=debug mcp-elasticsearch

Integration with Claude Desktop

Add to your Claude configuration:

{
  "mcpServers": {
    "elasticsearch": {
      "command": "mcp-elasticsearch",
      "env": {
        "ES_URL": "https://your-cluster.com",
        "ES_API_KEY": "your-api-key",
        "MCP_ES_LOG_LEVEL": "info"
      }
    }
  }
}

Integration with ApMentor

Update your config.json:

{
  "mcpServers": {
    "elasticsearch-go": {
      "command": "/usr/local/bin/mcp-elasticsearch",
      "env": {
        "ES_URL": "https://atani.es.eu-west-1.aws.found.io",
        "ES_API_KEY": "your-api-key",
        "MCP_ES_LOG_LEVEL": "info"
      }
    }
  }
}

Example Queries

List All Indices

{
  "tool": "list_indices",
  "parameters": {
    "pattern": "*"
  }
}

List Log Indices Only

{
  "tool": "list_indices", 
  "parameters": {
    "pattern": "logs-*"
  }
}

Get Index Mappings

{
  "tool": "get_index_mappings",
  "parameters": {
    "index": "logs-apm.error-*"
  }
}
{
  "tool": "search",
  "parameters": {
    "index": "logs-*",
    "query": "{\"match\": {\"service.name\": \"broker-api-b2b\"}}",
    "size": 50
  }
}

Complex Search with Aggregations

{
  "tool": "search",
  "parameters": {
    "index": "logs-*",
    "query": "{\"bool\": {\"must\": [{\"term\": {\"service.name\": \"broker-api-b2b\"}}, {\"range\": {\"@timestamp\": {\"gte\": \"now-24h\"}}}]}}",
    "size": 0,
    "aggs": "{\"error_types\": {\"terms\": {\"field\": \"error.type.keyword\", \"size\": 10}}}"
  }
}

Search with Sorting

{
  "tool": "search",
  "parameters": {
    "index": "logs-*",
    "query": "{\"match\": {\"log.level\": \"ERROR\"}}",
    "sort": "[{\"@timestamp\": {\"order\": \"desc\"}}]",
    "size": 20
  }
}

Development

# Install dependencies
go mod download

# Format code
gofmt -w .

# Run tests
go test -v ./...

# Build
go build -o bin/mcp-elasticsearch .

# Run with debug logging
MCP_ES_LOG_LEVEL=debug go run .

Error Handling

The server provides detailed error messages for common issues:

  • Authentication failures: Check your API key or credentials
  • Index not found: Verify index names and patterns
  • Query syntax errors: Validate your Elasticsearch query JSON
  • Connection issues: Ensure Elasticsearch is accessible

Security Considerations

  • Store API keys and credentials securely
  • Use environment variables for sensitive configuration
  • Consider network security for Elasticsearch access
  • Monitor query patterns and resource usage

License

MIT License - See LICENSE file for details.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Playwright McpPlaywright MCP server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
CursorThe AI Code Editor
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Serper MCP ServerA Serper MCP Server
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Amap Maps高德地图官方 MCP Server
WindsurfThe new purpose-built IDE to harness magic
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
DeepChatYour AI Partner on Desktop
ChatWiseThe second fastest AI chatbot™
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code