Adithya-R35/mcp-email-agent
If you are the rightful owner of mcp-email-agent and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MCP Database Server with OAuth Email Agent is an intelligent email-based data access system that integrates a Model Control Protocol (MCP) server for database queries with an AI-powered email agent using Gmail OAuth2 authentication.
MCP Database Server with OAuth Email Agent
An intelligent email-based data access system that combines a Model Control Protocol (MCP) server for database queries with an AI-powered email agent using Gmail OAuth2 authentication.
Features
MCP Database Server (mcp_server.py)
- MSSQL Integration: Direct connection to Microsoft SQL Server databases
- Resource Management: Pre-defined database resources for common queries
- Health Monitoring: Built-in connection health checks
- Flexible Configuration: Environment-based configuration support
OAuth Email Agent (oauth_email_agent.py)
- Gmail OAuth2: Secure authentication with Gmail API
- AI-Powered Processing: Uses OpenAI GPT-4 for intelligent email parsing
- Authorization System: Role-based access control for data requests
- CSV Export: Automatic data export with email attachments
- LangGraph Workflow: Structured processing pipeline
Available Data Resources
- Customer Data - Complete customer information and contact details
- Product Catalog - Product details, inventory, and pricing
- Customer Addresses - Address information and locations
- Sales Order Details - Transaction history and order data
- Product Descriptions - Detailed product specifications
Quick Start
1. Clone Repository
git clone https://github.com/yourusername/mcp-email-agent.git
cd mcp-email-agent
2. Install Dependencies
pip install -r requirements.txt
3. Environment Setup
cp .env.example .env
# Edit .env with your database and API credentials
4. Gmail OAuth Setup
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Gmail API
- Create OAuth 2.0 credentials
- Download
credentials.jsonto project root
5. Run the Services
Start MCP Server:
python mcp_server.py
Start Email Agent:
python oauth_email_agent.py
Configuration
Database Configuration
Set these environment variables in .env:
MSSQL_SERVER=your_server
MSSQL_DATABASE=your_database
MSSQL_USERNAME=your_username
MSSQL_PASSWORD=your_password
API Keys
OPENAI_API_KEY=your_openai_key
Usage
Email Requests
Send emails requesting data to the configured Gmail account:
Example requests:
- "I need customer contact information"
- "Can you send me the product inventory?"
- "Show me recent sales data"
- "I want customer addresses for shipping"
Authorization
Configure authorized users in oauth_email_agent.py:
authorized_clients = [
AuthorizedClient(
email="user@company.com",
name="John Doe",
company="Your Company",
authorized_resources=["*"] # or specific resources
)
]
Response Types
- ✅ Data Response: CSV attachment with requested data
- ❌ Unauthorized: Access denied message
- ❓ Clarification: Request for more specific information
- 🚫 No Data: Resource not available message
Security Features
- OAuth2 authentication for Gmail access
- Role-based authorization system
- Resource-level access control
- Secure credential management
- No hardcoded passwords or tokens
Architecture
Email Request → Gmail API → LangGraph Workflow → MCP Server → Database
↓
CSV Response ← Gmail API ← AI Response Generation ← Query Results
Dependencies
- Database:
pyodbcfor MSSQL connectivity - AI:
langchain-openaifor GPT-4 integration - Workflow:
langgraphfor process orchestration - Gmail:
google-api-python-clientfor OAuth2 and API access - MCP:
mcpfor Model Control Protocol server
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Security Notes
- Never commit
credentials.jsonortoken.json - Keep
.envfiles out of version control - Use strong database passwords
- Regularly rotate API keys
- Monitor authorized user list
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For issues and questions:
- Check the GitHub Issues page
- Review the setup documentation in
/setup/ - Ensure all dependencies are properly installed
- Verify environment variables are correctly set
Roadmap
- Support for additional database types (PostgreSQL, MySQL)
- Web interface for authorization management
- Advanced query filtering and parameterization
- Slack integration
- Enhanced logging and monitoring
- Multi-language support