MCP Gmail Server
README.md
# š§ MCP Gmail Server
A Model Context Protocol (MCP) server that enables Claude Desktop to read Gmail emails and create draft replies.

---
## šÆ What This Server Does
This MCP server connects Claude Desktop to your Gmail account, allowing you to:
- **Read unread emails** - Fetch and display unread emails from your inbox
- **Create draft replies** - Automatically draft responses to emails without sending them
---
## š Table of Contents
- [Features](#-features)
- [Prerequisites](#-prerequisites)
- [Installation](#-installation)
- [Google Cloud Setup](#-google-cloud-setup)
- [Configuration](#%EF%B8%8F-configuration)
- [Usage](#-usage)
- [Example Prompts](#-example-prompts)
- [Troubleshooting](#-troubleshooting)
- [Project Structure](#-project-structure)
- [Security Notes](#-security-notes)
- [Available MCP Tools](#-available-mcp-tools)
- [Development](#-development)
- [Contributing](#-contributing)
- [License](#-license)
- [Acknowledgments](#-acknowledgments)
- [Contact](#-contact)
---
## ⨠Features
| Feature | Description |
|---------|-------------|
| š§ **Read Emails** | Fetch unread emails with sender, subject, and preview |
| š **Draft Replies** | Create draft replies in Gmail (doesn't send automatically) |
| š **OAuth 2.0** | Secure authentication with Google |
| š„ļø **Claude Desktop** | Native integration with Claude Desktop app |
---
## š¦ Prerequisites
- **Python 3.10+** (Required - MCP doesn't support Python 3.9 or below)
- **Claude Desktop** installed on your computer
- **Google Cloud Project** with Gmail API enabled
- **Git** (optional, for cloning)
### Check Your Python Version
```bash
python --version
```
> Must show `Python 3.10.x` or higher.
---
## š Installation
### Step 1: Clone the Repository
```bash
git clone https://github.com/TheMlengineer-py/MCP_Server.git
cd MCP_Server
```
### Step 2: Create Virtual Environment (Optional but Recommended)
```bash
python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
```
### Step 3: Install Dependencies
```bash
pip install mcp google-api-python-client google-auth-oauthlib google-auth-httplib2
```
Or use requirements.txt:
```bash
pip install -r requirements.txt
```
---
## š Google Cloud Setup
### Step 1: Create a Google Cloud Project
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
2. Click **"Create Project"**
3. Name your project (e.g., `mcp-gmail-local`)
4. Click **"Create"**
### Step 2: Enable Gmail API
1. Go to **APIs & Services** ā **Library**
2. Search for **"Gmail API"**
3. Click **"Enable"**
### Step 3: Configure OAuth Consent Screen
1. Go to **APIs & Services** ā **OAuth consent screen**
2. Select **"External"** ā Click **"Create"**
3. Fill in required fields:
- **App name:** `Local MCP Gmail`
- **User support email:** Your email
- **Developer contact:** Your email
4. Click **"Save and Continue"**
5. Add scopes:
- `https://www.googleapis.com/auth/gmail.readonly`
- `https://www.googleapis.com/auth/gmail.compose`
6. Add your email as a **Test User**
7. Click **"Save and Continue"**
### Step 4: Create OAuth Credentials
1. Go to **APIs & Services** ā **Credentials**
2. Click **"+ Create Credentials"** ā **"OAuth client ID"**
3. Application type: **"Desktop app"**
4. Name: `Local MCP Gmail Client`
5. Click **"Create"**
6. Click **"Download JSON"**
7. Rename the file to `credentials.json`
8. Move it to the `MCP_Server/` folder
### Step 5: Authenticate
Run this command to generate `token.json`:
```bash
cd MCP_Server
python -c "from app.gmail_auth import get_gmail_service; get_gmail_service(); print('Auth complete')"
```
> A browser window will open. Sign in and grant permissions.
---
## āļø Configuration
### Claude Desktop Config
Locate your Claude Desktop configuration file:
| OS | Path |
|----|------|
| **Windows** | `%APPDATA%\Claude\claude_desktop_config.json` |
| **macOS** | `~/Library/Application Support/Claude/claude_desktop_config.json` |
| **Linux** | `~/.config/Claude/claude_desktop_config.json` |
### Configuration File
Add this configuration (adjust paths for your system):
#### Windows
```json
{
"mcpServers": {
"gmail": {
"command": "C:\\Users\\YourUsername\\AppData\\Local\\Programs\\Python\\Python313\\python.exe",
"args": [
"C:\\Users\\YourUsername\\MCP_Gmail\\MCP_Server\\app\\server.py"
]
}
}
}
```
#### macOS/Linux
```json
{
"mcpServers": {
"gmail": {
"command": "python3",
"args": [
"/Users/YourUsername/MCP_Gmail/MCP_Server/app/server.py"
]
}
}
}
```
### Verify Your Python Path
```bash
# Windows (Git Bash)
which python
# macOS/Linux
which python3
```
> Use the full path in your config.
---
## š® Usage
### Start Claude Desktop
1. Save your `claude_desktop_config.json`
2. **Completely close** Claude Desktop (check system tray)
3. **Reopen** Claude Desktop
4. Look for the Gmail MCP server in the tools
### Verify Connection
In Claude Desktop, you should see the Gmail MCP server connected. If you see an error, check the [Troubleshooting](#-troubleshooting) section.
---
## š¬ Example Prompts
### Reading Emails
> **"Show me my unread emails"**
Claude will fetch and display your unread emails with:
- Sender name
- Subject line
- Email preview snippet
> **"Check my Gmail inbox"**
> **"What emails do I have?"**
> **"List my latest unread messages"**
---
### Creating Draft Replies
> **"Draft a reply to the Usertesting email saying I'm interested in the test opportunity"**
Claude will:
1. Find the email
2. Create a draft reply
3. Save it to your Gmail Drafts folder
> **"Create a draft reply to the first email thanking them for reaching out"**
> **"Reply to the Airtm email explaining I haven't had time to use the service yet"**
> **"Draft a response to Vaultleap asking for more information about their product"**
---
### Combined Workflows
> **"Show me my unread emails and draft a polite decline to any promotional emails"**
> **"Check my inbox and summarize what needs my attention"**
---
## š§ Troubleshooting
### Server Disconnected Error
**Check the logs:**
| OS | Log Location |
|----|--------------|
| **Windows** | `%APPDATA%\Claude\logs\mcp-server-gmail.log` |
| **macOS** | `~/Library/Application Support/Claude/logs/` |
---
### Common Issues
#### 1. `ModuleNotFoundError: No module named 'mcp'`
**Cause:** MCP not installed in the Python version Claude is using.
**Fix:**
```bash
# Use the same Python as in your config
/path/to/python -m pip install mcp
```
---
#### 2. `ModuleNotFoundError: No module named 'app'`
**Cause:** Missing `__init__.py` files.
**Fix:** Create these files:
```bash
touch MCP_Server/__init__.py
touch MCP_Server/app/__init__.py
```
---
#### 3. `MCP requires Python >=3.10`
**Cause:** Using Python 3.9 or older.
**Fix:** Install Python 3.10+ and update your config path.
---
#### 4. `Expecting value: line 1 column 1 (char 0)`
**Cause:** Empty or corrupted `token.json` or `credentials.json`.
**Fix:**
```bash
# Delete and re-authenticate
rm token.json
python -c "from app.gmail_auth import get_gmail_service; get_gmail_service()"
```
---
#### 5. OAuth Error - Browser Won't Open
**Fix:** Manually copy the URL from terminal and paste in browser.
---
### Test Your Setup
Run this diagnostic:
```bash
cd MCP_Server
python tests/test_server.py
```
**Expected output:**
```
[OK] Path configured
[OK] MCP imported successfully
[OK] gmail_auth imported successfully
[OK] gmail_client imported successfully
[OK] Gmail authentication successful
=== All checks passed! Server should work. ===
```
---
## š Project Structure
```
MCP_Server/
āāā .github/
ā āāā workflows/
ā āāā deploy.yml # CI/CD pipeline
āāā app/
ā āāā __init__.py
ā āāā server.py # MCP server entry point
ā āāā gmail_auth.py # OAuth 2.0 authentication
ā āāā gmail_client.py # Gmail API operations
āāā tests/
ā āāā __init__.py
ā āāā conftest.py # Pytest configuration
ā āāā test_server.py # Test suite
āāā docs/
ā āāā images/ # Screenshots & diagrams
āāā credentials.json # Google OAuth credentials (DO NOT COMMIT)
āāā token.json # OAuth token (DO NOT COMMIT)
āāā requirements.txt # Python dependencies
āāā .gitignore # Git ignore rules
āāā LICENSE # MIT License
āāā README.md # This file
```
---
## š Security Notes
> ā ļø **Never commit these files:**
- `credentials.json`
- `token.json`
**Add to your `.gitignore`:**
```
credentials.json
token.json
*.pyc
__pycache__/
venv/
.env
```
---
## š Available MCP Tools
| Tool | Description | Gmail Scope |
|------|-------------|-------------|
| `get_unread_emails` | Fetch unread emails from inbox | `gmail.readonly` |
| `create_draft_reply` | Create a draft reply to an email | `gmail.compose` |
---
## š ļø Development
### Run Server Manually
```bash
cd MCP_Server
python app/server.py
```
> The server communicates via stdin/stdout using JSON-RPC (MCP protocol).
### Run Tests
```bash
# Manual test
python tests/test_server.py
# Pytest
python -m pytest tests/ -v
```
---
## š Requirements
```txt
mcp>=1.0.0
google-api-python-client>=2.0.0
google-auth-oauthlib>=1.0.0
google-auth-httplib2>=0.1.0
```
---
## š¤ Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
---
## š License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
## š Acknowledgments
- [Anthropic](https://anthropic.com) for Claude and the MCP protocol
- [Google](https://developers.google.com/gmail/api) for the Gmail API
---
## š§ Contact
**Dave** - dave.resume.job@gmail.com
**Project Link:** [https://github.com/TheMlengineer-py/MCP_Server](https://github.com/TheMlengineer-py/MCP_Server)
---
<div align="center">
**Made with ā¤ļø for the Claude Desktop community**
</div>This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessOutdated data