Elasticsearch MCP Server
A Model Context Protocol (MCP) server for Elasticsearch, providing core Elasticsearch functionality through MCP tools.
Features
- Search Operations: Perform full-text search, term queries, and complex aggregations
- Index Management: Create, delete, and manage Elasticsearch indices
- Document Operations: Index, update, delete, and retrieve documents
- Cluster Information: Get cluster health, stats, and node information
- Mapping Management: Create and manage index mappings
- Template Management: Manage index templates and component templates
Installation
From PyPI
pip install mcp-server-elasticsearch
From Source
git clone https://github.com/your-username/mcp-server-elasticsearch.git
cd mcp-server-elasticsearch
pip install -e .
Configuration
Create a configuration file (e.g., elastic-mcp.json5) with your Elasticsearch connection details:
{
"elasticsearch": {
"hosts": ["http://localhost:9200"],
"username": "your_username", // optional
"password": "your_password", // optional
"api_key": "your_api_key", // optional, alternative to username/password
"verify_certs": true,
"ca_certs": "/path/to/ca.pem", // optional
"timeout": 30
},
"server": {
"host": "localhost",
"port": 8000,
"log_level": "INFO"
}
}
Usage
As a Standalone Server
# Using configuration file
elasticsearch-mcp-server --config elastic-mcp.json5
# Using environment variables
export ELASTICSEARCH_HOSTS=http://localhost:9200
export ELASTICSEARCH_USERNAME=your_username
export ELASTICSEARCH_PASSWORD=your_password
elasticsearch-mcp-server
As a Python Module
from elasticsearch_mcp_server import ElasticsearchMCPServer, ElasticsearchConfig
# Load configuration
config = ElasticsearchConfig.from_file("elastic-mcp.json5")
# Create and run server
server = ElasticsearchMCPServer(config)
await server.run_stdio()
Environment Variables
You can configure the server using environment variables:
ELASTICSEARCH_HOSTS: Comma-separated list of Elasticsearch hostsELASTICSEARCH_USERNAME: Username for authenticationELASTICSEARCH_PASSWORD: Password for authenticationELASTICSEARCH_API_KEY: API key for authentication (alternative to username/password)ELASTICSEARCH_VERIFY_CERTS: Whether to verify SSL certificates (default: true)ELASTICSEARCH_CA_CERTS: Path to CA certificate fileELASTICSEARCH_TIMEOUT: Request timeout in seconds (default: 30)
Available Tools
The server provides the following MCP tools:
Search Operations
search: Perform search queries with various parametersmsearch: Execute multiple search requestscount: Count documents matching a query
Document Operations
index_document: Index a single documentget_document: Retrieve a document by IDupdate_document: Update a documentdelete_document: Delete a documentbulk_operations: Perform bulk operations
Index Management
create_index: Create a new indexdelete_index: Delete an indexget_index_info: Get index informationlist_indices: List all indices
Mapping Management
put_mapping: Create or update index mappingget_mapping: Retrieve index mapping
Cluster Operations
cluster_health: Get cluster health statuscluster_stats: Get cluster statisticsnode_info: Get node information
Requirements
- Python 3.12+
- Elasticsearch 8.0+
Dependencies
elasticsearch>=8.0.0,<9.0.0mcp>=1.0.0pydantic>=2.0.0pydantic-settings>=2.0.0click>=8.0.0aiohttp>=3.8.0python-dotenv>=1.0.0pyjson5>=1.6.0structlog>=23.0.0anyio>=4.0.0uvicorn>=0.24.0starlette>=0.27.0
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues or have questions, please file an issue on the GitHub repository.
Metadata
Release files for sugon-mcp-server-elasticsearch 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sugon_mcp_server_elasticsearch-0.1.1.tar.gz | 15.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sugon_mcp_server_elasticsearch-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.6 kB
Release files / sugon_mcp_server_elasticsearch-0.1.1.tar.gz
| Download URL | sugon_mcp_server_elasticsearch-0.1.1.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2eec579f236b43eb1d5ea7ef52413d9a012656dea8a7d65537f7e2d7d4f22c86
|
|
BLAKE2b-256 checksum How to use checksums |
5a0b831c6d0b23d851fb78a572cc8e00115b1341987cc86982aff77de28cf96e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / sugon_mcp_server_elasticsearch-0.1.1-py3-none-any.whl
| Download URL | sugon_mcp_server_elasticsearch-0.1.1-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0513da718739ecaba8c8cb07f9a8231ff891bd723143f2473a7fba690b2f8d9d
|
|
BLAKE2b-256 checksum How to use checksums |
0efa93ae0c77f8a8954294f79c7aac6d87d6387d5472d7d7c96cba97d716df7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|