py-mcp-qdrant-rag
A Model Context Protocol (MCP) server implementation for RAG (Retrieval-Augmented Generation) using Qdrant vector database with support for both Ollama and OpenAI embeddings.
Features
π Semantic Search: Search through stored documents using advanced semantic similarity
π Multi-Format Support: Process various document formats including PDF, TXT, MD, DOCX, and more
π Web Scraping: Add documentation directly from URLs
π Bulk Import: Import entire directories of documents at once
π§ Flexible Embeddings: Choose between Ollama (local) or OpenAI embeddings
πΎ Vector Storage: Efficient storage and retrieval using Qdrant vector database
π§ MCP Integration: Seamless integration with Claude Desktop application
β‘ Fast Retrieval: Optimized vector search for quick information retrieval
Prerequisites
Python 3.11 or higher
Conda (Miniconda or Anaconda)
Qdrant vector database
Ollama for local embeddings OR OpenAI API key
Claude Desktop application
Installation
1. Clone the Repository
2. Setup Conda Environment
For macOS/Linux:
For Windows:
3. Start Qdrant Vector Database
Using Docker:
Or using Qdrant Cloud:
Sign up at cloud.qdrant.io
Create a cluster and get your URL and API key
4. Configure Claude Desktop
Locate your Claude Desktop configuration file:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/claude/claude_desktop_config.json
Add the following configuration:
Important: Replace /path/to/... with the actual paths from your system.
5. Restart Claude Desktop
After saving the configuration, completely restart Claude Desktop to load the MCP server.
Usage
Once configured, you can interact with the RAG system directly in Claude Desktop using natural language commands.
Adding Documentation
From URLs:
From Local Directories:
Searching Documentation
Managing Sources
Configuration Options
Environment Variables
Variable | Description | Default | Required |
| Qdrant server URL |
| Yes |
| Embedding provider ( |
| Yes |
| Ollama server URL (if using Ollama) |
| If using Ollama |
| OpenAI API key (if using OpenAI) | - | If using OpenAI |
| Qdrant collection name |
| No |
| Text chunk size for splitting |
| No |
| Overlap between chunks |
| No |
| Model name for embeddings |
| No |
Using OpenAI Embeddings
To use OpenAI embeddings instead of Ollama, update your configuration:
Using Qdrant Cloud
For Qdrant Cloud deployment:
Supported File Types
The system automatically processes the following file types:
Text:
.txt,.md,.markdown,.rstDocuments:
.pdf,.docx,.doc,.odtCode:
.py,.js,.ts,.java,.cpp,.c,.h,.go,.rs,.php,.rb,.swiftData:
.json,.yaml,.yml,.xml,.csvWeb: HTML content from URLs
API Reference
Core Functions
add_documentation(url: str) -> dict
Add documentation from a web URL to the vector database.
Parameters:
url: The URL to fetch and index
Returns:
Dictionary with status and indexed chunks count
add_directory(path: str) -> dict
Recursively add all supported files from a directory.
Parameters:
path: Directory path to scan
Returns:
Dictionary with indexed files and total chunks
search_documentation(query: str, limit: int = 5) -> list
Search through stored documentation using semantic similarity.
Parameters:
query: Search query textlimit: Maximum number of results (default: 5)
Returns:
List of relevant document chunks with scores
list_sources() -> list
List all documentation sources in the database.
Returns:
List of unique source identifiers
Architecture
Project Structure
Component Overview
MCP Server: Handles communication with Claude Desktop
RAG Engine: Manages document indexing and retrieval
Embedding Providers: Abstract interface for different embedding services
Document Loader: Processes various file formats and splits text
Vector Store: Qdrant integration for efficient similarity search
Development
Running in Standalone Mode
For development and testing without Claude Desktop:
Running Tests
Adding New File Types
To support additional file types, modify the SUPPORTED_EXTENSIONS in document_loader.py and implement the corresponding parser.
Troubleshooting
Common Issues
"Path not found" Error
Ensure all paths in configuration are absolute paths
Verify Python path is from the conda environment:
which python
"Connection refused" to Qdrant
Check if Qdrant is running:
docker psVerify the port:
curl http://localhost:6333/health
"Connection refused" to Ollama
Ensure Ollama is running:
ollama listCheck the service:
curl http://localhost:11434/api/tags
Claude Desktop doesn't show MCP server
Verify JSON syntax in configuration file
Check Claude Desktop logs for errors
Ensure paths use forward slashes or escaped backslashes
Windows-Specific Issues
Path format: Use double backslashes
\\or forward slashes/Firewall: Allow ports 6333 (Qdrant) and 11434 (Ollama)
Admin rights: Run Anaconda Prompt as Administrator if needed
Debug Mode
Enable debug logging by adding to environment:
Performance Optimization
Chunking Strategy
Adjust
CHUNK_SIZEfor your document typesIncrease
CHUNK_OVERLAPfor better context preservationUse smaller chunks for technical documentation
Embedding Cache
Documents are embedded only once
Re-indexing skips unchanged files
Clear collection to force re-indexing
Search Optimization
Increase
limitparameter for more resultsUse specific technical terms for better precision
Combine searches with different phrasings
Contributing
We welcome contributions! Please follow these steps:
Fork the repository
Create a feature branch:
git checkout -b feature/amazing-featureMake your changes and add tests
Commit with clear messages:
git commit -m 'Add amazing feature'Push to your fork:
git push origin feature/amazing-featureOpen a Pull Request
Development Guidelines
Follow PEP 8 style guide
Add unit tests for new features
Update documentation as needed
Ensure all tests pass before submitting
Security Considerations
API Keys: Never commit API keys to version control
File Access: The system only accesses explicitly provided paths
Network: Ensure Qdrant and Ollama are not exposed to public internet
Sensitive Data: Be cautious when indexing confidential documents
License
This project is provided for educational purposes. See the LICENSE file for details.
Acknowledgments
Anthropic for the Model Context Protocol
Qdrant for the excellent vector database
Ollama for local LLM infrastructure
OpenAI for embedding models
Support
For questions, issues, or feature requests:
Open an issue: GitHub Issues
Check existing issues before creating new ones
Provide detailed information for bug reports
Made with β€οΈ by amornpan