A prototype Customer Support chatbot for a computer products company, built with MCP (Model Context Protocol) integration and a lightweight LLM.
- Customer authentication using email and PIN
- Product search and browsing
- Order history viewing
- Product details lookup
- Natural language conversation using OpenRouter API
- MCP Server: Handles all product and order operations via Streamable HTTP
- LLM: Uses OpenRouter API for intelligent responses
- UI: Gradio interface for easy interaction
- Deployment: HuggingFace Spaces
chatbot/
├── app.py # Main Gradio application entry point
├── config.py # Configuration and environment variables
├── mcp_client.py # MCP server client implementation
├── llm_client.py # OpenRouter LLM API client
├── utils.py # Utility functions (extractors, helpers)
├── intent_detection.py # Intent detection logic
├── response_generator.py # LLM response generation
├── auth.py # User authentication functions
├── message_processor.py # Message processing and tool orchestration
├── requirements.txt # Python dependencies
├── README.md # This file
└── .env # Environment variables (not in repo)
app.py: Main application file that sets up the Gradio interface and handles UI interactionsconfig.py: Loads environment variables, configures logging, and initializes LLM clientmcp_client.py:MCPServerclass for interacting with the MCP server (products, orders, authentication)llm_client.py: Functions for calling the OpenRouter APIutils.py: Helper functions for extracting SKUs, search queries, and customer IDsintent_detection.py: Determines user intent and selects appropriate toolsresponse_generator.py: Generates conversational responses using LLMauth.py: Handles customer authentication via email and PINmessage_processor.py: Orchestrates message processing, tool execution, and response generation
- Create and activate virtual environment:
python3 -m venv venv
source venv/bin/activate- Install dependencies:
pip install --upgrade pip
pip install -r requirements.txt- Run the application:
python app.py- Open your browser to
http://localhost:7860
donaldgarcia@example.net/ PIN:7912michellejames@example.com/ PIN:1520laurahenderson@example.org/ PIN:1488spenceamanda@example.org/ PIN:2535glee@example.net/ PIN:4582
verify_customer_pin- Authenticate customerslist_products- Browse product catalogsearch_products- Search products by keywordget_product- Get detailed product informationlist_orders- View customer order historyget_order- Get order detailscreate_order- Place new orders
- Create a new Space on HuggingFace
- Set SDK to "Gradio"
- Upload all Python files (
app.py,config.py,mcp_client.py,llm_client.py,utils.py,intent_detection.py,response_generator.py,auth.py,message_processor.py),requirements.txt, andREADME.md - Set environment variables in Space settings
- The Space will automatically build and deploy
OPENROUTER_API_KEY: OpenRouter API key (required)OPENROUTER_MODEL: OpenRouter model to use (default:google/gemini-2.5-flash)
MCP_SERVER_URL: MCP server endpoint (default: provided URL)OPENROUTER_BASE_URL: OpenRouter API base URL (default:https://openrouter.ai/api/v1)
- Copy the example environment file:
cp .env.example .env- Edit
.envand add your OpenRouter API key:
OPENROUTER_API_KEY=your-actual-api-key-here- Run the application:
python app.pyAlternatively, you can set environment variables directly:
export OPENROUTER_API_KEY="your-api-key-here"
export OPENROUTER_MODEL="google/gemini-2.5-flash" # Optional, this is the default
python app.py- Python 3.8+
- Gradio 4.44.0+
- Requests 2.31.0+
- python-dotenv 1.0.0+
- Provider: OpenRouter API
- Default Model:
google/gemini-2.5-flash(lightweight, fast) - No Local Models: Uses API-based LLMs (no model downloads required)