MCP server for Gmail โ send, search, read emails, manage drafts and labels via Google OAuth2.
Project description
Gmail MCP Server
Production-quality Model Context Protocol server for Gmail.
๐ง Send emails โ compose and send with CC support ๐ฅ Read emails โ fetch from any label (INBOX, SENT, etc.) ๐ Search emails โ full Gmail query syntax ๐ Manage drafts โ create and send drafts ๐ท๏ธ Organize labels โ list, add, remove labels ๐งต View threads โ get full conversation threads
Installation
pip install workos-gmail-mcp-server
Or install from source:
cd gmail_mcp_server
pip install -e .
Quick Start
export GOOGLE_CREDENTIALS_PATH=/path/to/credentials.json
export GOOGLE_TOKEN_PATH=/path/to/token.json
gmail-mcp-server
Configuration
| Variable | Required | Description |
|---|---|---|
GOOGLE_CREDENTIALS_PATH |
โ | Path to OAuth2 credentials.json from Google Cloud Console |
GOOGLE_TOKEN_PATH |
โ | Path to token.json (generated after first OAuth consent) |
OAuth Setup Guide
1. Create a Google Cloud Project
- Go to Google Cloud Console
- Create a new project (or select existing)
- Enable the Gmail API under APIs & Services โ Library
2. Configure OAuth Consent Screen
- Go to APIs & Services โ OAuth consent screen
- Choose External user type
- Fill in app name and email
- Add scope:
https://www.googleapis.com/auth/gmail.modify
3. Create OAuth2 Credentials
- Go to APIs & Services โ Credentials
- Click Create Credentials โ OAuth client ID
- Application type: Desktop app
- Download the JSON file as
credentials.json
4. Generate token.json
Run this one-time script to authorize and generate token.json:
from google_auth_oauthlib.flow import InstalledAppFlow
SCOPES = ["https://www.googleapis.com/auth/gmail.modify"]
flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
creds = flow.run_local_server(port=0)
with open("token.json", "w") as f:
f.write(creds.to_json())
print("token.json created successfully!")
5. Set Environment Variables
export GOOGLE_CREDENTIALS_PATH=/absolute/path/to/credentials.json
export GOOGLE_TOKEN_PATH=/absolute/path/to/token.json
Connecting to AI Agents
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"gmail": {
"command": "gmail-mcp-server",
"env": {
"GOOGLE_CREDENTIALS_PATH": "/path/to/credentials.json",
"GOOGLE_TOKEN_PATH": "/path/to/token.json"
}
}
}
}
Cursor / VS Code
Add to .mcp.json in your project root:
{
"mcpServers": {
"gmail": {
"command": "gmail-mcp-server",
"env": {
"GOOGLE_CREDENTIALS_PATH": "/path/to/credentials.json",
"GOOGLE_TOKEN_PATH": "/path/to/token.json"
}
}
}
}
Available Tools
| # | Tool | Description |
|---|---|---|
| 1 | gmail_send_email |
Send an email (to, subject, body, optional cc) |
| 2 | gmail_read_emails |
Read recent emails from a label |
| 3 | gmail_get_email |
Get a single email by message ID |
| 4 | gmail_search_emails |
Search emails using Gmail query syntax |
| 5 | gmail_mark_read |
Mark an email as read |
| 6 | gmail_mark_unread |
Mark an email as unread |
| 7 | gmail_create_draft |
Create a draft email |
| 8 | gmail_send_draft |
Send an existing draft |
| 9 | gmail_list_labels |
List all Gmail labels |
| 10 | gmail_add_label |
Add a label to a message |
| 11 | gmail_remove_label |
Remove a label from a message |
| 12 | gmail_get_thread |
Get a full email thread |
Development
# Install in development mode
pip install -e .
# Run tests
pytest tests/ -v
# Run the server
gmail-mcp-server
Project Structure
gmail_mcp_server/
โโโ pyproject.toml
โโโ LICENSE
โโโ README.md
โโโ server.json
โโโ src/gmail_mcp_server/
โ โโโ __init__.py
โ โโโ __main__.py
โ โโโ config.py
โ โโโ client.py
โ โโโ server.py
โ โโโ tools/
โ โโโ __init__.py
โ โโโ messages.py
โ โโโ drafts.py
โ โโโ labels.py
โ โโโ threads.py
โโโ tests/
โโโ conftest.py
โโโ test_client.py
โโโ test_messages.py
License
MIT
Project details
Release history Release notifications | RSS feed
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 workos_gmail_mcp_server-2.0.0.tar.gz.
File metadata
- Download URL: workos_gmail_mcp_server-2.0.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c82fa56f3817839d27587cb33a55c2189b5f4eebcefa40b7aeaa083db13cbea5
|
|
| MD5 |
61141d6d82c985544e4bb64cfba52fe0
|
|
| BLAKE2b-256 |
1f3349210bca35f2c23324a47044b316532e00ad84c4af2b55ea03e1c3b3f8db
|
File details
Details for the file workos_gmail_mcp_server-2.0.0-py3-none-any.whl.
File metadata
- Download URL: workos_gmail_mcp_server-2.0.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c06f8bb166684ba83a649f18dea0564e47860c3b23d58c593cad69f72b705ce
|
|
| MD5 |
66cc6598070eff5a99d3ab295e9ef843
|
|
| BLAKE2b-256 |
6759791f21c0b68e52d8d42f67ad8dfee143d8b28ef6ed289db743dd0649bc0f
|