A Model Context Protocol (MCP) server for OpenSearch that provides seamless integration between LangChain agents and OpenSearch, enabling natural language search and data analysis capabilities.
OpenSearch MCP Server provides the following key features:
- Natural Language Search: Perform OpenSearch queries using natural language through GPT models
- Index Management: List indices, view mapping information, and manage data structures
- Real-time Search: Convert complex search queries from natural language to OpenSearch queries
- Docker-based Deployment: Easy installation and execution through docker-compose
- Docker and Docker Compose
- Python 3.10+ (for running the agent)
- OpenAI API key (for GPT model usage)
OpenSearch MCP Server
├── opensearch/ # OpenSearch configuration files
│ └── opensearch.yml # OpenSearch configuration
├── scripts/ # Initialization scripts
│ └── enable-mcp-server.sh # MCP server activation script
├── agents/ # LangChain agents
│ ├── agent.py # Main agent script
│ ├── requirements.txt # Python dependencies
│ └── .env # Environment variables
├── img/ # Documentation images
│ └── screenshot.png # Example screenshot
├── docker-compose.yml # Docker Compose configuration
└── Dockerfile # Custom OpenSearch image
- OpenSearch: Search engine (port 9200)
- OpenSearch Dashboards: Web UI (port 5601)
- MCP Server: Bridge between OpenSearch and LangChain
- LangChain Agent: Natural language processing agent
# Clone the repository
git clone https://github.com/capelabs/opensearch-mcp-server.git
cd opensearch-mcp-server
# Start services with Docker Compose
docker-compose up -dcd agents
# Create and activate virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Linux/Mac
# or venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txtSet your OpenAI API key in the agents/.env file:
OPENAI_API_KEY=your_openai_api_key_here# Start all services with Docker Compose
docker-compose up -d
# Check service status
docker psAfter OpenSearch is fully started, the MCP server will be automatically activated. You can verify this with the following commands:
# Check OpenSearch cluster settings
curl -X GET "localhost:9200/_cluster/settings?pretty"Open a web browser and navigate to http://localhost:5601 to open the OpenSearch dashboard and add sample data.
You can add any sample data you like, In this case Sample flight data in this README.
cd agents
python agent.pyOnce the agent is running, you can ask questions in natural language:
Input: Show me all indices
Input: What's the mapping for the user index?
Input: Find users where name is "john"
Input: Search for logs from the last 24 hours
- ListIndexTool: Retrieve list of all indices
- IndexMappingTool: Get mapping information for specific indices
- SearchIndexTool: Execute complex search queries
We welcome contributions to the project! Please follow these steps:
# Fork and clone the repository
git clone https://github.com/your-username/opensearch-mcp-server.git
cd opensearch-mcp-server
# Create a development branch
git checkout -b feature/your-feature-name- Python code should follow PEP 8 style guidelines
- Docker-related files should include clear comments
- New features should be submitted with appropriate test code
- Write clear commit messages describing your changes
- Update documentation for new features
- Ensure all tests pass
- Create a Pull Request and request review
Please submit bugs or feature requests through GitHub Issues. Include the following information:
- Clear description of the issue
- Steps to reproduce
- Expected vs actual results
- Environment information (OS, Docker version, etc.)
This project is distributed under the MIT License.
# Check OpenSearch container logs
docker-compose logs opensearch
# Check for port conflicts
netstat -tulpn | grep :9200# Restart MCP activation script
docker-compose restart enable_mcp_server# Reinstall dependencies
pip install --upgrade -r requirements.txt
# Verify OpenAI API key
echo $OPENAI_API_KEY- For large datasets, adjust JVM heap memory size in
opensearch.yml - Enable security plugins for production environments
- Optimize index shard and replica settings
For questions or suggestions, please reach out through GitHub Issues.