RAG-MCP

M1T8E6/RAG-MCP

3.2

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.

Tools
2
Resources
0
Prompts
0

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 token
  • base_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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Run tests and quality checks
  5. Commit your changes: git commit -am 'Add feature'
  6. Push to the branch: git push origin feature-name
  7. 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

Acknowledgments