A powerful Model Context Protocol (MCP) based Retrieval-Augmented Generation (RAG) chatbot that intelligently searches through your document knowledge base to provide accurate, context-aware responses. Built with GroundX for document storage and retrieval, and Google's Gemini AI for natural language generation.
- 🔍 Intelligent Document Search: Leverages GroundX's powerful semantic search capabilities
- 🤖 AI-Powered Responses: Uses Google Gemini 2.0 Flash for generating contextual answers
- 📚 Document Ingestion: Easy document upload and processing (PDF, TXT, DOCX, etc.)
- 🌐 Web Interface: Beautiful, responsive chat interface with real-time messaging
- 🔌 MCP Integration: Standard Model Context Protocol implementation for tool interoperability
- 🚀 RESTful API: Complete HTTP API for programmatic access
- 📊 Health Monitoring: Built-in health checks and comprehensive logging
- ⚡ Real-time Processing: Fast document search with context-aware responses
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Web Client │◄───┤ Flask Server ├───►│ MCP Server │
└─────────────────┘ └──────────────┘ └─────────────────┘
│ │
▼ ▼
┌──────────────┐ ┌─────────────────┐
│ Gemini AI │ │ GroundX │
│ (Text Gen.) │ │ (Doc Storage) │
└──────────────┘ └─────────────────┘
- Python 3.8+
- GroundX API account
- Google AI Studio API key
-
Clone the repository:
git clone https://github.com/yourusername/mcp-rag-chatbot.git cd mcp-rag-chatbot -
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp .env.example .env # Edit .env with your API keys -
Configure your
.envfile:GROUNDX_API_KEY=your_groundx_api_key_here GEMINI_API_KEY=your_gemini_api_key_here
python newserver.pyThe server will start with:
- Web Interface: http://localhost:8080
- MCP Server: Running on stdio
- API Endpoints: Available at base URL
- Open http://localhost:8080 in your browser
- Start asking questions about your documents
- The system will automatically search for relevant context and provide informed answers
The server implements standard MCP tools that can be used by any MCP-compatible client:
search_doc_for_rag_context(query: str)- Search documents for relevant contextingest_documents(local_file_path: str, file_type: str)- Add documents to knowledge base
| Variable | Description | Default |
|---|---|---|
GROUNDX_API_KEY |
GroundX API key (required) | |
GEMINI_API_KEY |
Google AI Studio API key (required) |
Serves the main chat web interface.
Main RAG endpoint for conversational queries.
Request:
{
"query": "Your question here"
}Response:
{
"answer": "AI-generated response",
"context_used": true,
"query": "Your original question"
}- fastmcp: MCP server implementation
- groundx: Document storage and retrieval
- google-generativeai: Gemini AI integration
- flask: Web server framework
- flask-cors: CORS support
- python-dotenv: Environment variable management
- Document Ingestion: Upload documents to GroundX buckets for semantic indexing
- Query Processing: User questions are processed and relevant context is retrieved
- Context Augmentation: Retrieved context is combined with the user query
- AI Generation: Gemini AI generates informed responses based on the context
- Response Delivery: Contextual answers are delivered via web interface or API
"GROUNDX_API_KEY environment variable is not set"
- Ensure your
.envfile contains the correct API key - Verify the
.envfile is in the same directory asnewserver.py
"No relevant documents found"
- Make sure documents have been ingested into your GroundX bucket
- Wait a few minutes after ingestion for documents to be indexed
- Try different query phrasings
Connection errors
- Check your internet connection
- Verify API keys are valid and have sufficient quotas
The server provides comprehensive logging. Check the console output for detailed information about:
- Document search operations
- AI response generation
- API connectivity status
- Error details