Enables semantic search capabilities by integrating with OpenSearch-based search services, allowing for document retrieval across multiple indices with support for advanced filtering by categories, dates, tags, and metadata.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Search Serversearch for 'machine learning' in the research_papers index"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Search Server
A Model Context Protocol (MCP) server built with FastMCP that provides semantic search capabilities by integrating with an OpenSearch-based search service. This server uses Server-Sent Events (SSE) transport and includes comprehensive validation, error handling, and Docker support.
Features
✅ FastMCP Integration: Built on FastMCP framework with SSE transport
✅ Pydantic Validation: Comprehensive input/output validation
✅ Docker Support: Multi-stage Dockerfile and docker-compose configuration
✅ Retry Logic: Automatic retry with exponential backoff
✅ Structured Logging: JSON and console logging support
✅ Health Checks: Built-in health monitoring
✅ Type Safety: Full type hints throughout the codebase
✅ Security: Non-root user in Docker container
✅ Configurable: Environment-based configuration
Architecture
Prerequisites
Python 3.11+
Docker and Docker Compose (for containerized deployment)
Search service running on
search_service:8008(or configured URL)
Quick Start
Local Development
Clone the repository
cd d:\projects\DeepResearch\MCPSearchInstall dependencies
pip install -r requirements.txtConfigure environment
cp mcp/.env.example mcp/.env # Edit mcp/.env with your configurationRun the server
cd mcp python server.py
The server will start on http://0.0.0.0:8080
Docker Deployment
Build and run with Docker Compose
docker-compose up -d --buildCheck logs
docker logs -f mcp_search_serverCheck health
curl http://localhost:8080/health
Configuration
All configuration is managed through environment variables. Edit mcp/.env or set environment variables directly.
Environment Variables
Variable | Default | Description |
|
| Base URL of the search service |
|
| HTTP request timeout in seconds |
|
| Server bind address |
|
| Server port |
|
| Default user ID for requests |
|
| Logging level (DEBUG, INFO, WARNING, ERROR) |
|
| Log format (json or console) |
|
| Maximum retry attempts for failed requests |
|
| Base delay between retries in seconds |
Example .env File
Usage
Available Tools
search_documents
Search for documents in OpenSearch indices using the integrated search service.
Parameters:
query(string, required): Search query text (minimum 1 character)user_id(string, required): User identifier for trackingindices(array of strings, required): OpenSearch indices to searchfilters(object, optional): Search filterscategories(array of strings): Filter by categoriesdate_from(string): Start date (ISO format)date_to(string): End date (ISO format)tags(array of strings): Filter by tagsmetadata(object): Additional metadata filters
Returns:
Example Usage
Basic Search:
Advanced Search with Filters:
API Documentation
Search Service Integration
The MCP server communicates with a search service at http://search_service:8008/search (configurable).
Expected Search Service API:
Endpoint:
POST /searchContent-Type:
application/json
Request Body:
Response Body:
Docker
Building the Image
Running the Container
Docker Compose
The provided docker-compose.yml sets up:
MCP Search Server on port 8080
Connected to
test_networkHealth checks enabled
Automatic restart policy
Logging configuration
Start services:
Stop services:
View logs:
Development
Project Structure
Running Tests
Code Quality
The codebase follows:
PEP 8 style guidelines
Type hints throughout
Docstrings for all public functions
Pydantic for data validation
Structured logging with context
Adding New Tools
To add new MCP tools:
Define the tool function in
server.pyor create a new module inmcp/tools/Decorate with
@mcp.tool()Add proper type hints and docstrings
Update documentation in
prompts/directory
Example:
Logging
The server uses structured logging with configurable output format.
JSON Format (default for production):
Console Format (for development):
Configure via LOG_FORMAT environment variable.
Error Handling
The server implements comprehensive error handling:
Validation Errors
HTTP Errors
Connection Errors
Retry Logic
Automatic retry for 5xx errors and connection failures
Exponential backoff: 1s, 2s, 3s
Maximum 3 retry attempts (configurable)
Troubleshooting
Server Won't Start
Check if port 8080 is available:
netstat -ano | findstr :8080 # Windows lsof -i :8080 # Linux/MacVerify Python version:
python --version # Should be 3.11+Check configuration:
cat mcp/.env
Can't Connect to Search Service
Verify search service is running:
docker ps | grep search_serviceCheck network connectivity:
docker network inspect test_networkTest search service directly:
curl -X POST http://search_service:8008/search \ -H "Content-Type: application/json" \ -d '{"query":"test","user_id":"test","indices":["test"]}'
Container Issues
Check container logs:
docker logs mcp_search_serverInspect container:
docker inspect mcp_search_serverRebuild image:
docker-compose down docker-compose build --no-cache docker-compose up -d
Performance
Optimization Tips
Connection Pooling: HTTP client uses connection pooling (max 20 connections)
Timeout Configuration: Adjust
SEARCH_TIMEOUTbased on search complexityRetry Strategy: Configure
MAX_RETRIESandRETRY_DELAYfor your needsIndex Selection: Only search necessary indices to improve performance
Filter Usage: Use filters instead of including criteria in query text
Monitoring
Key metrics to monitor:
processing_time_msin search responsesHTTP request/response times
Error rates and retry attempts
Container resource usage
Security
Best Practices Implemented
✅ Non-root user in Docker container (UID 1000)
✅ No sensitive data in logs
✅ Input validation with Pydantic
✅ Timeout protection against slow requests
✅ Health check endpoints
✅ Minimal container image (python:3.11-slim)
Recommendations
Use HTTPS in production
Implement authentication/authorization
Set up rate limiting
Use secrets management for sensitive config
Regular security updates for dependencies
Contributing
Contributions are welcome! Please follow these guidelines:
Fork the repository
Create a feature branch
Make your changes with tests
Update documentation
Submit a pull request
License
[Specify your license here]
Support
For issues and questions:
Check the Troubleshooting section
Review logs:
docker logs mcp_search_serverCheck search service logs
Open an issue on GitHub
Resources
Changelog
Version 1.0.0 (2024-01-15)
Initial release
FastMCP integration with SSE transport
Search documents tool
Pydantic validation
Docker support
Comprehensive documentation
Built with ❤️ using FastMCP and Python