lakshya1410/Gmail-MCP-Server
If you are the rightful owner of Gmail-MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Gmail MCP Server is a Model Context Protocol server that integrates with the Gmail API to automatically fetch, analyze, and categorize emails, enhancing email management efficiency.
Gmail MCP Server š§
A Model Context Protocol (MCP) server that connects to Gmail API to fetch, analyze, and categorize emails automatically. This server helps you quickly identify important emails, ignore routine messages, and spot deletable promotional content.
Features āØ
- Gmail Integration: Secure OAuth2 authentication with Gmail API
- Smart Email Analysis: Automatically categorizes emails into:
- š“ Important: Urgent emails requiring attention
- š” Ignorable: Regular emails that can wait
- š¢ Deletable: Promotional/spam emails safe to delete
- Flexible Fetching: Get unread emails or recent messages
- MCP Compatible: Works with Claude Desktop and other MCP clients
Setup š
1. Prerequisites
- Python 3.12+
- Google Cloud Console project with Gmail API enabled
- Gmail account
2. Google Cloud Setup
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Gmail API
- Create OAuth 2.0 credentials (Desktop Application)
- Download the credentials as
credentials.json
3. Installation
# Clone or download the server files
# Ensure credentials.json is in the project directory
# Install dependencies
pip install google>=3.0.0 google-api-python-client>=2.170.0 google-auth>=2.40.2 google-auth-oauthlib>=1.2.2 mcp>=1.9.1
# or with uv:
uv add google>=3.0.0 google-api-python-client>=2.170.0 google-auth>=2.40.2 google-auth-oauthlib>=1.2.2 mcp>=1.9.1
4. Test Authentication
python gmail_auth_test.py
This will open your browser for Gmail OAuth approval and save authentication tokens.
Usage š»
Add to Claude Desktop
Add the following to your Claude Desktop configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
Mac: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"gmail-analyzer": {
"command": "python",
"args": ["path/to/your/main.py"],
"env": {}
}
}
}
Replace path/to/your/main.py
with the actual path to your server files.
Standalone Testing
# Test the email analyzer directly
python gmail_analyzer.py
# Test authentication
python gmail_auth_test.py
MCP Server
# Run the MCP server
python main.py
Available Tools
test_connection
Test if the MCP server is working correctly.
fetch_and_analyze_gmail
Fetch emails from Gmail and analyze them automatically.
max_emails
(int): Maximum emails to fetch (default: 5)unread_only
(bool): Only fetch unread emails (default: true)
analyze_emails
Analyze provided email content and categorize them.
emails
(array): List of email contents to analyze
File Structure š
āāā main.py # MCP server implementation
āāā gmail_analyzer.py # Standalone email analyzer
āāā gmail_auth_test.py # Authentication testing script
āāā credentials.json # Google OAuth credentials (you provide)
āāā token.json # Generated authentication tokens
āāā pyproject.toml # Project dependencies
āāā README.md # This file
Email Categorization Logic š§
Important Emails contain keywords like:
urgent
,asap
,important
,critical
,deadline
meeting
,schedule
,follow up
,action required
boss
,manager
,client
,customer
Deletable Emails contain keywords like:
unsubscribe
,newsletter
,promotion
,deal
sale
,discount
,marketing
,advertisement
Ignorable Emails are everything else that doesn't fall into the above categories.
Security & Privacy š
- Uses OAuth2 for secure Gmail authentication
- Only requests read-only access to Gmail (
gmail.readonly
scope) - Credentials are stored locally in
token.json
- No email content is stored permanently or sent to external services
Troubleshooting š§
Common Issues
"Credentials file not found"
- Ensure
credentials.json
is in the same directory as the Python files
"Authentication failed"
- Run
python gmail_auth_test.py
to reset authentication - Check that Gmail API is enabled in Google Cloud Console
"No emails found"
- Try setting
unread_only: false
to fetch recent emails instead - Check your Gmail account has emails
Getting Help
- Run the authentication test script first
- Check the Google Cloud Console for API quotas and permissions
- Ensure your OAuth consent screen is properly configured
Dependencies š¦
-
google-api-python-client
: Gmail API client -
google-auth
: Google authentication -
google-auth-oauthlib
: OAuth2 flow -
mcp
: Model Context Protocol frameworkBuild by Lakshya Tripathi