elasticsearch-mcp

elasticsearch-mcp

Enables secure and efficient interaction with Elasticsearch clusters through the Model Context Protocol, providing tools for data management, search, and export.

Category
Visit Server

README

Elasticsearch MCP

Model Context Protocol server for Elasticsearch integration with comprehensive security and performance features

npm version TypeScript Elasticsearch License: MIT

elasticsearch-mcp is a Model Context Protocol (MCP) server that provides standardized, secure tools for interacting with Elasticsearch clusters. Built with TypeScript and optimized for Elastic Cloud environments, it offers comprehensive data management capabilities with enterprise-grade security features.

πŸš€ Features

  • πŸ” Secure by Design: Input validation, script sanitization, injection prevention
  • ☁️ Elastic Cloud Ready: Native support for cloud ID and API key authentication
  • ⚑ High Performance: Streaming for large datasets, connection pooling, health monitoring
  • πŸ› οΈ Comprehensive Tools: 7 essential tools covering all major Elasticsearch operations
  • πŸ“Š Advanced Querying: Full Elasticsearch DSL support with aggregations and highlighting
  • πŸ“ Data Export: Stream large datasets to CSV with compression support
  • πŸ” Smart Validation: Zod-based schemas with security-first validation
  • πŸ“ Full TypeScript: Complete type safety with strict null checks

πŸ“¦ Installation

npm install elasticsearch-mcp

πŸƒβ€β™‚οΈ Quick Start

1. Basic Setup

# Set your Elasticsearch credentials
export ELASTIC_CLOUD_ID="your-cloud-id"
export ELASTIC_API_KEY="your-api-key"

# Start the MCP server
npx elasticsearch-mcp

2. Using with Claude Desktop

Add to your Claude Desktop MCP configuration:

{
  "mcpServers": {
    "elasticsearch-mcp": {
      "command": "npx",
      "args": ["elasticsearch-mcp"],
      "env": {
        "ELASTIC_CLOUD_ID": "your-cloud-id",
        "ELASTIC_API_KEY": "your-api-key"
      }
    }
  }
}

3. Using with any MCP Client

import { ElasticMCPServer } from 'elasticsearch-mcp';

const server = new ElasticMCPServer();
await server.start();

πŸ› οΈ Available Tools

Tool Description Use Cases
fetch_indices List and filter Elasticsearch indices Index management, monitoring
search_elasticsearch Advanced search with aggregations Data analysis, querying
create_index Create indices with mappings/settings Schema management
insert_data Insert documents with validation Data ingestion
update_document Update documents with scripts Data modification
delete_document Delete by ID or query Data cleanup
export_to_csv Stream data to CSV files Reporting, data export

πŸ“‹ Tool Examples

Search with Aggregations

{
  "tool": "search_elasticsearch",
  "arguments": {
    "index": "sales-data",
    "query": {
      "range": {
        "date": {
          "gte": "2024-01-01",
          "lte": "2024-12-31"
        }
      }
    },
    "aggregations": {
      "monthly_sales": {
        "date_histogram": {
          "field": "date",
          "calendar_interval": "month"
        },
        "aggs": {
          "total_revenue": {
            "sum": { "field": "amount" }
          }
        }
      }
    }
  }
}

Export Large Dataset

{
  "tool": "export_to_csv",
  "arguments": {
    "index": "user-analytics",
    "query": {
      "bool": {
        "filter": [
          { "term": { "status": "active" } },
          { "range": { "last_login": { "gte": "2024-01-01" } } }
        ]
      }
    },
    "fields": ["user_id", "email", "last_login", "country"],
    "filename": "active_users_2024.csv",
    "compress": true,
    "maxRows": 100000
  }
}

Create Index with Schema

{
  "tool": "create_index",
  "arguments": {
    "name": "product-catalog",
    "mappings": {
      "properties": {
        "name": { "type": "text", "analyzer": "standard" },
        "price": { "type": "float" },
        "category": { "type": "keyword" },
        "created_at": { "type": "date" },
        "tags": { "type": "keyword" },
        "description": { "type": "text" }
      }
    },
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1,
      "analysis": {
        "analyzer": {
          "product_analyzer": {
            "type": "standard",
            "stopwords": "_english_"
          }
        }
      }
    },
    "aliases": ["products", "catalog"]
  }
}

βš™οΈ Configuration

Environment Variables

Variable Description Required Example
ELASTIC_CLOUD_ID Elastic Cloud deployment ID Yes* deployment:dXMtY2VudHJhbDE=
ELASTIC_API_KEY Elasticsearch API key Yes* VnVhQ2ZHY0JDZGJrU...
ELASTIC_NODE Self-hosted Elasticsearch URL Yes* https://localhost:9200
ELASTIC_USERNAME Basic auth username No elastic
ELASTIC_PASSWORD Basic auth password No changeme
LOG_LEVEL Logging level No info
LOG_FORMAT Log output format No text
MAX_CONCURRENT_REQUESTS Request concurrency limit No 10

*Either ELASTIC_CLOUD_ID or ELASTIC_NODE is required

Configuration File

Create .env file:

# Elastic Cloud (recommended)
ELASTIC_CLOUD_ID=your-deployment-id
ELASTIC_API_KEY=your-api-key

# Logging
LOG_LEVEL=info
LOG_FORMAT=json

# Performance
MAX_CONCURRENT_REQUESTS=10
REQUEST_TIMEOUT_MS=30000

πŸ”’ Security Features

Input Validation

  • Zod Schemas: Strict type validation for all inputs
  • Field Name Validation: Prevents reserved field usage
  • Size Limits: Document size, array length, string length limits
  • Depth Validation: Prevents deeply nested objects/queries

Script Security

  • Script Sanitization: Blocks dangerous script patterns
  • Parameter Validation: Validates script parameters
  • Execution Limits: Prevents resource exhaustion

Query Security

  • Injection Prevention: Sanitizes and validates all queries
  • Script Query Blocking: Prevents script-based queries in sensitive operations
  • Rate Limiting: Protects against abuse

Data Protection

  • Credential Masking: Never logs sensitive information
  • Secure Connections: TLS/SSL support
  • Access Control: Validates permissions before operations

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   MCP Client    │◄──►│Elasticsearch MCP│◄──►│  Elasticsearch  β”‚
β”‚  (Claude, etc.) β”‚    β”‚     Server      β”‚    β”‚    Cluster      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Tools     β”‚
                       β”‚             β”‚
                       β”‚ β€’ fetch     β”‚
                       β”‚ β€’ search    β”‚
                       β”‚ β€’ create    β”‚
                       β”‚ β€’ insert    β”‚
                       β”‚ β€’ update    β”‚
                       β”‚ β€’ delete    β”‚
                       β”‚ β€’ export    β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Performance

Benchmarks

  • Search: <500ms average response time
  • Large Exports: 10K+ documents/second with streaming
  • Memory Usage: <100MB for typical operations
  • Concurrent Requests: Up to 10 simultaneous operations

Optimization Features

  • Connection Pooling: Reuses Elasticsearch connections
  • Streaming: Memory-efficient processing of large datasets
  • Compression: Reduces export file sizes by 70%+
  • Health Monitoring: Automatic reconnection on failures

πŸ”§ Development

Setup Development Environment

# Clone repository
git clone https://github.com/RajwardhanShinde/elk-mcp.git
cd elk-mcp

# Install dependencies
npm install

# Set up environment
cp .env.example .env
# Edit .env with your Elasticsearch credentials

# Run in development mode
npm run dev

# Run tests
npm test

# Build for production
npm run build

Project Structure

elasticsearch-mcp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ tools/           # MCP tool implementations
β”‚   β”œβ”€β”€ elasticsearch/   # ES client and connection management
β”‚   β”œβ”€β”€ validation/      # Input validation schemas
β”‚   β”œβ”€β”€ errors/          # Error handling utilities
β”‚   β”œβ”€β”€ config.ts        # Configuration management
β”‚   β”œβ”€β”€ logger.ts        # Structured logging
β”‚   └── server.ts        # Main MCP server
β”œβ”€β”€ tests/               # Comprehensive test suite
β”œβ”€β”€ docs/                # Documentation
└── build/               # Compiled output

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Ensure all tests pass
  5. Submit a pull request

πŸ“š Documentation

πŸ› Troubleshooting

Common Issues

Connection Failed

# Check credentials
echo $ELASTIC_CLOUD_ID
echo $ELASTIC_API_KEY

# Test connection
curl -H "Authorization: ApiKey $ELASTIC_API_KEY" \\
     "$ELASTIC_NODE/_cluster/health"

Permission Denied

  • Ensure API key has required privileges
  • Check index permissions
  • Verify cluster access

Tool Validation Errors

  • Check input parameter types
  • Validate required fields
  • Review field name restrictions

See Troubleshooting Guide for more details.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🏷️ Version History

  • v0.1.0 - Initial release with 7 core tools
  • Full changelog: CHANGELOG.md

πŸ”— Links


Built with ❀️ for the Elasticsearch and MCP communities

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured