Skip to content

GitHub template repository for building MCP UI chat analytics systems with natural language processing

License

Notifications You must be signed in to change notification settings

get10acious/rops_h1_poc_analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LoyaltyAnalytics - Natural Language Analytics POC

A complete implementation of an intelligent admin homepage with natural language analytics capabilities. This project demonstrates a fully functional real-time analytics chatbot that can query loyalty program databases and generate visualizations using natural language, built with modern MCP (Model Context Protocol) integration.

πŸš€ Getting Started (TL;DR)

Quick Setup:

git clone <your-repo-url>
cd rops_h1_poc_analytics
make install
make docker-up
make init-db
make setup-mcp
make start

Access: http://localhost:3000

The Makefile handles all the complexity - just follow the commands above!

🎯 Project Overview

This is a working implementation of a dynamic, intelligent "mission control" for loyalty program analytics. The system allows non-technical users to ask plain English questions about merchants, users, and redemption data, receiving interactive data visualizations in real-time.

Key Features

  • Natural Language Queries: Ask questions like "Show me the top 10 merchants by redemption volume this month"
  • Interactive Chart.js Visualizations: Automatic chart and table generation with export/fullscreen capabilities
  • Complete Tool Ecosystem: Database queries, Python code execution, and MCP-UI visualization generation
  • Real-time Chat Interface: WebSocket-based communication for instant responses
  • Database Integration: Direct PostgreSQL connection with loyalty program data
  • MCP Integration: Model Context Protocol with automated PostgreSQL Toolbox setup
  • Advanced AI Agent: LangGraph-based ReAct agent with multi-iteration reasoning and composite tools
  • Code Sandbox: Python code execution for custom analytics and data processing
  • Environment-Based Configuration: Flexible configuration using environment variables
  • Automated Setup: One-command setup for MCP servers and database initialization

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    WebSocket    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    MCP     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      │◄──────────────►│    Backend      │◄──────────►│   MCP Servers    β”‚
β”‚   (React)       β”‚                 β”‚   (FastAPI)     β”‚            β”‚                 β”‚
β”‚                 β”‚                 β”‚                 β”‚            β”‚ β€’ DB Toolbox    β”‚
β”‚ Chat Interface  β”‚                 β”‚ ReAct Agent     β”‚            β”‚ β€’ MCP-UI        β”‚
β”‚ MCPUI UIResource|
|  Charts         β”‚                 β”‚ WebSocket Hub   β”‚            β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                                             β–Ό
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚   PostgreSQL    β”‚
                                    β”‚                 β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • Python 3.11+
  • Node.js 18+
  • Git

1. Clone and Setup

git clone <your-repo-url>
cd rops_h1_poc_analytics

2. Complete Setup (One Command)

# Install all dependencies and setup everything
make install

3. Start the Application

The Makefile simplifies the running process. Follow these steps in order:

To Start the Frontend:

make setup-frontend
make start-frontend

To Start the Backend and All Necessary Tools:

make setup-backend    # Creates .env file automatically
make init-db          # Initialize database with sample data
make setup-mcp        # Download and configure MCP Toolbox
make start-backend    # Start backend with MCP servers

4. Access the Application

Alternative: Start Everything at Once

# Complete setup and start both services
make install
make docker-up        # Start PostgreSQL
make init-db          # Initialize database
make setup-mcp        # Setup MCP servers
make start            # Start both frontend and backend

✨ Recent Updates

This project has been updated with several key improvements:

πŸ”§ Enhanced Configuration

  • Environment-Based Setup: All configuration now uses environment variables
  • Automatic .env Creation: Template file created during setup
  • Flexible Database Configuration: Individual postgres connection parameters

πŸ€– Improved MCP Integration

  • Automated MCP Setup: mcp_setup.py downloads and configures PostgreSQL Toolbox
  • Working MCP Configuration: Uses proven format from mcpui-sandbox-chat
  • Environment-Driven Config: MCP servers configured from environment variables

πŸ—„οΈ Database Improvements

  • Loyalty Program Schema: Complete loyalty program database with realistic data
  • Environment-Driven Init: Database initialization uses environment settings
  • Better Error Handling: Improved logging and error management

πŸš€ Streamlined Setup

  • One-Command Setup: make install && make setup-mcp && make init-db && make start
  • Automatic Downloads: MCP Toolbox downloaded automatically
  • Consistent Naming: Fixed case sensitivity issues across the codebase

πŸ“‹ Original Challenge Brief

This project demonstrates a complete implementation of the MCP UI Chat Analytics system. It serves as both a working example and a foundation for further development.

Learning Objectives

  • Architect a real-time, full-stack application using WebSockets
  • Integrate and orchestrate multiple MCP servers
  • Translate natural language queries into database queries and visualizations
  • Utilize AI agents to accelerate development

Competencies Assessed

  • Description & Delegation: Clear, context-rich instructions for complex systems
  • Discernment & Diligence: Critical evaluation of generated code and queries
  • Problem-solving Style: Adaptive vs. Innovative approaches

πŸ› οΈ Development Workflow

AI-Assisted Development Pattern

This template follows a structured approach for AI-assisted development:

  1. Plan First: Provide context and collaboratively refine architecture
  2. IDE Configuration: Use AI to configure MCP toolchain
  3. TDD Setup: Convert plans into failing tests
  4. Implementation: Build minimal code to pass tests
  5. Integration: Connect frontend and backend
  6. Validation: End-to-end testing and documentation

Available Commands

# Development
make install          # Install all dependencies
make setup-backend    # Setup Python environment
make setup-frontend   # Setup Node.js dependencies
make setup-mcp        # Configure MCP servers

# Running
make start            # Start both servers
make start-backend    # Start backend only
make start-frontend   # Start frontend only
make dev              # Initialize DB and start servers

# Testing
make test             # Run all tests
make test-backend     # Run backend tests
make test-frontend    # Run frontend tests
make test-mcp         # Test MCP integration

# Database
make init-db          # Initialize with sample data
make docker-up        # Start PostgreSQL
make docker-down      # Stop PostgreSQL
make check-db         # Test database connection

# Utilities
make clean            # Clean build artifacts
make status           # Check service status
make logs-backend     # View backend logs

πŸ“ Project Structure

rops_h1_poc_analytics/
β”œβ”€β”€ backend/                    # FastAPI backend
β”‚   β”œβ”€β”€ models/                # Database models
β”‚   β”œβ”€β”€ tests/                 # Backend tests
β”‚   β”œβ”€β”€ mcp_servers/           # MCP server configurations
β”‚   β”œβ”€β”€ notebooks/             # Jupyter notebooks for testing
β”‚   β”œβ”€β”€ main.py                # FastAPI application
β”‚   β”œβ”€β”€ langgraph_agent.py     # ReAct agent implementation
β”‚   β”œβ”€β”€ mcp_multi_client.py    # MCP client manager
β”‚   β”œβ”€β”€ websocket_manager.py   # WebSocket handling
β”‚   └── requirements.txt       # Python dependencies
β”œβ”€β”€ frontend/                  # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/        # React components
β”‚   β”‚   β”œβ”€β”€ hooks/             # Custom hooks
β”‚   β”‚   β”œβ”€β”€ types/             # TypeScript types
β”‚   β”‚   └── app/               # Next.js app directory
β”‚   β”œβ”€β”€ package.json           # Node.js dependencies
β”‚   └── next.config.ts         # Next.js configuration
β”œβ”€β”€ docs/                      # Documentation
β”‚   β”œβ”€β”€ AI_GUIDE.md            # AI assistant instructions
β”‚   β”œβ”€β”€ CHALLENGE_BRIEF.md     # Hackathon challenge
β”‚   β”œβ”€β”€ DEVELOPMENT_PATTERNS.md # Coding standards
β”‚   └── MCP_INTEGRATION_GUIDE.md # MCP setup guide
β”œβ”€β”€ scripts/                   # Utility scripts
β”œβ”€β”€ docker-compose.yml         # Docker services
β”œβ”€β”€ Makefile                   # Development commands
└── README.md                  # This file

πŸ—„οΈ Database Schema

The template includes a sample analytics database

πŸ€– AI Assistant Integration

This template is designed to work seamlessly with AI coding assistants. Key features:

  • Comprehensive Context: Detailed system documentation for AI understanding
  • Structured Prompts: Pre-written prompts for common development tasks
  • Clear Patterns: Consistent coding patterns and architecture
  • Progressive Implementation: Step-by-step development approach

πŸ”§ Configuration

Environment Variables

Create a .env file in the root directory:

# Database
DATABASE_URL=postgresql://analytics:password@localhost:5432/analytics_db
REDIS_URL=redis://localhost:6379

# API Keys (for production)
OPENAI_API_KEY=your_openai_key_here
GEMINI_API_KEY=your_gemini_key_here

# Development
LOG_LEVEL=INFO
DEBUG=true

MCP Server Configuration

The template includes pre-configured MCP servers:

  • Database Toolbox: For PostgreSQL queries
  • MCP UI: For visualization generation

πŸ§ͺ Testing

Backend Tests

# Run all backend tests
make test-backend

# Run specific test categories
cd backend && python -m pytest tests/ -v
cd backend && python -m pytest tests/test_websocket.py -v
cd backend && python -m pytest tests/test_orchestration.py -v

Frontend Tests

# Run frontend tests
make test-frontend

# Run component tests
cd frontend && npm test

Integration Tests

# Test MCP integration
make test-mcp

# Test MCP UI integration
make test-mcp-ui

πŸš€ Deployment

Docker Deployment

# Build and start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Production Considerations

  • Configure proper environment variables
  • Set up SSL certificates
  • Configure reverse proxy (nginx)
  • Set up monitoring and logging
  • Configure database backups

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes following the development patterns
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Troubleshooting

Common Issues

Database Connection Issues:

# Check if PostgreSQL is running
make check-db

# Restart database
make docker-down
make docker-up
make init-db

MCP Server Issues:

# Re-setup MCP servers
make setup-mcp

# Check MCP status
make status

Frontend Not Loading:

# Restart frontend
make start-frontend

# Check if backend is running
make status

Backend Not Starting:

# Check logs
make logs-backend

# Restart backend
make start-backend

Service Status

# Check all services
make status

# View logs
make logs-backend
make logs-frontend

πŸ†˜ Support

For support and questions:

  • Check the documentation in the docs/ directory
  • Review the troubleshooting section above
  • Create an issue in the repository

πŸ™ Acknowledgments

About

GitHub template repository for building MCP UI chat analytics systems with natural language processing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published