### Start Local Elasticsearch for Development Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Use the 'start-local' script to quickly set up a local Elasticsearch and Kibana instance for development and testing. This simplifies the local environment setup. ```bash # Start local Elasticsearch and Kibana using start-local script curl -fsSL https://elastic.co/start-local | sh # This starts: # - Elasticsearch at http://localhost:9200 # - Kibana at http://localhost:5601 ``` -------------------------------- ### Install mcp-proxy Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Install the mcp-proxy tool using uv. Refer to the mcp-proxy README for alternative installation methods. ```bash uv tool install mcp-proxy ``` -------------------------------- ### Install mcp-proxy Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Install the mcp-proxy tool using 'uv' to bridge Claude Desktop's stdio mode to a streamable-HTTP MCP server. ```bash # Install mcp-proxy uv tool install mcp-proxy ``` -------------------------------- ### Build Project with Cargo Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/docs/CONTRIBUTING.md Use this command to build the project using Cargo. Ensure Rust is installed. ```sh cargo build ``` -------------------------------- ### Start Local Elasticsearch Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/docs/CONTRIBUTING.md Downloads and runs a local Elasticsearch and Kibana instance using Docker. This is for development purposes only and disables HTTPS and uses basic authentication. ```bash curl -fsSL https://elastic.co/start-local | sh ``` -------------------------------- ### Build MCP Server from Source Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Instructions for building the MCP server locally, including installing Rust, cloning the repository, compiling the project, and running tests. This is for development purposes. ```bash # Install Rust using rustup curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Clone the repository git clone https://github.com/elastic/mcp-server-elasticsearch cd mcp-server-elasticsearch # Build the project cargo build # Build release version with optimizations cargo build --release # Run in stdio mode ES_URL="http://localhost:9200" ES_API_KEY="your-key" cargo run -- stdio # Run in HTTP mode ES_URL="http://localhost:9200" ES_API_KEY="your-key" cargo run -- http # Build Docker image docker build -t mcp/elasticsearch . # Run tests cargo test # Format code and check linting cargo fmt cargo clippy ``` -------------------------------- ### Run Elasticsearch MCP Server (stdio mode) Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Use this command to start the MCP server in stdio mode for direct client connections. Ensure necessary environment variables like ES_URL and ES_API_KEY are set. ```bash docker run -i --rm \ -e ES_URL \ -e ES_API_KEY \ docker.elastic.co/mcp/elasticsearch \ stdio ``` -------------------------------- ### Run Elasticsearch MCP Server in HTTP Mode Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Start the MCP server in HTTP mode using Docker. Ensure ES_URL and ES_API_KEY environment variables are set. ```bash docker run --rm \ -e ES_URL \ -e ES_API_KEY \ -p 8080:8080 \ docker.elastic.co/mcp/elasticsearch \ http ``` -------------------------------- ### MCP Tool Call: List Indices Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Example of calling the 'list_indices' MCP tool to find indices matching a pattern. The response includes index details. ```json // MCP Tool Call { "name": "list_indices", "arguments": { "index_pattern": "logs-*" } } // Response { "content": [ { "type": "text", "text": "Found 3 indices:" }, { "type": "json", "json": [ {"index": "logs-2024.01", "status": "open", "doc_count": 125000}, {"index": "logs-2024.02", "status": "open", "doc_count": 98500}, {"index": "logs-2024.03", "status": "open", "doc_count": 45200} ] } ] } // List all indices { "name": "list_indices", "arguments": { "index_pattern": "*" } } ``` -------------------------------- ### Get Shard Information (Specific Index) Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Call the get_shards tool with an index argument to retrieve shard information for a specific index. This allows targeted monitoring of shard distribution. ```json { "name": "get_shards", "arguments": { "index": "products" } } ``` -------------------------------- ### Get Elasticsearch Index Mappings Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Retrieves field mappings for a specified Elasticsearch index. Use this to understand the structure and types of data within an index. ```json { "name": "get_mappings", "arguments": { "index": "products" } } ``` -------------------------------- ### Get Shard Information (All Indices) Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Call the get_shards tool without arguments to retrieve shard information for all indices. The response includes a summary count and detailed shard data. ```json { "name": "get_shards", "arguments": {} } ``` -------------------------------- ### MCP Server Root Endpoint Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Access the root endpoint of the MCP server to get basic server information and a list of available endpoints. This is useful for initial discovery. ```bash # Root endpoint - server information curl http://localhost:8080/ # Response: # Elasticsearch MCP server. Version 0.4.6 # # Endpoints: # - streamable-http: /mcp # - sse: /mcp/sse ``` -------------------------------- ### Configure Claude Desktop with HTTP Proxy Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Configure Claude Desktop to use mcp-proxy to connect to a streamable-HTTP MCP server. This is useful for Claude Desktop free edition which only supports stdio. ```json { "mcpServers": { "elasticsearch-mcp-server": { "command": "/home/user/.local/bin/mcp-proxy", "args": [ "--transport=streamablehttp", "--header", "Authorization", "ApiKey your-api-key", "http://mcp-server-host:8080/mcp" ] } } } ``` -------------------------------- ### Run MCP Server in Stdio Mode with API Key Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Use this command to run the MCP server in stdio mode, connecting to Elasticsearch using an API key. Ensure ES_URL and ES_API_KEY environment variables are set. ```bash # Set environment variables for Elasticsearch connection export ES_URL="https://your-cluster.es.amazonaws.com:9200" export ES_API_KEY="your-api-key" # Run the MCP server container in stdio mode docker run -i --rm \ -e ES_URL \ -e ES_API_KEY \ docker.elastic.co/mcp/elasticsearch \ stdio ``` -------------------------------- ### Run MCP Server with Custom Configuration Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Execute the MCP server Docker container, mounting a custom JSON5 configuration file and providing necessary environment variables. This is useful for managing different environments. ```bash # Run with custom configuration file docker run -i --rm \ -e ES_URL="https://your-cluster.es.amazonaws.com:9200" \ -e ES_API_KEY="your-api-key" \ -v $(pwd)/elastic-mcp.json5:/config/elastic-mcp.json5 \ docker.elastic.co/mcp/elasticsearch \ stdio --config /config/elastic-mcp.json5 ``` -------------------------------- ### Run MCP Server in Stdio Mode with SSL Verification Skipped Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt For development, run the MCP server in stdio mode and skip SSL verification. Set ES_URL, ES_API_KEY, and ES_SSL_SKIP_VERIFY environment variables. ```bash # Skip SSL verification for development environments docker run -i --rm \ -e ES_URL="https://localhost:9200" \ -e ES_API_KEY="your-api-key" \ -e ES_SSL_SKIP_VERIFY="true" \ docker.elastic.co/mcp/elasticsearch \ stdio ``` -------------------------------- ### Configure Claude Desktop with MCP Server Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Add this JSON configuration to Claude Desktop to connect to an Elasticsearch MCP server via streamable HTTP. Replace placeholders with your specific values. ```json { "mcpServers": { "elasticsearch-mcp-server": { "command": "//.local/bin/mcp-proxy", "args": [ "--transport=streamablehttp", "--header", "Authorization", "ApiKey ", "http://:/mcp" ] } } } ``` -------------------------------- ### Build Docker Image Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/docs/CONTRIBUTING.md Builds the Docker image for the project. This is useful for containerized development or deployment. ```sh docker build -t mcp/elasticsearch ``` -------------------------------- ### Configure Claude Desktop for Stdio MCP Server Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Add this JSON configuration to your Claude Desktop settings to enable direct connection to the Elasticsearch MCP server via stdio. Ensure environment variables are correctly set. ```json { "mcpServers": { "elasticsearch-mcp-server": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "ES_URL", "-e", "ES_API_KEY", "docker.elastic.co/mcp/elasticsearch", "stdio" ], "env": { "ES_URL": "https://your-cluster.es.amazonaws.com:9200", "ES_API_KEY": "your-elasticsearch-api-key" } } } } ``` -------------------------------- ### Run MCP Inspector Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/docs/CONTRIBUTING.md Launches the MCP Inspector tool locally. This is part of the local testing workflow after making changes. ```bash npx @modelcontextprotocol/inspector ``` -------------------------------- ### Execute ES|QL Query with Calculations Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Executes an ES|QL query that includes calculations and data transformations. Use this for advanced analysis, including aggregations, evaluations, and rounding. ```json { "name": "esql", "arguments": { "query": "FROM sales | WHERE date >= \"2024-01-01\" | STATS total = SUM(amount), avg_amount = AVG(amount), count = COUNT(*) BY product_category | EVAL avg_rounded = ROUND(avg_amount, 2)" } } ``` -------------------------------- ### Run MCP Server in HTTP Mode with Custom Address Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Configure the MCP server to listen on a custom address and port for HTTP communication. Set the HTTP_ADDRESS environment variable. ```bash # Specify a custom address and port docker run --rm \ -e ES_URL="https://your-cluster.es.amazonaws.com:9200" \ -e ES_API_KEY="your-api-key" \ -e HTTP_ADDRESS="0.0.0.0:3000" \ -p 3000:3000 \ docker.elastic.co/mcp/elasticsearch \ http ``` -------------------------------- ### Custom MCP Server Configuration Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Configure the MCP server using a JSON5 file, allowing for environment variable interpolation for sensitive details like API keys and URLs. Ensure the configuration file is mounted into the container. ```json5 // elastic-mcp.json5 { // Configure the target Elasticsearch server "elasticsearch": { "url": "${ES_URL}", "api_key": "${ES_API_KEY:}", "username": "${ES_USERNAME:}", "password": "${ES_PASSWORD:}", "ssl_skip_verify": "${ES_SSL_SKIP_VERIFY:false}" } } ``` -------------------------------- ### Troubleshoot MCP Server Container Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Use Docker commands to inspect the running MCP server container, check its status, view logs, and test connectivity to Elasticsearch. ```bash # Check container status docker ps | grep elasticsearch-mcp-server # View container logs for troubleshooting docker logs # Test Elasticsearch connectivity from container docker exec curl -k -H "Authorization: ApiKey your-api-key" https://your-cluster:9200 ``` -------------------------------- ### Configure Claude Desktop for Elasticsearch MCP Server Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Add this JSON configuration to your Claude Desktop settings to connect to the Elasticsearch MCP server using the stdio protocol. Replace placeholders with your actual Elasticsearch cluster URL and API key. ```json { "mcpServers": { "elasticsearch-mcp-server": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "ES_URL", "-e", "ES_API_KEY", "docker.elastic.co/mcp/elasticsearch", "stdio" ], "env": { "ES_URL": "", "ES_API_KEY": "" } } } } ``` -------------------------------- ### Run MCP Server in Stdio Mode with Username/Password Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt This command runs the MCP server in stdio mode using username and password authentication for Elasticsearch. Set ES_URL, ES_USERNAME, and ES_PASSWORD environment variables. ```bash # Alternative: Use username/password authentication docker run -i --rm \ -e ES_URL="https://your-cluster.es.amazonaws.com:9200" \ -e ES_USERNAME="elastic" \ -e ES_PASSWORD="your-password" \ docker.elastic.co/mcp/elasticsearch \ stdio ``` -------------------------------- ### Execute Basic ES|QL Query Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Executes a basic ES|QL query for data analysis. Use this for SQL-like operations on Elasticsearch data, such as filtering, counting, and sorting. ```json { "name": "esql", "arguments": { "query": "FROM logs-* | WHERE status_code >= 400 | STATS error_count = COUNT(*) BY host | SORT error_count DESC | LIMIT 10" } } ``` -------------------------------- ### Test MCP Server with Local Elasticsearch Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Run the MCP server in Docker, connecting to a locally running Elasticsearch instance. This requires configuring environment variables for the local Elasticsearch connection. ```bash # Test the MCP server with local Elasticsearch docker run -i --rm \ -e ES_URL="http://host.docker.internal:9200" \ -e ES_USERNAME="elastic" \ -e ES_PASSWORD="changeme" \ -e ES_SSL_SKIP_VERIFY="true" \ docker.elastic.co/mcp/elasticsearch \ stdio ``` -------------------------------- ### Verify Elasticsearch Connectivity (API Key) Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Test connectivity from the MCP server container to your Elasticsearch cluster using an API key. Requires the API key and ES_URL. ```bash docker exec curl -k -H "Authorization: ApiKey " ``` -------------------------------- ### Check Container Status Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Verify that the Elasticsearch MCP Server container is running. The output should show the container with a status of 'Up'. ```bash docker ps | grep elasticsearch-mcp-server ``` -------------------------------- ### Verify Elasticsearch Connectivity (Basic Auth) Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Test connectivity from the MCP server container to your Elasticsearch cluster using basic authentication. Requires username and password. ```bash docker exec curl -k -u : ``` -------------------------------- ### Check Container Logs Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md View the logs of the MCP server container to diagnose any issues. Look for errors related to Elasticsearch connection, authentication, or network connectivity. ```bash docker logs ``` -------------------------------- ### Run MCP Server in HTTP Mode Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Run the MCP server in HTTP mode, recommended for web integrations and concurrent clients. This command maps port 8080 for communication. ```bash # Run the MCP server in HTTP mode on port 8080 docker run --rm \ -e ES_URL="https://your-cluster.es.amazonaws.com:9200" \ -e ES_API_KEY="your-api-key" \ -p 8080:8080 \ docker.elastic.co/mcp/elasticsearch \ http ``` -------------------------------- ### Retrieve MCP Server Information Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Fetch information about the Elasticsearch MCP server, including its version and available endpoints, by accessing the root URL. ```bash # Check server information curl http://localhost:8080/ # Response: # Elasticsearch MCP server. Version 0.4.6 # # Endpoints: # - streamable-http: /mcp # - sse: /mcp/sse ``` -------------------------------- ### Test Health Endpoint (HTTP Mode) Source: https://github.com/elastic/mcp-server-elasticsearch/blob/main/README.md Send a request to the health check endpoint when using streamable-HTTP protocol. A 'pong' response confirms the server is healthy. ```bash curl http://:8080/ping ``` -------------------------------- ### Perform Elasticsearch Search with Query DSL Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Executes a search query against an Elasticsearch index using the Query DSL. Supports filtering, sorting, and field selection. Use for complex search criteria. ```json { "name": "search", "arguments": { "index": "products", "fields": ["name", "price", "category"], "query_body": { "query": { "bool": { "must": [ {"match": {"category": "electronics"}} ], "filter": [ {"range": {"price": {"gte": 100, "lte": 500}}} ] } }, "size": 10, "sort": [{"price": "asc"}] } } } ``` -------------------------------- ### MCP SSE Endpoint (Deprecated) Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Connect to the SSE endpoint for Server-Sent Events transport. Note that this endpoint is deprecated and Streamable HTTP is recommended. ```bash # SSE endpoint (deprecated, use streamable-http) # Connect to /mcp/sse for Server-Sent Events transport curl http://localhost:8080/mcp/sse ``` -------------------------------- ### MCP Streamable HTTP Endpoint Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Interact with the recommended Streamable HTTP endpoint using POST requests to send MCP protocol messages. This is the primary method for communication. ```bash # Streamable HTTP endpoint (recommended) # POST requests to /mcp for MCP protocol messages curl -X POST http://localhost:8080/mcp \ -H "Content-Type: application/json" \ -H "Authorization: ApiKey your-api-key" \ -d '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}' ``` -------------------------------- ### Perform Elasticsearch Search with Aggregations Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Executes a search query against an Elasticsearch index to perform aggregations. Use this to analyze and summarize data, such as calculating totals or counts by category. ```json { "name": "search", "arguments": { "index": "orders", "query_body": { "size": 0, "aggs": { "sales_by_category": { "terms": {"field": "category.keyword"}, "aggs": { "total_revenue": {"sum": {"field": "total"}} } } } } } } ``` -------------------------------- ### Test MCP Server Health Endpoint Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Use curl to check the health status of the MCP server running in HTTP mode. The endpoint should respond with 'Ready'. ```bash # Test the health endpoint curl http://localhost:8080/ping # Response: Ready ``` -------------------------------- ### MCP Server Health Check Endpoints Source: https://context7.com/elastic/mcp-server-elasticsearch/llms.txt Access the server's health check endpoints to verify its operational status. These are essential for orchestration systems like Kubernetes. ```bash # Health check - ping endpoint curl http://localhost:8080/ping # Response: Ready # Readiness probe curl http://localhost:8080/_health/ready # Response: Ready # Liveness probe curl http://localhost:8080/_health/live # Response: Alive ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.