py-mcp-qdrant-rag
Enables semantic search and retrieval-augmented generation (RAG) using Qdrant vector database. Supports indexing documents from URLs and local directories, with flexible embedding options using Ollama or OpenAI.
README
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
git clone https://github.com/amornpan/py-mcp-qdrant-rag.git
cd py-mcp-qdrant-rag
2. Setup Conda Environment
For macOS/Linux:
# Grant permissions and run installation script
chmod +x install_conda.sh
./install_conda.sh
# Activate the environment
conda activate mcp-rag-qdrant-1.0
# Install Ollama Python client
pip install ollama
# Pull the embedding model
ollama pull nomic-embed-text
# Get Python path (save this for later configuration)
which python
For Windows:
# Create and activate environment
conda create -n mcp-rag-qdrant-1.0 python=3.11
conda activate mcp-rag-qdrant-1.0
# Install required packages
pip install ollama
# Pull the embedding model
ollama pull nomic-embed-text
# Get Python path (save this for later configuration)
where python
3. Start Qdrant Vector Database
Using Docker:
docker run -p 6333:6333 -v $(pwd)/qdrant_storage:/qdrant/storage qdrant/qdrant
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.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
Add the following configuration:
{
"mcpServers": {
"mcp-rag-qdrant-1.0": {
"command": "/path/to/conda/envs/mcp-rag-qdrant-1.0/bin/python",
"args": [
"/path/to/py-mcp-qdrant-rag/run.py",
"--mode",
"mcp"
],
"env": {
"QDRANT_URL": "http://localhost:6333",
"EMBEDDING_PROVIDER": "ollama",
"OLLAMA_URL": "http://localhost:11434"
}
}
}
}
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:
"Add documentation from https://docs.python.org/3/tutorial/"
"Index the content from https://github.com/user/repo/blob/main/README.md"
From Local Directories:
"Add all documents from /Users/username/Documents/project-docs"
"Index all files in C:\Projects\Documentation"
Searching Documentation
"Search for information about authentication methods"
"Find documentation about REST API endpoints"
"What does the documentation say about error handling?"
"Look up information on database configuration"
Managing Sources
"List all documentation sources"
"Show me what documents are indexed"
"What sources are available in the knowledge base?"
Configuration Options
Environment Variables
| Variable | Description | Default | Required |
|---|---|---|---|
QDRANT_URL |
Qdrant server URL | http://localhost:6333 |
Yes |
EMBEDDING_PROVIDER |
Embedding provider (ollama or openai) |
ollama |
Yes |
OLLAMA_URL |
Ollama server URL (if using Ollama) | http://localhost:11434 |
If using Ollama |
OPENAI_API_KEY |
OpenAI API key (if using OpenAI) | - | If using OpenAI |
COLLECTION_NAME |
Qdrant collection name | documents |
No |
CHUNK_SIZE |
Text chunk size for splitting | 1000 |
No |
CHUNK_OVERLAP |
Overlap between chunks | 200 |
No |
EMBEDDING_MODEL |
Model name for embeddings | nomic-embed-text (Ollama) or text-embedding-3-small (OpenAI) |
No |
Using OpenAI Embeddings
To use OpenAI embeddings instead of Ollama, update your configuration:
{
"mcpServers": {
"mcp-rag-qdrant-1.0": {
"command": "/path/to/python",
"args": ["/path/to/run.py", "--mode", "mcp"],
"env": {
"QDRANT_URL": "http://localhost:6333",
"EMBEDDING_PROVIDER": "openai",
"OPENAI_API_KEY": "sk-your-openai-api-key-here"
}
}
}
}
Using Qdrant Cloud
For Qdrant Cloud deployment:
{
"env": {
"QDRANT_URL": "https://your-cluster.qdrant.io",
"QDRANT_API_KEY": "your-qdrant-api-key",
"EMBEDDING_PROVIDER": "ollama",
"OLLAMA_URL": "http://localhost:11434"
}
}
Supported File Types
The system automatically processes the following file types:
- Text:
.txt,.md,.markdown,.rst - Documents:
.pdf,.docx,.doc,.odt - Code:
.py,.js,.ts,.java,.cpp,.c,.h,.go,.rs,.php,.rb,.swift - Data:
.json,.yaml,.yml,.xml,.csv - Web: 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
py-mcp-qdrant-rag/
├── run.py # Main entry point
├── mcp_server.py # MCP server implementation
├── rag_engine.py # Core RAG functionality
├── embeddings/
│ ├── base.py # Embedding provider interface
│ ├── ollama.py # Ollama embedding implementation
│ └── openai.py # OpenAI embedding implementation
├── document_loader.py # Document processing and chunking
├── requirements.txt # Python dependencies
├── install_conda.sh # Installation script (Unix)
└── tests/ # Unit tests
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:
conda activate mcp-rag-qdrant-1.0
python run.py --mode standalone
Running Tests
conda activate mcp-rag-qdrant-1.0
pytest 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 ps - Verify the port:
curl http://localhost:6333/health
"Connection refused" to Ollama
- Ensure Ollama is running:
ollama list - Check 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:
{
"env": {
"LOG_LEVEL": "DEBUG",
"QDRANT_URL": "http://localhost:6333",
"EMBEDDING_PROVIDER": "ollama"
}
}
Performance Optimization
Chunking Strategy
- Adjust
CHUNK_SIZEfor your document types - Increase
CHUNK_OVERLAPfor better context preservation - Use 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 results - Use 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-feature - Make your changes and add tests
- Commit with clear messages:
git commit -m 'Add amazing feature' - Push to your fork:
git push origin feature/amazing-feature - Open 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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。