A full-stack Retrieval-Augmented Generation (RAG) application built with a Model Context Protocol (MCP) server backend and a modern Next.js frontend. This project enables users to chat with their documents (PDFs) using OpenAI's models and a vector database for context retrieval.
-
MCP Server Backend (Node.js/TypeScript)
- Implements the Model Context Protocol (MCP).
- Document Ingestion: Parses PDFs using
pypdf(Python bridge) and chunking. - Vector Search: utilizing Qdrant for high-performance similarity search.
- Embeddings: OpenAI
text-embedding-3-small. - Tools:
ingest_document(for admin/setup) andquery_knowledge_base(for RAG).
-
Next.js Frontend
- Chat Interface: Clean, responsive UI built with Tailwind CSS and
shadcn/ui. - Streaming: Real-time token streaming using Vercel AI SDK (v6).
- Input Management: Robust handling of user inputs and tool invocations.
- Chat Interface: Clean, responsive UI built with Tailwind CSS and
├── backend/ # MCP Server Implementation
│ ├── src/
│ │ ├── lib/ # OpenAI & Qdrant clients
│ │ ├── tools/ # MCP Tools (ingest.ts, query.ts)
│ │ ├── mcp-server.ts # Main server entry point
│ │ └── index.ts # Server startup
│ ├── scripts/
│ │ ├── manual_ingest.ts # Script to manually trigger ingestion
│ │ └── parse_doc.py # Python script for PDF parsing
│ ├── data/ # Directory for storing raw documents
│ └── package.json
│
├── frontend/ # Next.js App Router Application
│ ├── src/
│ │ ├── app/
│ │ │ ├── api/chat/ # Route Handler for AI SDK
│ │ │ └── page.tsx # Main Chat UI Component
│ │ └── components/ # UI Components (shadcn/ui)
│ └── package.json
└── README.md
- Node.js (v18 or higher)
- Python (v3.10+) with
pip - Docker (Desktop or Engine) for running Qdrant
- OpenAI API Key
git clone <your-repo-url>
cd <repo-name>- Navigate to the backend:
cd backend npm install - Install Python dependencies (for PDF parsing):
pip install pypdf # If pip fails, try: python -m pip install pypdf - Configure Environment Variables:
Copy
.env.exampleto.envand fill in your keys.OPENAI_API_KEY=sk-... # Your OpenAI Key QDRANT_URL=http://localhost:6333 PORT=3001 MODE=sse
- Navigate to the frontend:
cd frontend npm install - Configure Environment Variables:
Create
.env.local:OPENAI_API_KEY=sk-... # Required for AI SDK MCP_SERVER_URL=http://localhost:3001/sse
You must have Docker running.
docker run -d -p 6333:6333 -v $(pwd)/qdrant_storage:/qdrant/storage:z qdrant/qdrantNote: If you encounter an error starting Docker, ensure Docker Desktop is running.
Place your PDF files in backend/src/tools/PDF/ (or update the path).
Run the manual ingestion script:
cd backend
npx tsx scripts/manual_ingest.tsYou need to run both servers (use two terminals).
Terminal 1 (Backend):
cd backend
npm run devTerminal 2 (Frontend):
cd frontend
npm run devAccess the chat interface at http://localhost:3000.
CURRENT ISSUES:
1)The chatbot front interface is working but not being able to retrieve data and access the embeddings. Currently trying to fix this issue.
2)- RAG Connection: Accessing the query_knowledge_base tool depends on a local Qdrant instance. If Qdrant is not running (e.g., Docker issues), the chat will fall back to general knowledge.