mcp-email-agent

Adithya-R35/mcp-email-agent

3.2

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

  1. Customer Data - Complete customer information and contact details
  2. Product Catalog - Product details, inventory, and pricing
  3. Customer Addresses - Address information and locations
  4. Sales Order Details - Transaction history and order data
  5. 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

  1. Go to Google Cloud Console
  2. Create a new project or select existing
  3. Enable Gmail API
  4. Create OAuth 2.0 credentials
  5. Download credentials.json to 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: pyodbc for MSSQL connectivity
  • AI: langchain-openai for GPT-4 integration
  • Workflow: langgraph for process orchestration
  • Gmail: google-api-python-client for OAuth2 and API access
  • MCP: mcp for Model Control Protocol server

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Security Notes

  • Never commit credentials.json or token.json
  • Keep .env files 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:

  1. Check the GitHub Issues page
  2. Review the setup documentation in /setup/
  3. Ensure all dependencies are properly installed
  4. 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