Elastic-Python-MCP-Server
The Elasticsearch MCP Server is a Python-based application designed to search and analyze property data using Elasticsearch. It integrates with Google Maps for geocoding and supports semantic search through Elasticsearch Serverless. The project offers extensive property search features and requires Python, Elasticsearch, and a Google Maps API key.
Elasticsearch MCP Server
This is a Python-based MCP (Model Control Protocol) server that provides an interface for searching and analyzing property data using Elasticsearch. The server was converted from a Jupyter notebook to a standalone Python script.
Watch a demo of the property search system in action:
https://github.com/user-attachments/assets/df498631-fb16-4ba5-b1fd-c14670213d73
Features
-
Property Search: Search for properties using various criteria including:
- Location (with geocoding support)
- Price range
- Number of bedrooms/bathrooms
- Square footage
- Property features
- Tax and maintenance costs
-
Geocoding Integration: Uses Google Maps API to convert location strings into geographic coordinates
-
Elasticsearch Integration:
- Connects to Elasticsearch Serverless
- Uses ELSER (Elastic Learned Sparse Encoder) for semantic search
- Supports custom search templates
Project Structure
.
├── data-ingestion/ # Scripts for setting up and populating Elasticsearch
│ ├── data/ # Local data directory for property data
│ ├── ingest-properties.py # Main ingestion script
│ ├── requirements.txt # Python dependencies
│ ├── setup.sh # Setup script
│ └── README.md # Data ingestion documentation
├── elastic_mcp_server.py # Main MCP server
├── env_config.sh # Environment configuration
├── env_config.template.sh # Environment configuration template
├── requirements.txt # Python dependencies
└── README.md # This file
Data Ingestion
Before running the MCP server, you need to set up and populate your Elasticsearch instance with property data. This is handled by the scripts in the data-ingestion
folder:
- Navigate to the data-ingestion directory:
cd data-ingestion
- Follow the setup instructions in the to:
- Set up the Python environment
- Configure Elasticsearch
- Download and ingest the property data
Requirements
- Python 3.x
- Elasticsearch Serverless instance
- Google Maps API key
- Required Python packages (see requirements.txt)
Setting Up Required Services
Creating a Google Maps API Key
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- Geocoding API
- Maps JavaScript API
- Create credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "API Key"
- Copy the generated API key
- (Optional) Restrict the API key to only the required APIs
Setting Up Elasticsearch Serverless
- Go to Elastic Cloud
- Sign up or log in to your account
- Under "Serverless projects", select "Create serverless project"
- Choose your preferred cloud provider and region
- Click "Create deployment"
- Once created, within Kibana "Getting Started" you'll get an Elastic URL
- Create an API key with the required privileges (see for details)
Environment Variables
The following environment variables need to be configured in env_config.sh
:
ES_URL
: Your Elasticsearch Serverless URLES_API_KEY
: Your Elasticsearch API keyGOOGLE_MAPS_API_KEY
: Your Google Maps API keyPROPERTIES_SEARCH_TEMPLATE
: Search template ID (default: "properties-search-template")ELSER_INFERENCE_ID
: ELSER inference endpoint ID (default: ".elser-2-elasticsearch")ES_INDEX
: Elasticsearch index name (default: "properties")MCP_PORT
: Port number for the MCP server (default: 8001)
Setup
- Clone the repository:
git clone https://github.com/sunilemanjee/Elastic-Python-MCP-Server.git
cd ELASTIC-PYTHON-MCP-SERVER
- Create and configure your environment variables:
# Copy the template file
cp env_config.template.sh env_config.sh
# Edit env_config.sh with your credentials
nano env_config.sh # or use your preferred editor
- Set up the Python virtual environment:
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
- Source your environment variables:
source env_config.sh
Running the Server
- Run the server:
./run_server.sh
The server will start on port 8001 by default. You can verify it's running by checking:
curl -v http://localhost:8001/sse
API Endpoints
The server provides several MCP tools:
get_properties_template_params
: Returns the required parameters for the properties search templategeocode_location
: Converts a location string into geographic coordinatessearch_template
: Performs property searches using the configured search template
Search Parameters
The search template supports the following parameters:
query
: Main search query (mandatory)latitude
: Geographic latitude coordinatelongitude
: Geographic longitude coordinatebathrooms
: Number of bathroomstax
: Real estate tax amountmaintenance
: Maintenance fee amountsquare_footage
: Property square footagehome_price
: Maximum home pricefeatures
: Home features (e.g., poolupdated kitchen*)
License
Copyright Elasticsearch B.V. and contributors SPDX-License-Identifier: Apache-2.0