A complete user registration system built with Model Context Protocol (MCP) that handles user registration through a conversational chatbot interface. The system stores data locally in CSV format, replacing the need for external services like Google Sheets or Zapier.
This project demonstrates how to:
- Build a local MCP server from scratch in Python
- Create conversational AI interfaces with Streamlit
- Handle data persistence with local CSV storage
- Implement data validation and error handling
- Provide rich user interactions through natural language
βββββββββββββββββββ HTTP/JSON-RPC βββββββββββββββββββ CSV Operations βββββββββββββββββββ
β Streamlit UI β βββββββββββββββββββΊ β MCP Server β βββββββββββββββββββΊ β user_registrationsβ
β (Chat Interface)β β (Python Server) β β .csv β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- MCP Server (
registration_mcp_server.py) - Handles all data operations - Streamlit Chatbot (
streamlit_chatbot.py) - Provides user interface - CSV Storage (
user_registrations.csv) - Local data persistence
- Natural language interaction
- Step-by-step data collection (Name β Email β DOB)
- Real-time validation and feedback
- Confirmation before saving
- Add Registrations - Store new user data
- View All Registrations - List all registered users
- Search Functionality - Find users by name or email
- Statistics Dashboard - View registration analytics
- Data Validation - Email format, date validation, duplicate prevention
- Local MCP Server - No external dependencies
- CSV Storage - Simple, portable data format
- Error Handling - Comprehensive error messages
- Real-time Validation - Immediate feedback on data entry
- Responsive UI - Clean, intuitive Streamlit interface
- Python 3.8+
- pip package manager
Create a new directory and save these files:
registration_mcp_server.py- The MCP serverstreamlit_chatbot.py- The Streamlit interface
# Install MCP SDK for the server
pip install mcp
# Install Streamlit for the chatbot interface
pip install streamlit requestsOpen a terminal and run:
python registration_mcp_server.pyExpected Output:
π Starting Registration MCP Server...
π Data file: user_registrations.csv
π οΈ Available tools:
β’ add_registration - Add new user registration
β’ get_all_registrations - Retrieve all registrations
β’ search_registrations - Search by name or email
β’ get_registration_statistics - View registration stats
β’ validate_registration_data - Validate data before saving
π Available resources:
β’ file://user_registrations.csv - Direct CSV file access
β
Server ready for connections!
Connect your AI model to use these tools...
Open a new terminal and run:
streamlit run streamlit_chatbot.pyThe chatbot will open in your browser at http://localhost:8501
- Start Registration: Type
registeror click the "Register" button - Enter Name: Provide your full name (minimum 2 characters)
- Enter Email: Provide a valid email address
- Enter Date of Birth: Use YYYY-MM-DD format (e.g., 1990-05-15)
- Confirm Details: Review and confirm your registration
| Command | Description | Example |
|---|---|---|
register |
Start new registration | register |
show registrations |
View all registered users | show registrations |
search [query] |
Search by name or email | search john or search @gmail |
statistics |
View registration statistics | statistics |
help |
Show available commands | help |
User: register
Bot: Great! Let's start your registration. π
What's your full name?
User: John Doe
Bot: Nice to meet you, John Doe! π
Now, please provide your email address:
User: john@example.com
Bot: Perfect! π§
Now please enter your date of birth.
Format: YYYY-MM-DD (e.g., 1990-05-15)
User: 1990-05-15
Bot: π Please confirm your registration details:
β’ Name: John Doe
β’ Email: john@example.com
β’ Date of Birth: 1990-05-15
β
Everything looks good!
β’ Type 'confirm' to complete registration
User: confirm
Bot: π Registration Completed Successfully!
β
Successfully registered John Doe
Registration Details:
β’ Name: John Doe
β’ Email: john@example.com
β’ Date of Birth: 1990-05-15
β’ Registered: 2025-01-15 14:30:25
Data is stored in user_registrations.csv with these columns:
| Column | Description | Example |
|---|---|---|
| Name | User's full name | John Doe |
| Email address | john@example.com | |
| Date_of_Birth | Birth date (YYYY-MM-DD) | 1990-05-15 |
| Registration_Date | When registered | 2025-01-15 14:30:25 |
Name,Email,Date_of_Birth,Registration_Date
John Doe,john@example.com,1990-05-15,2025-01-15 14:30:25
Jane Smith,jane@example.com,1985-03-20,2025-01-15 14:35:12
Mike Johnson,mike@example.com,1992-07-08,2025-01-15 14:40:33-
add_registration- Purpose: Add new user registration
- Parameters:
name,email,dob - Validation: Name length, email format, date format, duplicate email check
-
get_all_registrations- Purpose: Retrieve all registered users
- Parameters: None
- Returns: List of all registrations with IDs
-
search_registrations- Purpose: Search users by name or email
- Parameters:
query(search term) - Returns: Matching registrations
-
get_registration_statistics- Purpose: Get registration analytics
- Parameters: None
- Returns: Total count, age demographics, registration dates
-
validate_registration_data- Purpose: Validate data without saving
- Parameters:
name,email,dob - Returns: Validation results for each field
| Field | Validation Rules |
|---|---|
| Name | β’ Minimum 2 characters β’ Maximum 100 characters β’ Cannot be empty |
| β’ Valid email format (user@domain.com) β’ Must be unique (no duplicates) β’ Cannot be empty |
|
| Date of Birth | β’ YYYY-MM-DD format β’ Cannot be in the future β’ Reasonable age limits (0-150 years) |
π Registration Statistics:
π Total Registrations: 25
π Unique Email Domains: 12
π
First Registration: 2025-01-10 09:15:30
π Latest Registration: 2025-01-15 16:45:22
πΎ File Size: 1,234 bytes
π₯ Age Demographics:
Average Age: 32.4 years
Youngest User: 18 years
Oldest User: 67 years
π Data File: user_registrations.csv
π Search Results for 'john' (3 matches):
1. John Doe
π§ Email: john@example.com
π Date of Birth: 1990-05-15
π
Registered: 2025-01-15 14:30:25
2. Johnny Smith
π§ Email: johnny.smith@gmail.com
π Date of Birth: 1988-11-22
π
Registered: 2025-01-14 11:20:15
``
### **Common Issues**
**1. "MCP Server: Disconnected"**
- **Cause**: MCP server not running
- **Solution**: Start the server with `python registration_mcp_server.py`
**2. "Invalid email format"**
- **Cause**: Incorrect email format
- **Solution**: Use format like `user@domain.com`
**3. "Invalid date format"**
- **Cause**: Wrong date format
- **Solution**: Use YYYY-MM-DD format (e.g., `1990-05-15`)
**4. "Email already registered"**
- **Cause**: Duplicate email address
- **Solution**: Use a different email address
**5. "Failed to call MCP tool"**
- **Cause**: Communication issue between client and server
- **Solution**: Restart both the MCP server and Streamlit app
### **File Permissions**
- Ensure the directory is writable (for CSV file creation)
- Check that `user_registrations.csv` isn't locked by another program
### **Port Conflicts**
- MCP server uses stdio communication (no port needed)
- Streamlit uses port 8501 (changeable with `--server.port` flag)
## π **Project Structure**
registration-chatbot/ βββ registration_mcp_server.py # MCP server with all tools βββ streamlit_chatbot.py # Streamlit chat interface βββ user_registrations.csv # Generated data file βββ README.md # This documentation βββ requirements.txt # Python dependencies (optional)
## π **Extending the System**
### **Adding New Fields**
1. Update `REQUIRED_FIELDS` in the MCP server
2. Add validation in `RegistrationValidator` class
3. Extend the chatbot conversation flow
4. Update CSV operations
### **Database Integration**
Replace CSV operations with database calls:
```python
# Instead of CSV operations
def add_registration(self, name, email, dob):
# Database insert logic here
cursor.execute("INSERT INTO users VALUES (?, ?, ?)", (name, email, dob))
Add external API calls to the MCP server:
@app.list_tools()
async def list_tools():
return [
Tool(name="send_email", description="Send welcome email"),
Tool(name="sync_to_crm", description="Sync to CRM system")
]After completing this project, you'll understand:
- MCP Architecture - How to build and structure MCP servers
- Data Validation - Implementing robust input validation
- Conversational AI - Creating natural language interfaces
- File Operations - CSV reading, writing, and manipulation
- Error Handling - Comprehensive error management
- UI/UX Design - Building user-friendly chat interfaces
- MCP Documentation: https://modelcontextprotocol.io/
- Streamlit Docs: https://docs.streamlit.io/
- Python CSV Module: https://docs.python.org/3/library/csv.html
Happy Coding! π
Built with β€οΈ using Model Context Protocol, Streamlit, and Python