An intelligent Gmail client that uses MCP (Model Context Protocol) to interact with Gmail and Gemini AI to provide smart email management capabilities.
- 🤖 AI-Powered Email Analysis - Uses Gemini AI to analyze emails and determine appropriate actions
- 📧 Complete Gmail Integration - Send, read, organize, and manage emails via Gmail API
- 🔧 MCP Protocol - Modern client-server architecture using Model Context Protocol
- 📊 Full Transparency - Complete logging of all AI interactions
- 🎯 Smart Actions - Automatic replies, summaries, spam detection, and email organization
- 💬 Interactive Interface - Command-line interface for easy email management
┌─────────────────┐ MCP Protocol ┌─────────────────┐
│ talk2gmail.py │ ◄─────────────────► │ gmail/server.py │
│ (MCP Client) │ │ (MCP Server) │
│ │ │ │
│ • Gemini AI │ │ • Gmail API │
│ • User Interface│ │ • OAuth 2.0 │
│ • Command Parser│ │ • Email Tools │
└─────────────────┘ └─────────────────┘
- Provides Gmail API integration via MCP tools
- Handles OAuth 2.0 authentication
- Exposes email operations as MCP tools
- Connects to Gmail MCP server
- Uses Gemini AI for intelligent email analysis
- Provides interactive command interface
The MCP server provides these email management tools:
| Tool | Description | Parameters |
|---|---|---|
send-email |
Send emails | recipient_id, subject, message |
get-unread-emails |
Retrieve unread emails | None |
read-email |
Get full email content | email_id |
trash-email |
Move emails to trash | email_id |
mark-email-as-read |
Mark emails as read | email_id |
open-email |
Open email in browser | email_id |
- Python 3.8+
- uv - Fast Python package manager (installation guide)
- Google Cloud Project with Gmail API enabled
- Gemini API Key
-
Install uv (if not already installed):
# On macOS and Linux curl -LsSf https://astral.sh/uv/install.sh | sh # On Windows powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # Or with pip pip install uv
-
Clone the repository:
git clone <repository-url> cd gmail_mcp
-
Install dependencies with uv:
# Install all dependencies (recommended) uv sync # Or install with optional enhanced features uv sync --extra enhanced # Or install with development dependencies uv sync --extra dev
-
Set up environment variables:
# Create .env file echo "GEMINI_API_KEY=your_gemini_api_key_here" > .env
-
Set up Gmail OAuth:
- Go to Google Cloud Console
- Enable Gmail API
- Create OAuth 2.0 credentials
- Download credentials as
client_creds.json
uv run python talk2gmail.pyOn first run, you'll complete the OAuth flow:
- Browser opens for Google authentication
- Grant permissions to access Gmail
- Token saved for future use
# Run with uv (recommended)
uv run python talk2gmail.py
# Or activate virtual environment and run directly
uv shell
python talk2gmail.py# Natural language queries
📧 Enter your Gmail request: get my unread emails
📧 Enter your Gmail request: read the latest email from john@example.com
📧 Enter your Gmail request: send a thank you email to sarah@company.comThe AI analyzes emails and determines actions:
- REPLY - Generates contextual responses
- SUMMARIZE - Creates concise summaries
- URGENT - Flags important emails
- SPAM - Detects and handles spam
- ARCHIVE - Organizes routine emails
📧 Processing email: abc123
📖 From: client@company.com
📝 Subject: Project Update Required
🤖 AI Action: REPLY
💭 AI Reasoning: Client requesting project status - should provide update
✅ Reply sent: "Thank you for your inquiry. I'll provide the project update by end of day."
Create a .env file:
GEMINI_API_KEY=your_gemini_api_key_here-
Google Cloud Console Setup:
- Create project
- Enable Gmail API
- Create OAuth 2.0 credentials
- Add authorized redirect URIs:
http://localhost:8080
-
Download credentials as
client_creds.json
The application requires these Gmail scopes:
https://www.googleapis.com/auth/gmail.modify
gmail_mcp/
├── gmail/
│ ├── __init__.py # Package entry point
│ └── server.py # Gmail MCP server
├── talk2gmail.py # Gmail MCP client
├── client_creds.json # Gmail OAuth credentials (you provide)
├── token.json # OAuth tokens (auto-generated)
├── .env # Environment variables (you create)
├── pyproject.toml # Project configuration and dependencies
├── requirements.txt # Python dependencies (legacy)
├── uv.lock # Dependency lock file (auto-generated)
└── README.md # This file
- OAuth 2.0 - Secure authentication with Google
- Local Storage - Tokens stored locally, never transmitted
- Minimal Scopes - Only requests necessary Gmail permissions
- No Data Collection - All processing happens locally
Made with ❤️ using MCP (Model Context Protocol) and Gemini AI