Custom Elasticsearch
About
A simple MCP server for Elasticsearch, designed for cloud environments where your public key is already authorized.
Details
- Author
- m0-ar
- Categories
- Search, Other, Database
- Tags
- #elasticsearch, #data-analysis
Jump to
Setup
Install Custom Elasticsearch in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/m0-ar/Custom-Elasticsearch-MCP-Server
Follow the installation instructions in the repository README, then restart your MCP client.
A simple MCP (Model Context Protocol) server for Elasticsearch designed for cloud environments where your public key is already authorized on the server.
No API Key Required- Unlike the official Elasticsearch MCP server that requires bothES_URLandES_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.
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
git clone https://github.com/M0-AR/Custom-Elasticsearch-MCP-Server.git cd Custom-Elasticsearch-MCP-Server docker build -t elasticsearch-mcp:latest .
{ "mcpServers": { "elasticsearch-custom": { "command": "docker", "args": [ "run", "-i", "--rm", "--add-host=host.docker.internal:host-gateway", "-e", "ES_URL=http://host.docker.internal:9400", "elasticsearch-mcp:latest" ] } } }
Close and reopen Cursor. You should see the elasticsearch-custom server with 4 tools enabled.
- ES_URL- Your Elasticsearch URL (default:http://localhost:9400)
- MAX_CONNECTIONS- Maximum concurrent connections (default:100)
- MAX_KEEPALIVE_CONNECTIONS- Maximum keepalive connections (default:20)
- CONNECTION_TIMEOUT- Connection timeout in seconds (default:30)
- REQUEST_TIMEOUT- Request timeout in seconds (default:30)
"ES_URL=http://host.docker.internal:9200"
"MAX_CONNECTIONS=200", "MAX_KEEPALIVE_CONNECTIONS=50", "CONNECTION_TIMEOUT=60", "REQUEST_TIMEOUT=60"
- List all indices:"Show me all elasticsearch indices"
- Search data:"Search for sales data in hq.sales index"
- Get mappings:"What fields are in the hq.menuitems index?"
- Check cluster:"Show me the elasticsearch cluster status"
This MCP server is designed to handle multiple parallel requests from multiple applications simultaneously using industry best practices:
✅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
- 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
{ "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" ] } } }
# 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
- simple_elasticsearch_mcp.py- Main MCP server
- Dockerfile- Container build instructions
- requirements.txt- Python dependencies
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | python3 simple_elasticsearch_mcp.py
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}' | python3 simple_elasticsearch_mcp.py
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
echo '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "get_mappings", "arguments": {"index": "hq.menuitems"}}}' | python3 simple_elasticsearch_mcp.py
echo '{"jsonrpc": "2.0", "id": 5, "method": "tools/call", "params": {"name": "get_shards", "arguments": {}}}' | python3 simple_elasticsearch_mcp.py
ES_URL="http://your-es-host:9200" python3 simple_elasticsearch_mcp.py
❌ "Connection refused" or "timed out" errors
Root Cause:The most common issue is Docker container networking when Elasticsearch is accessible via SSH tunnel.
Solution:Ensure these requirements are met:
If your Elasticsearch is behind SSH tunnel (common for cloud deployments):
# Start SSH tunnel to forward port 9400 ssh -L 9400:localhost:9400 -N -f -l username your-server-ip # Verify tunnel is working curl -X GET "localhost:9400/_cluster/health?pretty"
Yourmcp.jsonshould useexactlythis configuration:
"elasticsearch-custom": { "command": "docker", "args": [ "run", "-i", "--rm", "--add-host=host.docker.internal:host-gateway", "-e", "ES_URL=http://host.docker.internal:9400", "elasticsearch-mcp:latest" ] }
- ✅ Use--add-host=host.docker.internal:host-gateway(not IP addresses)
- ✅ UseES_URL=http://host.docker.internal:9400(not localhost)
- ✅ SSH tunnel must be running before starting Cursor
# Test if Docker can reach your Elasticsearch docker run --rm --add-host=host.docker.internal:host-gateway alpine/curl \ curl -s http://host.docker.internal:9400/_cluster/health
Test the full MCP workflow with this comprehensive command:
# Full MCP server test with proper initialization { echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}'; echo '{"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}}'; echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}'; } | docker run -i --rm --add-host=host.docker.internal:host-gateway -e ES_URL="http://host.docker.internal:9400" elasticsearch-mcp:latest
- Initialization response with server info
- List of all Elasticsearch indices in JSON format
- No error messages
Ifhost-gatewaydoesn't work, try network host mode:
"args": [ "run", "-i", "--rm", "--network=host", "-e", "ES_URL=http://localhost:9400", "elasticsearch-mcp:latest" ]
❌ "Received request before initialization was complete"
Root Cause:MCP protocol requires proper initialization sequence.
Solution:Always initialize before calling tools:
# Correct sequence: echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0"}}}' echo '{"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}}' echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "list_indices", "arguments": {}}}'
Build → Add to config → Restart Cursor → Done! 🚀
Search global news using natural language. Webz.io News Search API returns the most relevant articles and content, with filters for source, country, language, date, sentiment, and category.
Interact with an Elasticsearch cluster via the Model Context Protocol (MCP), enabling clients to query, manage, and analyze data.
An MCP server for interacting with Elasticsearch clusters, enabling LLM-powered applications to search, update, and manage data.
By connecting to Baselight, you can browse, discover, and query 70,000+ datasets and 450+ billion rows directly from your preferred environment—whether you’re building, analysing, or exploring.
Unified MCP server giving AI coding agents direct access to your databases: 70+ SQL databases via SqlKit (PostgreSQL, MySQL, SQL Server, SQLite, ClickHouse, Snowflake, BigQuery) and NoSQL via DocKit (Elasticsearch, MongoDB, DynamoDB). Local-first: credentials never leave your machine, read-only by default, 79 tools.
Query and export data from various databases including ElasticSearch, MySQL, PostgreSQL, Oracle, and SQLite.
Connect to and interact with an Elasticsearch cluster directly from any MCP client using environment variables for configuration.
Connects agents to Elasticsearch data, enabling natural language interaction with indices.
Manage Elasticsearch indices and execute queries using LLMs.
An MCP Server for interacting with Elasticsearch and OpenSearch clusters.
Access OSDU platform capabilities including search, data management, and schema operations.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.




