A full-stack AI agent platform with Retrieval Augmented Generation (RAG), Model Context Protocol (MCP) integration, and multi-LLM support. Built with FastAPI backend and Next.js frontend, featuring a ChatGPT-like interface with streaming responses, document management, and advanced RAG capabilities.
- π€ Multi-LLM Support: Switch between OpenAI (GPT-4o), Google Gemini, Groq, and Ollama models
- π¬ Streaming Chat: Real-time character-by-character streaming responses using Server-Sent Events (SSE)
- π Advanced RAG System:
- Hybrid search (Vector + BM25)
- Cross-encoder re-ranking
- Multiple document collections per user
- Per-user vectorstores with FAISS
- π MCP Integration: Model Context Protocol server support for extensible tooling
- π Authentication: JWT-based user authentication with secure password hashing
- π Document Management: Upload, organize, and query documents with collection support
- πΎ Session Management: Persistent conversation history with session switching
- β‘ Rate Limiting: Built-in API rate limiting for production use
- π WebSocket Support: Real-time bidirectional communication
- π¨ Modern UI: ChatGPT-inspired design with dark mode support
- π Health Monitoring: Real-time backend health status and MCP server count
- βοΈ Settings Panel: Configure MCP servers and LLM settings through intuitive UI
- π Dual Modes: Switch between Agent mode (with tools) and RAG mode
- π Markdown Support: Rich text rendering with code blocks and formatting
- π± Responsive Design: Works seamlessly on desktop and mobile devices
- Architecture
- Tech Stack
- Prerequisites
- Installation
- Configuration
- Usage
- Project Structure
- API Documentation
- Development
- Deployment
- Security
- Contributing
- License
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend (Next.js) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Chat UI β β Documents β β Settings β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
HTTP/WebSocket/SSE
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Backend (FastAPI) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Chat Serviceβ β RAG System β β MCP Client β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Auth β β Document β β LLM Factory β β
β β Service β β Processor β β β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββΌββββββββββββββββββββ
β β β
βββββββββΌβββββββ βββββββββββΌββββββββββ βββββββΌβββββββ
β PostgreSQL β β FAISS Vectorstoreβ β MCP β
β Database β β (Per User) β β Servers β
ββββββββββββββββ βββββββββββββββββββββ ββββββββββββββ
The backend follows a clean architecture pattern with clear separation of concerns:
- Core Layer: Domain models, database configuration, authentication
- Services Layer: Business logic (RAG, chat, document processing)
- API Layer: HTTP endpoints, middleware, request/response models
- MCP Layer: Model Context Protocol server implementations and client
The RAG system uses a hybrid search approach:
- Document Storage: Documents are chunked and stored in PostgreSQL
- Vector Embeddings: Chunks are embedded using OpenAI embeddings
- Vector Store: FAISS vectorstore stores embeddings per user
- Retrieval: Hybrid search combines:
- Vector similarity search (semantic matching)
- BM25 keyword search (lexical matching)
- Cross-encoder re-ranking (relevance scoring)
- Collection Filtering: Documents can be organized into collections for targeted retrieval
For detailed RAG architecture, see MULTIPLE_COLLECTIONS_RAG.md.
- Framework: FastAPI 0.115+
- Database: PostgreSQL 15+ with SQLAlchemy ORM
- Vector Store: FAISS (CPU/GPU)
- LLM Libraries:
- LangChain & LangGraph
- langchain-openai, langchain-google-genai, langchain-ollama
- MCP: Model Context Protocol (mcp>=1.20.0)
- Authentication: JWT (python-jose), bcrypt
- Document Processing: PyPDF2, python-docx, unstructured
- RAG Components: sentence-transformers, rank-bm25
- Framework: Next.js 16 (App Router)
- Language: TypeScript
- Styling: TailwindCSS v4
- State Management: Zustand
- HTTP Client: Fetch API with SSE support
- Markdown: react-markdown
- UI Components: Custom components with Lucide React icons
- Containerization: Docker & Docker Compose
- Web Server: Uvicorn (ASGI)
- Rate Limiting: SlowAPI
- Python: 3.11 or higher
- Node.js: 18 or higher
- PostgreSQL: 15 or higher
- Docker & Docker Compose (optional, for containerized deployment)
-
Clone the repository:
git clone <repository-url> cd agent-dosibridge
-
Set up environment variables:
# Backend environment variables cp backend/.env.example backend/.env # Edit backend/.env with your configuration # Frontend environment variables (optional, defaults work for Docker) # NEXT_PUBLIC_API_BASE_URL is set in docker-compose.yml
-
Start all services:
docker-compose up -d
This will start:
- PostgreSQL database on port 5432
- Backend API on port 8085
- Frontend on port 8086
-
Initialize the database (first time only):
docker exec -it agent-backend python init_db.py
-
Navigate to backend directory:
cd backend -
Create virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
cp .env.example .env # Edit .env with your configuration -
Generate security keys:
python generate_keys.py
This generates JWT_SECRET_KEY and MCP_APIKEY_ENCRYPTION_KEY. See KEY_SETUP.md for details.
-
Initialize database:
python init_db.py
-
Start the server:
./start_server.sh # Or manually: python -m uvicorn src.api:app --reload --host 0.0.0.0 --port 8000The API will be available at
http://localhost:8000API documentation athttp://localhost:8000/docs
-
Navigate to frontend directory:
cd frontend -
Install dependencies:
npm install # or yarn install # or pnpm install
-
Set up environment variables:
cp .env.local.example .env.local # Edit .env.local with your backend URL -
Start development server:
npm run dev # or yarn dev # or pnpm dev
The frontend will be available at
http://localhost:3000
# Database Configuration
DATABASE_URL="postgresql://user:password@localhost:5432/mcpagent"
# JWT Authentication Secret Key (generate with generate_keys.py)
JWT_SECRET_KEY=your-generated-jwt-secret-key-here
# MCP API Key Encryption Key (generate with generate_keys.py)
MCP_APIKEY_ENCRYPTION_KEY=your-generated-encryption-key-here
# CORS Origins (comma-separated)
CORS_ORIGINS="http://localhost:3000,http://localhost:8086"
# LLM API Keys (optional, can be set via UI)
OPENAI_API_KEY=""
GOOGLE_API_KEY=""
GROQ_API_KEY=""
# Environment
ENVIRONMENT="development"# Backend API URL
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000The application uses PostgreSQL with the following main tables:
- users: User accounts and authentication
- llm_config: LLM configuration (per user)
- mcp_servers: MCP server configurations (per user)
- sessions: Chat session management
- messages: Conversation messages
- document_collections: Document collections (per user)
- documents: Uploaded documents
- document_chunks: Document chunks for RAG
Generate required security keys using:
cd backend
python generate_keys.pySee backend/KEY_SETUP.md for detailed security setup instructions.
-
Using Docker Compose:
docker-compose up -d
-
Access the application:
- Frontend: http://localhost:8086 (or http://localhost:3000 in local dev)
- Backend API: http://localhost:8085 (or http://localhost:8000 in local dev)
- API Docs: http://localhost:8085/docs
- Register/Login: Create an account or login
- Configure LLM: Go to Settings β LLM Config to set up your preferred model
- Upload Documents (optional): Upload documents to collections for RAG
- Start Chatting:
- Select mode: Agent (with tools) or RAG (document-based)
- Type your message and get streaming responses
- Manage Sessions: Create, switch, or delete conversation sessions
- Create Collection: Create a document collection to organize your documents
- Upload Documents: Upload PDF, DOCX, or text files
- Query Documents: Use RAG mode to query your documents
- Collection Filtering: Select a collection to query specific documents
- Add MCP Server: Go to Settings β MCP Servers
- Configure: Provide server name, URL, and optional API key
- Enable/Disable: Toggle servers on/off as needed
- Use Tools: MCP tools are automatically available in Agent mode
agent-dosibridge/
βββ backend/
β βββ src/
β β βββ api/ # FastAPI application
β β β βββ routes/ # API route handlers
β β β βββ models.py # Pydantic models
β β β βββ middleware.py # CORS, rate limiting
β β β βββ lifespan.py # App lifecycle management
β β βββ core/ # Core domain layer
β β β βββ models.py # SQLAlchemy models
β β β βββ database.py # Database configuration
β β β βββ config.py # Application config
β β β βββ auth.py # Authentication logic
β β βββ services/ # Business logic
β β β βββ chat_service.py
β β β βββ advanced_rag.py
β β β βββ document_processor.py
β β β βββ mcp_client.py
β β β βββ llm_factory.py
β β βββ mcp/ # MCP server implementations
β β βββ utils/ # Utilities
β βββ init_db.py # Database initialization
β βββ generate_keys.py # Security key generation
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend container
β
βββ frontend/
β βββ app/ # Next.js app directory
β β βββ chat/ # Chat page
β β βββ login/ # Login page
β β βββ api/ # API routes
β βββ components/ # React components
β β βββ ChatWindow.tsx
β β βββ ChatInput.tsx
β β βββ DocumentUpload.tsx
β β βββ ui/ # UI components
β βββ lib/ # Utilities and API clients
β β βββ api/ # API client modules
β β βββ store.ts # Zustand store
β βββ types/ # TypeScript types
β βββ hooks/ # Custom React hooks
β βββ package.json
β βββ Dockerfile # Frontend container
β
βββ docker-compose.yml # Docker Compose configuration
βββ README.md # This file
βββ MULTIPLE_COLLECTIONS_RAG.md # RAG architecture details
βββ FRONTEND_STRUCTURE.md # Frontend structure guide
POST /api/auth/register- Register new userPOST /api/auth/login- Login and get JWT tokenGET /api/auth/me- Get current user info
POST /api/chat- Non-streaming chatPOST /api/chat/stream- Streaming chat (SSE)GET /api/sessions- List all sessionsGET /api/session/{id}- Get session historyDELETE /api/session/{id}- Delete session
POST /api/documents/upload- Upload documentGET /api/documents- List documentsDELETE /api/documents/{id}- Delete documentPOST /api/collections- Create collectionGET /api/collections- List collections
GET /api/llm-config- Get LLM configurationPOST /api/llm-config- Set LLM configurationGET /api/mcp-servers- List MCP serversPOST /api/mcp-servers- Add MCP serverPUT /api/mcp-servers/{name}- Update MCP serverDELETE /api/mcp-servers/{name}- Delete MCP server
GET /health- Health checkGET /api/tools- Get available tools
Full API documentation available at /docs when the backend is running.
-
Activate virtual environment:
cd backend source .venv/bin/activate
-
Run with auto-reload:
python -m uvicorn src.api:app --reload
-
Run tests (if available):
pytest
-
Start development server:
cd frontend npm run dev -
Build for production:
npm run build npm start
- Backend: Follow PEP 8, use type hints
- Frontend: Follow ESLint rules, use TypeScript
- Backend: Add routes in
backend/src/api/routes/, services inbackend/src/services/ - Frontend: Add components in
frontend/components/, API clients infrontend/lib/api/
-
Build images:
docker-compose build
-
Start services:
docker-compose up -d
-
View logs:
docker-compose logs -f
- Environment Variables: Set all required environment variables
- Security Keys: Generate strong keys for production
- Database: Use managed PostgreSQL service
- HTTPS: Use reverse proxy (nginx) with SSL certificates
- Rate Limiting: Configure appropriate rate limits
- Monitoring: Set up logging and monitoring
- Backups: Regular database backups
- JWT tokens with expiration
- Bcrypt password hashing
- Secure token storage
- Encrypted MCP API keys in database
- User-specific data isolation
- CORS configuration
- Rate limiting
- Never commit
.envfiles - Use strong, unique keys per environment
- Keep dependencies updated
- Regular security audits
See backend/KEY_SETUP.md for security key setup.
- MULTIPLE_COLLECTIONS_RAG.md - Detailed RAG system architecture
- FRONTEND_STRUCTURE.md - Frontend code organization
- backend/KEY_SETUP.md - Security key generation guide
- backend/README.md - Backend-specific documentation
- frontend/README.md - Frontend-specific documentation
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details
- LangChain & LangGraph for LLM orchestration
- FastAPI for the excellent web framework
- Next.js for the frontend framework
- All open-source contributors
Built with β€οΈ by the DosiBridge team