M1T8E6/RAG-MCP
If you are the rightful owner of RAG-MCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The RAG MCP Server is a Model Context Protocol server designed to provide Retrieval-Augmented Generation capabilities for document querying, enabling AI assistants to perform intelligent queries on document databases and retrieve contextual answers with source information.
RAG MCP Server
A Model Context Protocol (MCP) server that provides RAG (Retrieval-Augmented Generation) capabilities for document querying. This server enables AI assistants to perform intelligent queries on your document database and retrieve contextual answers with source information.
Features
- š Intelligent Document Querying: Perform semantic search on your document collection
- š Source Attribution: Get references to source documents with relevance scores
- š Secure Authentication: Token-based authentication for API access
- ā” Async Performance: Built with async/await for high-performance operations
- š ļø MCP Integration: Seamless integration with MCP-compatible AI assistants
- š§ Configurable: Flexible configuration options for different RAG backends
Installation
Prerequisites
- Python 3.10 or higher
- pip or uv package manager
Using pip
# Clone the repository
git clone https://github.com/yourusername/rag-mcp.git
cd rag-mcp-server
# Install dependencies
pip install -e .
Using uv (recommended)
# Clone the repository
git clone https://github.com/yourusername/rag-mcp.git
cd rag-mcp
# Install with uv
uv sync
Configuration
Environment Variables
Create a .env
file in the project root:
# RAG API Configuration
RAG_API_TOKEN=your_api_token_here
RAG_BASE_URL=https://your-rag-service.com/api-path
# Optional: Logging level
LOG_LEVEL=INFO
Configuration Options
RAG_API_TOKEN
: Your API token for RAG service authentication (required)RAG_BASE_URL
: Base URL for your RAG API service (optional, defaults to placeholder)
Usage
Running the Server
Direct execution
python src/server.py
Using the Makefile
make run
MCP Integration
Add this server to your MCP client configuration:
{
"mcpServers": {
"rag-server": {
"command": "python",
"args": ["/path/to/rag-mcp-server/src/server.py"],
"env": {
"RAG_API_TOKEN": "your_api_token_here",
"RAG_BASE_URL": "https://your-rag-service.com/api-path"
}
}
}
}
Available Tools
configure_rag
Configure the RAG tools with your API credentials.
Parameters:
api_token
(string, required): Your RAG API tokenbase_url
(string, optional): Base URL for the RAG service
Example:
{
"api_token": "your_api_token_here",
"base_url": "https://your-rag-service.com/api-path"
}
rag_docs
Perform intelligent queries on your document database with source attribution.
Parameters:
query
(string, required): The question to ask the RAG system
Example:
{
"query": "What are the main features of our product?"
}
Response includes:
- Generated answer based on your documents
- Source document references with relevance scores
- Content snippets from relevant documents
API Integration
The server expects your RAG API to follow this interface:
Request Format
{
"query": "Your question here",
}
Response Format
{
"answer": "Generated response",
"sources": [
{
"document": "document_name.pdf",
"score": 0.95,
"content": "Relevant text snippet..."
}
]
}
Development
Setting up Development Environment
# Install development dependencies
pip install -e ".[dev]"
# Or with uv
uv sync --group dev
Code Quality
The project uses several tools for code quality:
- Black: Code formatting
- Ruff: Linting and import sorting
- MyPy: Type checking
- pytest: Testing
Run quality checks:
# Format code
black src/
# Lint code
ruff check src/
# Type checking
mypy src/
# Run tests
pytest
Project Structure
āāā src/
ā āāā __init__.py
ā āāā server.py # Main MCP server
ā āāā tools/
ā āāā __init__.py
ā āāā base.py # Base tool class
ā āāā rag_tools.py # RAG tool implementation
āāā pyproject.toml # Project configuration
āāā Makefile # Build commands
āāā README.md # This file
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Make your changes
- Run tests and quality checks
- Commit your changes:
git commit -am 'Add feature'
- Push to the branch:
git push origin feature-name
- Submit a pull request
Code Style
- Follow PEP 8 guidelines
- Use type hints
- Write docstrings for all public functions
- Keep functions focused and small
- Add tests for new features
Troubleshooting
Common Issues
"RAG tools not configured" error
- Make sure to call the
configure_rag
tool first with your API token
Connection timeout errors
- Check that your
RAG_BASE_URL
is correct and accessible - Verify your network connection
- Ensure the RAG service is running
Authentication failures
- Verify your
RAG_API_TOKEN
is valid - Check that the token has appropriate permissions
Debug Mode
Enable debug logging by setting the environment variable:
export LOG_LEVEL=DEBUG
License
This project is licensed under the MIT License - see the file for details.
Support
- š§ Email: andreoni.matteo@proton.me
Acknowledgments
- Built with Model Context Protocol