MCP-RAG Server
# MCP-RAG: Model Context Protocol with RAG 🚀
A powerful and efficient RAG (Retrieval-Augmented Generation) implementation using GroundX and OpenAI, built with Modern Context Processing (MCP).
## 🌟 Features
- **Advanced RAG Implementation**: Utilizes GroundX for high-accuracy document retrieval
- **Model Context Protocol**: Seamless integration with MCP for enhanced context handling
- **Type-Safe**: Built with Pydantic for robust type checking and validation
- **Flexible Configuration**: Easy-to-customize settings through environment variables
- **Document Ingestion**: Support for PDF document ingestion and processing
- **Intelligent Search**: Semantic search capabilities with scoring
## 🛠️ Prerequisites
- Python 3.12 or higher
- OpenAI API key
- GroundX API key
- MCP CLI tools
## 📦 Installation
1. Clone the repository:
```bash
git clone <repository-url>
cd mcp-rag
```
2. Create and activate a virtual environment:
```bash
uv sync
source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
```
## ⚙️ Configuration
1. Copy the example environment file:
```bash
cp .env.example .env
```
2. Configure your environment variables in `.env`:
```env
GROUNDX_API_KEY="your-groundx-api-key"
OPENAI_API_KEY="your-openai-api-key"
BUCKET_ID="your-bucket-id"
```
## 🚀 Usage
### Starting the Server
Run the inspect server using:
```bash
mcp dev server.py
```
### Document Ingestion
To ingest new documents:
```python
from server import ingest_documents
result = ingest_documents("path/to/your/document.pdf")
print(result)
```
### Performing Searches
Basic search query:
```python
from server import process_search_query
response = process_search_query("your search query here")
print(f"Query: {response.query}")
print(f"Score: {response.score}")
print(f"Result: {response.result}")
```
With custom configuration:
```python
from server import process_search_query, SearchConfig
config = SearchConfig(
completion_model="gpt-4",
bucket_id="custom-bucket-id"
)
response = process_search_query("your query", config)
```
## 📚 Dependencies
- `groundx` (≥2.3.0): Core RAG functionality
- `openai` (≥1.75.0): OpenAI API integration
- `mcp[cli]` (≥1.6.0): Modern Context Processing tools
- `ipykernel` (≥6.29.5): Jupyter notebook support
## 🔒 Security
- Never commit your `.env` file containing API keys
- Use environment variables for all sensitive information
- Regularly rotate your API keys
- Monitor API usage for any unauthorized access
## 🤝 Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull RequestTDQS
Scored across 3 tools
The tools have significant overlap and unclear boundaries. Both 'process_search_query' and 'search_doc_for_rag_context' appear to handle search queries with similar inputs (query strings) and similar purposes (retrieving relevant information). While 'process_search_query' mentions GroundX and OpenAI integration and returns a structured SearchResponse, while 'search_doc_for_rag_context' returns plain text for RAG context, their core functionality is too similar, likely causing agent confusion about which to use for search tasks.
The naming is mostly consistent with a verb_noun pattern ('ingest_documents', 'process_search_query', 'search_doc_for_rag_context'), though 'search_doc_for_rag_context' is slightly verbose and includes an abbreviation (RAG). All use snake_case, and the verbs ('ingest', 'process', 'search') are appropriate for their actions, with only minor deviations from perfect consistency.
With only 3 tools, the count feels thin for a RAG server's scope, which typically involves more operations like document management (e.g., delete, list), query customization, or knowledge base maintenance. While the tools cover basic ingestion and search, the limited number may restrict agent workflows and indicate an incomplete surface, though it's not extreme.
There are significant gaps in the tool surface for a RAG server. Core operations are missing: no tools to list, update, or delete documents from the knowledge base, and no way to manage the knowledge base itself (e.g., clear or reset). The search functionality is duplicated rather than expanded, and there's no support for advanced RAG features like chunking or metadata handling, which will likely cause agent failures in complex tasks.