MCP server for Gmail API โ list, read, send, draft, label, and trash emails
Project description
๐ค What is this?
mcp-google-gmail is a Python-based MCP server that acts as a bridge between any MCP-compatible client (like Claude Desktop, Cursor, or Windsurf) and the Gmail API. It allows you to list, read, search, send, draft, label, and trash emails โ all driven by AI through natural language.
๐ Quick Start
Essentially the server runs in one line: uvx mcp-google-gmail@latest.
This command will automatically download the latest code and run it. We recommend always using @latest to ensure you have the newest version with the latest features and bug fixes.
-
โ๏ธ Prerequisite: Google Cloud Setup
- You must configure Google Cloud Platform credentials and enable the Gmail API first.
- โก๏ธ Jump to the Detailed Google Cloud Platform Setup guide below.
-
๐ Install
uvuvxis part ofuv, a fast Python package installer. Install it if you haven't:# macOS / Linux curl -LsSf https://astral.sh/uv/install.sh | sh # Windows powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
-
๐ Authenticate
- Run the built-in auth command to set up your credentials:
# Point to your OAuth credentials file GMAIL_CREDENTIALS_PATH="/path/to/credentials.json" uvx mcp-google-gmail@latest auth
- This opens your browser for Google sign-in. After granting permission, a
token.jsonis saved automatically. - You only need to do this once โ subsequent runs use the cached token.
- Run the built-in auth command to set up your credentials:
-
๐ Run the Server!
uvx mcp-google-gmail@latest -
๐ Connect your MCP Client
- Configure your client (e.g., Claude Desktop) to connect to the running server.
- โก๏ธ See Usage with Claude Desktop for config examples.
You're ready! Start issuing commands via your MCP client.
โจ Key Features
- Full Gmail Access: Read, search, send, draft, label, and trash emails.
- 15 Tools covering all common Gmail operations.
- Flexible Authentication: Supports OAuth 2.0, Service Accounts, Base64 injection, and Application Default Credentials.
- Pagination: All list operations support
page_tokenandmax_results. - Attachments: Send emails with file attachments.
- Reply Threading: Reply to existing threads with proper In-Reply-To headers.
- HTML Email: Send plain text and/or HTML bodies.
- Stdio & SSE Transports: Works with Claude Desktop, Cursor, and remote/container deployments.
๐ Authentication
The auth Command
Before using the MCP server, authenticate with Gmail:
# Using OAuth credentials (interactive โ opens browser)
GMAIL_CREDENTIALS_PATH="/path/to/credentials.json" uvx mcp-google-gmail@latest auth
# Specify where to save the token
GMAIL_CREDENTIALS_PATH="/path/to/credentials.json" \
GMAIL_TOKEN_PATH="/path/to/token.json" \
uvx mcp-google-gmail@latest auth
On success, you'll see:
Credentials path: /path/to/credentials.json
Token path: token.json
Authenticated as: you@gmail.com
Total messages: 12345
Token saved to: token.json
Authentication Priority
The server checks for credentials in this order:
GMAIL_CREDENTIALS_CONFIGโ Base64-encoded service account JSON (env var)GMAIL_SERVICE_ACCOUNT_PATHโ Path to service account key fileGMAIL_TOKEN_PATHโ Path to existing OAuth tokenGMAIL_CREDENTIALS_PATHโ Path to OAuth credentials (interactive browser flow)- Application Default Credentials โ
GOOGLE_APPLICATION_CREDENTIALS/gcloud/ GCP metadata
Method A: OAuth 2.0 (Personal Accounts) ๐งโ๐ป
Best for personal use or local development.
- Set up OAuth credentials in Google Cloud Console (see GCP Setup)
- Run
mcp-google-gmail authto authenticate via browser - Token is cached for future use with automatic refresh
GMAIL_CREDENTIALS_PATHโ Path to OAuthcredentials.json(default:credentials.json)GMAIL_TOKEN_PATHโ Where to store the token (default:token.json)
Method B: Service Account (Servers/Automation) โ
Best for headless environments. Requires domain-wide delegation for accessing user mailboxes.
GMAIL_SERVICE_ACCOUNT_PATHโ Path to service account JSON key (default:service_account.json)
Method C: Base64-Encoded Credentials (Containers) ๐
Best for Docker, Kubernetes, CI/CD where file mounting is impractical.
GMAIL_CREDENTIALS_CONFIGโ Base64-encoded content of your service account JSON- Generate with:
base64 -w 0 service_account.json
Method D: Application Default Credentials (GCP) ๐
Best for Google Cloud environments (Cloud Run, GKE, Compute Engine).
- Uses
GOOGLE_APPLICATION_CREDENTIALSorgcloud auth application-default login - No additional env vars needed โ used as automatic fallback
๐ ๏ธ Available Tools (15 Total)
Read Operations
-
gmail_list_messagesโ List messages with query, labels, pagination (1-500 per page)query(optional): Gmail search query (e.g."is:unread","from:alice@example.com")label_ids(optional): Filter by label IDs (e.g.["INBOX"])max_results(optional, default 20): Messages per page (1-500)page_token(optional): Token for next pageinclude_spam_trash(optional, default false): Include spam/trash- Returns:
{messages: [{id, thread_id, snippet, subject, from, date}], next_page_token, result_size_estimate}
-
gmail_get_messageโ Get full message by ID (headers, body, attachments)message_id: The Gmail message ID- Returns:
{id, thread_id, subject, from, to, cc, date, body_text, body_html, labels, attachments}
-
gmail_search_messagesโ Search with Gmail query syntax, returns compact summaries (1-100 per page). Usegmail_get_messageto read the full body of a result.query: Gmail search query (e.g."has:attachment after:2024/01/01")max_results(optional, default 10): Results per page (1-100)page_token(optional): Token for next page- Returns:
{messages: [{id, thread_id, snippet, subject, from, to, date, labels}], next_page_token, result_size_estimate}
-
gmail_list_draftsโ List drafts with pagination and query filtermax_results(optional, default 20): Drafts per page (1-500)page_token(optional): Token for next pagequery(optional): Gmail search query to filter drafts- Returns:
{drafts: [{draft_id, message_id, subject, to, snippet}], next_page_token, result_size_estimate}
Send Operations
-
gmail_send_messageโ Send email with to/cc/bcc, HTML body, attachments, reply threadingto,subject,body(required)cc,bcc,html_body,attachment_paths(optional)reply_to_message_id,thread_id(optional, for threading)- Returns:
{id, thread_id, label_ids}
-
gmail_create_draftโ Create a draft without sending (same params as send)- Returns:
{draft_id, message_id}
- Returns:
-
gmail_update_draftโ Update an existing draft (merges provided fields with existing)draft_id(required), all other fields optional- Returns:
{draft_id, message_id}
-
gmail_delete_draftโ Permanently delete a draftdraft_id(required)- Returns:
{success: true}
-
gmail_send_draftโ Send an existing draftdraft_id(required)- Returns:
{message_id, thread_id}
Label Operations
-
gmail_list_labelsโ List all labels (system and user-created)- Returns:
{labels: [{id, name, type}]}
- Returns:
-
gmail_create_labelโ Create a new label (supports nesting with/)name: Label name (e.g."Projects/Work")- Returns:
{id, name}
-
gmail_delete_labelโ Delete a user label (system labels cannot be deleted)label_id: The label ID- Returns:
{success: true}
-
gmail_modify_message_labelsโ Add/remove labels from a messagemessage_id(required)add_label_ids(optional): Label IDs to addremove_label_ids(optional): Label IDs to remove- Returns:
{id, label_ids}
Trash Operations
-
gmail_trash_messageโ Move a message to trash (auto-deleted after 30 days)message_id: The message ID- Returns:
{id, label_ids}
-
gmail_untrash_messageโ Restore a message from trashmessage_id: The message ID- Returns:
{id, label_ids}
๐ Usage with Claude Desktop
Add the server config to your claude_desktop_config.json:
๐ต Config: uvx + OAuth (Recommended for personal use)
{
"mcpServers": {
"gmail": {
"command": "uvx",
"args": ["mcp-google-gmail@latest"],
"env": {
"GMAIL_CREDENTIALS_PATH": "/path/to/credentials.json",
"GMAIL_TOKEN_PATH": "/path/to/token.json"
}
}
}
}
๐ macOS Note: If you get a spawn uvx ENOENT error, use the full path:
"command": "/Users/yourusername/.local/bin/uvx"
๐ต Config: uvx + Service Account
{
"mcpServers": {
"gmail": {
"command": "uvx",
"args": ["mcp-google-gmail@latest"],
"env": {
"GMAIL_SERVICE_ACCOUNT_PATH": "/path/to/service_account.json"
}
}
}
}
๐ก Config: Development (from cloned repo)
{
"mcpServers": {
"gmail": {
"command": "uv",
"args": ["run", "--directory", "/path/to/mcp-gmail", "mcp-google-gmail"]
}
}
}
โ๏ธ Usage with Cursor / Windsurf
{
"mcpServers": {
"gmail": {
"command": "uvx",
"args": ["mcp-google-gmail@latest"],
"env": {
"GMAIL_CREDENTIALS_PATH": "/path/to/credentials.json",
"GMAIL_TOKEN_PATH": "/path/to/token.json"
}
}
}
}
๐ณ SSE Transport (Remote / Container)
uv run mcp-google-gmail --transport sse
| Variable | Default | Description |
|---|---|---|
HOST / FASTMCP_HOST |
0.0.0.0 |
Bind address |
PORT / FASTMCP_PORT |
8000 |
Listen port |
โ๏ธ Google Cloud Platform Setup (Detailed)
This setup is required before running the server.
- Create/Select a GCP Project โ Go to the Google Cloud Console
- Enable the Gmail API โ Navigate to "APIs & Services" โ "Library", search for "Gmail API", click Enable
- Configure OAuth Consent Screen โ Go to "APIs & Services" โ "OAuth consent screen", select External, fill in app name and contact email, add the scope
https://www.googleapis.com/auth/gmail.modify - Create OAuth Credentials โ Go to "APIs & Services" โ "Credentials" โ "Create Credentials" โ "OAuth 2.0 Client ID", select Desktop application
- Download Credentials โ Click the download button and save as
credentials.json - Authenticate โ Run the auth command:
GMAIL_CREDENTIALS_PATH="/path/to/credentials.json" uvx mcp-google-gmail@latest auth
Complete the browser sign-in. Atoken.jsonwill be saved for future use.
For Service Accounts: Go to Credentials โ Create Credentials โ Service Account, create a key (JSON), download it. Note: Service accounts require domain-wide delegation for Gmail access.
๐ง Environment Variables Reference
| Variable | Default | Description |
|---|---|---|
GMAIL_CREDENTIALS_CONFIG |
โ | Base64-encoded service account JSON |
GMAIL_SERVICE_ACCOUNT_PATH |
service_account.json |
Path to service account key file |
GMAIL_TOKEN_PATH |
token.json |
Path to OAuth token file |
GMAIL_CREDENTIALS_PATH |
credentials.json |
Path to OAuth client credentials file |
HOST / FASTMCP_HOST |
0.0.0.0 |
SSE transport bind address |
PORT / FASTMCP_PORT |
8000 |
SSE transport port |
๐ฌ Example Prompts for Claude
- "List my 10 most recent unread emails"
- "Search for emails from alice@example.com with attachments"
- "Send an email to bob@example.com with subject 'Meeting Notes' and the body 'Here are the notes from today.'"
- "Create a draft reply to the last email from my manager"
- "Label all emails from newsletter@example.com as 'Newsletters'"
- "Trash all promotional emails from the last week"
- "Show me the full content of message ID abc123"
- "What are my unread emails about project deadlines?"
๐ค Contributing
Contributions are welcome! Please open an issue to discuss bugs or feature requests. Pull requests are appreciated.
๐ License
This project is licensed under the MIT License โ see the LICENSE file for details.
๐ Credits
- Built with FastMCP
- Uses Google API Python Client
- Inspired by mcp-google-sheets
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_google_gmail-0.1.4.tar.gz.
File metadata
- Download URL: mcp_google_gmail-0.1.4.tar.gz
- Upload date:
- Size: 205.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb3a35a0586307f59479b1506b6ece4cb51f798b534e5a880318b000f335e04e
|
|
| MD5 |
620ce354b5621bd3c0262010a786c93c
|
|
| BLAKE2b-256 |
212ab8021c9b49e0875e0aaf95607a81c643f5a91ba07e2b36796d785b2f7fe0
|
File details
Details for the file mcp_google_gmail-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mcp_google_gmail-0.1.4-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a31f24473b16f4c621d8877e2586ba7abd810ec82b972e19eae84ac7d7ba81a9
|
|
| MD5 |
0ea1e81f839849042197ed8776f50e4e
|
|
| BLAKE2b-256 |
4d411d87b53a004b7ff641c65437abe9018f6d2d46cc91e2156dba58f583be95
|