Gmail MCP Server
The server provides Gmail email management capabilities via MCP tools.
List unread emails with optional subject filtering
List all emails (inbox or all mail)
Search emails using Gmail query syntax
Delete emails (move to trash and mark read) by position or message ID
Archive emails by position or message ID
List Gmail labels
Create new labels with optional colors
Batch add/remove labels on emails, with auto-removal of other Triage labels when adding a Triage label
View recent email operations (delete, archive, label changes) with configurable limit
Provides tools for managing Gmail inbox, including listing, searching, reading, deleting, archiving, and labeling emails, as well as automated triage and organization.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Gmail MCP Server list my unread emails"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Gmail MCP Server
A purpose-built Model Context Protocol (MCP) server for Gmail integration, allowing AI assistants to review unread emails and perform email management operations.
Features
List Unread Emails: Retrieve unread emails from Gmail inbox with optional subject filtering
List All Emails: Retrieve all emails from Gmail (defaults to inbox, option for all mail)
Search Emails: Search emails using full Gmail query syntax (
from:,to:,subject:,has:attachment,after:,label:,is:starred)Email Content: Access complete email content including headers, body, and metadata
Delete Emails: Permanently delete emails by ID
Archive Emails: Archive emails (remove from inbox) by ID
Web Dashboard: Beautiful, responsive dashboard for intelligent inbox management
Auto-Triage: Automatic email classification and organization every 15 minutes
Auto-Cleanup: Intelligent deletion of trivial emails and archiving of calendar invites
Related MCP server: Gmail MCP Server
Installation
Clone this repository:
git clone <repository-url>
cd gmail-mcp-serverSet up Google OAuth 2.0 credentials:
Go to Google Cloud Console
Create a new project or select an existing one
Enable the Gmail API
Create OAuth 2.0 credentials (Desktop application)
Download the credentials JSON file and save as
credentials.jsonin the project root
Authenticate (see Authentication below):
make authNo separate install step is needed — make auth (and every other make target that needs Python
deps, e.g. test, lint, dashboard) automatically creates a local .venv/ and installs the
project into it on first run. You never need to pip install anything system-wide (many distros
ship an "externally managed" system Python that refuses direct pip install anyway).
Start the server:
.venv/bin/python -m gmail_mcp_server.serverWeb Dashboard & Inbox Management
The Gmail MCP Server includes a powerful web-based dashboard for intelligent inbox management with automatic triaging and organization.
Quick Start
Start the dashboard with:
make dashboardOr manually:
.venv/bin/python app.pyThe dashboard will be available at http://localhost:5000
Dashboard Features
Auto-Triage Every 15 Minutes: Automatically classifies and organizes emails
Intelligent Organization: Groups emails by priority (Critical → Important → Info)
Auto-Cleanup: Automatically deletes trivial field changes and archives calendar invites
Real-time Stats: View total emails, last sync time, and next sync countdown
Quick Navigation: Click email groups to preview Gmail search results
Responsive Design: Works on desktop, tablet, and mobile devices
Manual Refresh: Trigger triage immediately with the refresh button
Using with Claude Code
When using Claude Code, you can leverage this Gmail MCP server to manage your email directly from your development environment:
Inbox Triaging: Use the
/triagecommand to automatically organize and clean your inboxIntegration in Workflows: Claude Code can help analyze email content and suggest actions
Automated Management: Set up the dashboard to run in the background and manage emails while you code
Easy Access: Check your organized inbox without leaving your IDE
To use with Claude Code:
Ensure the MCP server is configured in your
.mcp.jsonClaude Code will have access to the Gmail tools for email management
Use natural language commands to manage emails (e.g., "delete these spam emails", "archive calendar invites")
See DASHBOARD.md for comprehensive dashboard documentation.
MCP Configuration
To use this Gmail MCP server with Claude or gemini-cli, you need to configure a .mcp.json file. This file tells the AI assistant how to connect to your MCP server.
.mcp.json Configuration
Create a .mcp.json file in your home directory or project directory with the following configuration:
{
"mcpServers": {
"gmail": {
"command": "/path/to/gmail-mcp-server/.venv/bin/python3",
"args": ["-m", "gmail_mcp_server.server"],
"cwd": "/path/to/gmail-mcp-server"
}
}
}Configuration Details:
command: The Python interpreter to use. Point this at.venv/bin/python3(created automatically bymake auth) so the server has access to its installed dependencies — a barepython/python3will fail withModuleNotFoundErrorunless those packages happen to be installed system-wide.args: Arguments to pass to the Gmail MCP server modulecwd: The working directory where the Gmail MCP server is installed
For Claude Desktop:
Place the .mcp.json file in your Claude Desktop configuration directory:
macOS:
~/Library/Application Support/Claude/Windows:
%APPDATA%\Claude\Linux:
~/.config/claude/
For gemini-cli:
Place the .mcp.json file in your home directory or specify the path when running gemini-cli.
Example Usage
Once configured, you can use the Gmail MCP server with AI assistants by passing it in your client configuration.
Dashboard PIN Security
The dashboard can be protected with a 4-digit PIN. When configured, the dashboard shows a PIN entry screen on every new session (sessions last 4 hours).
Setting a PIN
make set-pin
# Enter new PIN: ****
# Confirm PIN: ****
# PIN saved.Or use the Python CLI directly:
python3 app.py --set-pinThis writes a PBKDF2-SHA256 hashed PIN to .pincode in the project root. The raw PIN is never stored. Both .pincode and .flask_secret are gitignored.
To remove PIN protection, delete .pincode:
rm .pincodeRunning in Kubernetes
All secrets are consolidated in a single gmail-mcp-secrets Kubernetes Secret (see k8s/secret.yaml_example). When using PIN protection, include the pre-hashed .pincode value there rather than generating it on-disk.
1. Generate the PIN hash locally:
make set-pin # writes .pincode to repo root
cat .pincode # copy the "salt:hash" stringOr generate it directly:
python3 -c "
import secrets, hashlib
pin = '1234' # replace with your PIN
salt = secrets.token_hex(16)
h = hashlib.pbkdf2_hmac('sha256', pin.encode(), salt.encode(), 260000).hex()
print(f'{salt}:{h}')
"2. Add it to your k8s/secret.yaml (alongside the other secrets):
stringData:
.pincode: "salt:hash-from-above"
FLASK_SECRET_KEY: "$(python3 -c 'import secrets; print(secrets.token_hex(32))')"
# ... other fields from k8s/secret.yaml_example3. Apply and deploy:
kubectl apply -f k8s/secret.yaml
kubectl apply -f k8s/deployment.yamlThe entrypoint copies .pincode from the read-only /secrets/ mount to /app/ on startup. FLASK_SECRET_KEY is injected as an environment variable to keep sessions stable across pod restarts.
Make Commands
Use the included Makefile for quick access to common tasks:
# Display available commands
make help
# Initialize Gmail OAuth authentication (requires credentials.json)
make auth
# Set or change the dashboard PIN
make set-pin
# Start the web dashboard
make dashboard
# Stop the running dashboard
make kill-dashboard
# Run inbox triage once (email classification and organization)
make triage
# Watch inbox every 10 minutes (runs triage repeatedly)
make watchYou can specify which Claude model to use with the MODEL variable:
make triage MODEL=haiku # Fast triage with Haiku (default)
make triage MODEL=sonnet # Balanced triage with Sonnet
make triage MODEL=opus # Most capable triage with Opus
make watch MODEL=opusAvailable Tools
1. list_unread_emails
Lists unread emails in Gmail inbox with optional filtering. Rebuilds the in-memory position map used by delete/archive/modify tools.
Parameters:
subject_filter(optional): Filter emails by subject textmax_results(optional): Maximum number of emails to return (default: 50)
2. list_all_emails
Lists emails in Gmail (defaults to inbox, including both read and unread messages). Rebuilds the in-memory position map.
Parameters:
inbox_only(optional): Whether to list only emails currently in inbox (default:true). Set tofalseto list all emails across all folders.max_results(optional): Maximum number of emails to return (default: 50)
3. search_emails
Searches emails using standard Gmail search query syntax. Rebuilds the in-memory position map.
Parameters:
query(required): Gmail search query string (e.g.from:user@example.com,has:attachment,subject:report,after:2024/01/01,is:starred,label:work)max_results(optional): Maximum number of emails to return (default: 50)
4. delete_emails
Moves emails to trash and marks them as read. Accepts position numbers from the last email list/search call and/or explicit Gmail message IDs.
Parameters:
positions(optional): Array of 1-based position numbers from the email listmessage_ids(optional): Array of Gmail message IDs
5. archive_emails
Archives emails (removes from inbox) and marks them as read.
Parameters:
positions(optional): Array of 1-based position numbersmessage_ids(optional): Array of Gmail message IDs
6. list_labels
Returns all Gmail labels (system + user-defined).
Parameters: None
7. create_label
Creates a new Gmail label with optional color.
Parameters:
name(required): Label name (e.g.,Triage/Security)background_color(optional): Hex color (e.g.,#4a86e8) — must be a predefined Gmail colortext_color(optional): Hex text color — must be paired withbackground_color
8. modify_labels
Adds and/or removes labels on emails. When adding a Triage/* label, all other Triage/* labels on the email are automatically removed (one-label-per-email invariant).
Parameters:
positions(optional): Array of 1-based position numbersmessage_ids(optional): Array of Gmail message IDsadd_labels(optional): Array of label names to addremove_labels(optional): Array of label names to remove
9. list_recent_actions
Returns the in-memory log of recent email operations (capped at 100).
Parameters:
limit(optional): Maximum number of actions to return (default: 10)
Authentication
Initial Setup
On first run, the server requires authentication. Use the provided authentication helper:
make authThis automatically creates .venv (if it doesn't exist yet) and installs dependencies into it
before running the auth flow, so no manual pip install step is required.
Or manually, using the project's virtualenv:
.venv/bin/python -m gmail_mcp_server.authThis will:
Check that
credentials.jsonexists in the project rootOpen a browser window for OAuth 2.0 authentication
Request permission to access your Gmail account
Save the authentication token to
token.jsonfor future use
Getting Credentials
Before running make auth, you need to set up Google OAuth 2.0 credentials:
Go to Google Cloud Console
Create a new project or select an existing one
Enable the Gmail API
Create OAuth 2.0 credentials (Desktop application)
Download the credentials JSON file and save as
credentials.jsonin the project root
How It Works
The server checks for an existing authentication token (
token.json) on startupIf the token exists and is valid, the server uses it automatically
If the token is expired but has a refresh token, it refreshes automatically
If no token exists, the server will request authentication using the
make authcommand
Required Gmail API Scopes
https://www.googleapis.com/auth/gmail.readonly- Read emailshttps://www.googleapis.com/auth/gmail.modify- Delete and archive emails
Security Notes
Keep your
credentials.jsonandtoken.jsonfiles secureThese files are automatically ignored by git
The server only requests minimal required permissions
All operations are performed through official Gmail API
Development
make test, make lint, make format, and make auth all automatically create .venv/ (with dev
dependencies) on first run, so there's no separate setup step.
Run tests:
make test # run all tests
make test-cov # run with coverage reportLint and format:
make lint # check with ruff
make format # auto-format and fix imports with ruffRun the MCP server directly:
.venv/bin/python -m gmail_mcp_server # short form (via __main__.py)
.venv/bin/python -m gmail_mcp_server.server # explicit
.venv/bin/gmail-mcp-server # installed entry pointTest the server interactively with the MCP Inspector:
npx @modelcontextprotocol/inspector .venv/bin/python3 -m gmail_mcp_server.serverAvailable Tools
7 toolsarchive_emailsA
Archive emails (remove from inbox). Accepts positions[] from email list and/or message_ids[].
Inputs: positions, message_ids.
create_labelC
Create a new Gmail label
Inputs: name (required), text_color, background_color.
delete_emailsA
Move emails to trash and mark as read. Accepts positions[] from email list and/or message_ids[].
Inputs: positions, message_ids.
list_labelsB
List all Gmail labels
Inputs: no named parameters.
list_recent_actionsB
Show recent actions taken on emails (delete, archive, label changes, etc.)
Inputs: limit.
list_unread_emailsA
List unread emails in Gmail inbox with optional subject filtering
Inputs: max_results, subject_filter.
modify_labelsA
Batch add/remove labels on emails. Accepts positions[] and/or message_ids[], plus add_labels[] and/or remove_labels[] (label names). When adding a Triage/* label, all other Triage/* labels on the email are automatically removed.
Inputs: positions, add_labels, message_ids, remove_labels.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool serves a unique function: listing unread emails, deleting, archiving, managing labels, and viewing recent actions. No two tools have overlapping purposes; even delete_emails and archive_emails are clearly distinguished by their actions.
All tool names follow a consistent verb_noun pattern in snake_case (e.g., list_unread_emails, create_label, modify_labels). The naming is predictable and makes the action-resource relationship clear.
With 7 tools, the server is well-scoped for basic Gmail inbox management and label operations. Each tool addresses a necessary operation without redundancy or unnecessary complexity.
The tool set covers core inbox operations (list, delete, archive) and label management (list, create, modify), but lacks essential features like sending emails, reading full email content, searching beyond unread, or marking read/unread. Gaps exist for a full email workflow.
Maintenance
Related MCP Connectors
Give AI agents their own email inboxes: list, read and send mail via scoped, revocable OAuth grants.
Email for AI agents: read, search and send from your Gmail, Outlook, Yahoo, iCloud or IMAP inbox.
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Gmail, Outlook, Drive, OneDrive and calendars for AI agents. Many accounts, one endpoint, audit log.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to manage Gmail by reading unread emails with automatic classification, creating AI-generated draft replies, and saving drafts directly to Gmail through the Gmail API.-
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with Gmail accounts for reading unread emails, creating draft replies with proper threading, and managing messages, with optional professional writing guidelines, templates, and Google Docs/Calendar integration.-
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to manage Gmail through natural language interactions, including sending, reading, searching emails, and managing labels with auto authentication support.1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to manage Gmail through natural language, including sending, reading, searching, labeling emails, managing attachments, and performing thread operations.3MIT