Labsco
M0-AR logo

Custom Elasticsearch

from M0-AR

A simple MCP server for Elasticsearch, designed for cloud environments where your public key is already authorized.

๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredAdvanced setup

Custom Elasticsearch MCP Server

A simple MCP (Model Context Protocol) server for Elasticsearch designed for cloud environments where your public key is already authorized on the server.

Why This Custom Version?

No API Key Required - Unlike the official Elasticsearch MCP server that requires both ES_URL and ES_API_KEY, this version only needs the URL since your public key is already trusted on the cloud server.

Enhanced Tools - Better usability with optional parameters and improved defaults compared to the official version.

What This Does

This MCP server connects Cursor to your Elasticsearch cluster with 4 powerful tools:

  • list_indices - List all indices (optional pattern filter)
  • search - Full Elasticsearch Query DSL support
  • get_mappings - Get field mappings for any index
  • get_shards - View cluster shard information

Comparison with Official Server

FeatureOfficial ServerThis Custom Server
AuthenticationRequires ES_URL + ES_API_KEYOnly needs ES_URL (public key authorized)
list_indicesRequires indexPattern parameterOptional parameter with "*" default
Tools Available4 tools (same functions)4 tools (enhanced usability)
SecurityAPI key basedPublic key authorization
ConcurrencySynchronous blockingAsync with connection pooling
PerformanceSingle request at a time100+ concurrent requests

Concurrent Request Handling

This MCP server is designed to handle multiple parallel requests from multiple applications simultaneously using industry best practices:

Key Features:

โœ… Async/Await Architecture - Non-blocking I/O for parallel request processing โœ… Connection Pooling - Reuses HTTP connections (up to 100 concurrent) โœ… HTTP/2 Support - Multiplexes multiple requests over single connection โœ… Configurable Limits - Adjust connection limits for your workload โœ… Thread-Safe - FastMCP handles concurrent tool execution safely

Performance Characteristics:

  • Default: 100 concurrent connections, 20 keepalive connections
  • Scalable: Configure up to 1000+ concurrent connections
  • Efficient: Connection reuse reduces latency by ~50%
  • Reliable: Proper timeout handling prevents connection exhaustion

Configuration for High Traffic:

{
    "mcpServers": {
        "elasticsearch-custom": {
            "command": "docker",
            "args": [
                "run", "-i", "--rm",
                "--add-host=host.docker.internal:host-gateway",
                "-e", "ES_URL=http://host.docker.internal:9400",
                "-e", "MAX_CONNECTIONS=200",
                "-e", "MAX_KEEPALIVE_CONNECTIONS=50",
                "-e", "CONNECTION_TIMEOUT=60",
                "-e", "REQUEST_TIMEOUT=60",
                "elasticsearch-mcp:latest"
            ]
        }
    }
}

Testing Concurrent Requests:

# Test 10 parallel requests
for i in {1..10}; do
    echo '{"jsonrpc": "2.0", "id": '$i', "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}' | \
    python3 simple_elasticsearch_mcp.py &
done
wait

Files

  • simple_elasticsearch_mcp.py - Main MCP server
  • Dockerfile - Container build instructions
  • requirements.txt - Python dependencies

Manual Testing

Test the server directly:

python3 simple_elasticsearch_mcp.py

Test with JSON-RPC commands:

1. List all tools:

echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | python3 simple_elasticsearch_mcp.py

2. List all indices:

echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}' | python3 simple_elasticsearch_mcp.py

3. Search for data:

echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "search", "arguments": {"index": "hq.sales", "queryBody": {"query": {"match_all": {}}, "size": 3}}}}' | python3 simple_elasticsearch_mcp.py

4. Get index mappings:

echo '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_mappings", "arguments": {"index": "hq.menuitems"}}}' | python3 simple_elasticsearch_mcp.py

5. Check cluster shards:

echo '{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "get_shards", "arguments": {}}}' | python3 simple_elasticsearch_mcp.py

Set custom Elasticsearch URL:

ES_URL="http://your-es-host:9200" python3 simple_elasticsearch_mcp.py

That's It!

Build โ†’ Add to config โ†’ Restart Cursor โ†’ Done! ๐Ÿš€