Python MCP server for Gmail drafts, sending, search, and mailbox workflows
Project description
sudo-mcp-gmail
A Python MCP server for Gmail that lets MCP clients such as Claude Desktop, Codex desktop, and other compatible clients use the published package name sudo-mcp-gmail:
- create Gmail drafts with
to,cc,bcc,subject,body_text, optionalbody_html, and attachments from local files or HTTPS URLs - update existing Gmail drafts
- fetch and send Gmail drafts by draft ID
- reply, reply-all, and forward messages
- send Gmail messages with the same fields and attachment support
- list Gmail labels
- mark messages read or unread
- list recent Gmail messages
- read a specific Gmail message
- search Gmail using raw Gmail queries or structured filters such as subject keywords, body keywords, senders, and company domains
- preserve original attachment filenames and file extensions when safely available
Warning: send_gmail_message, send_gmail_draft, reply_to_gmail_message, reply_all_gmail_message, and forward_gmail_message send mail immediately from your Gmail account.
Tools
create_gmail_draft
Creates a Gmail draft with optional attachments.
Inputs:
to: list[str]subject: strbody_text: strcc: list[str] | Nonebcc: list[str] | Nonebody_html: str | Noneattachments: list[str] | None— local file paths or HTTPS URLs
update_gmail_draft
Updates an existing draft by Gmail draft ID.
Inputs:
draft_id: strto: list[str]subject: strbody_text: strcc: list[str] | Nonebcc: list[str] | Nonebody_html: str | Noneattachments: list[str] | None— local file paths or HTTPS URLs
get_gmail_draft
Fetches a draft by Gmail draft ID.
Inputs:
draft_id: str
send_gmail_draft
Sends an existing draft by Gmail draft ID.
Inputs:
draft_id: str
reply_to_gmail_message
Replies to a Gmail message.
Inputs:
message_id: strbody_text: strbody_html: str | Noneattachments: list[str] | None— local file paths or HTTPS URLs
reply_all_gmail_message
Replies-all to a Gmail message.
Inputs:
message_id: strbody_text: strbody_html: str | Noneattachments: list[str] | None— local file paths or HTTPS URLs
forward_gmail_message
Forwards a Gmail message.
Inputs:
message_id: strto: list[str]body_text: strcc: list[str] | Nonebcc: list[str] | Nonebody_html: str | Noneattachments: list[str] | None— local file paths or HTTPS URLs
send_gmail_message
Sends a Gmail message immediately.
Inputs:
to: list[str]subject: strbody_text: strcc: list[str] | Nonebcc: list[str] | Nonebody_html: str | Noneattachments: list[str] | None— local file paths or HTTPS URLs
list_gmail_labels
Lists Gmail labels.
mark_gmail_message_read
Marks a Gmail message as read.
Inputs:
message_id: str
mark_gmail_message_unread
Marks a Gmail message as unread.
Inputs:
message_id: str
list_gmail_messages
Lists Gmail messages.
Inputs:
query: str | Nonelabel_ids: list[str] | Nonemax_results: int
get_gmail_message
Fetches a full Gmail message.
Inputs:
message_id: str
search_gmail_messages
Searches Gmail using structured filters and returns the Gmail query it built.
Inputs:
raw_query: str | Nonesubject_keywords: list[str] | Nonebody_keywords: list[str] | Nonefrom_addresses: list[str] | Nonecompany_domains: list[str] | Nonehas_attachments: bool | Nonenewer_than_days: int | Nonelabel_ids: list[str] | Nonemax_results: int
Prerequisites
- Python 3.10+
- A Google account with Gmail enabled
- A Google Cloud project with the Gmail API enabled
- OAuth desktop client credentials downloaded as JSON
Gmail API setup
- Open Google Cloud Console.
- Create or select a project.
- Enable Gmail API.
- Go to APIs & Services → OAuth consent screen.
- Configure the consent screen.
- Go to APIs & Services → Credentials.
- Create OAuth client ID credentials.
- Choose Desktop app.
- Download the JSON credentials file.
- Save it as
credentials.jsonin the project root, or set a custom path withGMAIL_MCP_CREDENTIALS_FILE.
Install from source
python -m venv .venv
source .venv/Scripts/activate
pip install -e .
Install from pip
After you publish the package to PyPI, install it anywhere without cloning the repo:
pip install sudo-mcp-gmail
Then run it with:
sudo-mcp-gmail
If you want to pin a specific release:
pip install sudo-mcp-gmail==0.1.0
Authentication
The first time the server needs Gmail access, it opens a local browser OAuth flow.
By default:
- client credentials file:
credentials.json - refresh token file:
token.json
Environment variables:
GMAIL_MCP_CREDENTIALS_FILE— path to Google OAuth desktop credentials JSONGMAIL_MCP_TOKEN_FILE— path where the Gmail refresh token will be stored
Example:
export GMAIL_MCP_CREDENTIALS_FILE="C:/path/to/credentials.json"
export GMAIL_MCP_TOKEN_FILE="C:/path/to/token.json"
On Windows PowerShell:
$env:GMAIL_MCP_CREDENTIALS_FILE = "C:\path\to\credentials.json"
$env:GMAIL_MCP_TOKEN_FILE = "C:\path\to\token.json"
Run locally
sudo-mcp-gmail
Claude Desktop MCP config
Add a server entry pointing to the installed command. Example shape:
{
"mcpServers": {
"gmail": {
"command": "sudo-mcp-gmail",
"env": {
"GMAIL_MCP_CREDENTIALS_FILE": "C:/path/to/credentials.json",
"GMAIL_MCP_TOKEN_FILE": "C:/path/to/token.json"
}
}
}
}
If your client requires launching via Python directly, use:
{
"mcpServers": {
"gmail": {
"command": "python",
"args": ["-m", "sudo_mcp_gmail.server"],
"env": {
"GMAIL_MCP_CREDENTIALS_FILE": "C:/path/to/credentials.json",
"GMAIL_MCP_TOKEN_FILE": "C:/path/to/token.json"
}
}
}
}
Codex or other MCP clients
Use the same pattern:
- command:
sudo-mcp-gmailorpython -m sudo_mcp_gmail.server - pass the Gmail credentials/token file paths through environment variables
Attachment URL safety
Remote attachments support HTTPS URLs only.
Blocked attachment sources:
http://...file://...https://localhost/...- private-network or loopback IP targets such as
https://127.0.0.1/...orhttps://192.168.1.10/...
Safety behavior:
- remote downloads are size-limited to 10 MB
- filenames are taken from
Content-Dispositionwhen available, otherwise from the URL path - filenames are sanitized before attaching
- original filename and extension are preserved when safely available
Example prompts in an MCP client
- "Create a Gmail draft to jane@example.com with cc to finance@example.com, subject 'Q2 follow-up', body 'Please see attached', and attach
C:/tmp/report.pdf." - "Update Gmail draft
r-1234567890with a new subject and body." - "Get the Gmail draft with ID
r-1234567890." - "Send the Gmail draft with ID
r-1234567890." - "Reply to message
<message_id>with body 'Thanks, received.'" - "Reply all to message
<message_id>and attachC:/tmp/notes.txt." - "Forward message
<message_id>to jane@example.com with note 'Please review'." - "List Gmail labels."
- "Mark message
<message_id>as read." - "Mark message
<message_id>as unread." - "Send an email to jane@example.com with subject 'Hello', body 'Checking in', and attach
C:/tmp/agenda.docx." - "Create a Gmail draft to jane@example.com and attach
https://example.com/files/report.pdf." - "Send an email to jane@example.com and attach
https://example.com/files/invoice.pdf." - "List my last 10 inbox emails."
- "Get message
<message_id>." - "Search my email for invoices from stripe.com in the last 30 days with attachments."
Security notes
- Keep
credentials.jsonand token files private. - Do not commit OAuth credentials or refresh tokens.
- This server uses the Gmail scope
https://www.googleapis.com/auth/gmail.modify, which allows reading mailbox data, creating drafts, sending messages, replying, forwarding, and modifying labels/read state. - Sending/replying/forwarding tools act immediately, so use them carefully.
- Remote attachment URLs are restricted to HTTPS and blocked for localhost/private-network targets.
- Remote attachment downloads are limited to 10 MB.
Build and publish the pip package
Build distributable artifacts:
python -m pip install --upgrade pip
pip install -e .[dev]
python -m build
This creates:
dist/*.tar.gz— source distributiondist/*.whl— wheel distribution
Validate the package metadata before upload:
python -m twine check dist/*
Upload to TestPyPI first:
python -m twine upload --repository testpypi dist/*
Install from TestPyPI to verify:
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple sudo-mcp-gmail
Upload to PyPI:
python -m twine upload dist/*
After publishing, anyone can install and run it with:
pip install sudo-mcp-gmail
sudo-mcp-gmail
Development
Install development tooling:
pip install -e .[dev]
pytest
Release checklist
- Update the version in
pyproject.tomlandsrc/sudo_mcp_gmail/__init__.py. - Clear old build artifacts if needed.
- Run
pytest. - Run
python -m build. - Run
python -m twine check dist/*. - Upload to TestPyPI, verify install, then upload to PyPI.
- Create a git tag matching the release version if you want versioned releases in GitHub.
Suggested future features
- archive/unarchive tools
- trash/untrash tools
- label add/remove tools for messages and threads
- thread-level tools
- download Gmail attachments
- pagination support for large searches
- unread/starred/important convenience filters
- better HTML sanitization or markdown-to-HTML support for outgoing messages
- attachment metadata in read/search results
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 sudo_mcp_gmail-0.1.0.tar.gz.
File metadata
- Download URL: sudo_mcp_gmail-0.1.0.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8279d36d76f218c693548a4d95d0749013f69f5a477fb59d7fa686f7d33538c4
|
|
| MD5 |
d17d930e8a29a54b893927901429270b
|
|
| BLAKE2b-256 |
9e887903c4f07bf0c0d03abe63d8b6d383670bee1309c1878aae253d0c79bedc
|
File details
Details for the file sudo_mcp_gmail-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sudo_mcp_gmail-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69eb62a0d73f735e4b48a157929fd2c9d9d03427bb4c231cd28284f8bcee0571
|
|
| MD5 |
37328e28143a4df24f502016bd652e32
|
|
| BLAKE2b-256 |
57e7f8d6ab0eb24407939f19a4dd41f1c75dd1ad15886b0895c294f7dd67c22e
|