gmail-mcp-server
Provides tools for searching, reading, and summarizing emails, as well as creating drafts, sending drafts, and applying custom labels through the Gmail API, with safety boundaries preventing deletions and system-label modifications.
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 Search my inbox for emails from Acme Corp this week and flag anything urgent"
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 working example of connecting Claude to a real business tool — Gmail — the way it should be done: with proper login security, the AI only able to do what it's explicitly allowed to do, and no way for it to take an irreversible action (like sending an email) without a clear checkpoint.
The problem this solves
AI assistants like Claude are increasingly expected to do things, not just talk — search an inbox, draft a reply, flag something urgent — instead of a person copy-pasting between a chat window and their actual tools. That capability is genuinely useful, but connecting an AI assistant directly to something as sensitive as an email account raises an obvious question: what happens if it gets it wrong, or is tricked into doing something it shouldn't?
Most quick "connect my AI to my inbox" setups skip past that question — they hand over broad access and hope for the best. That's the gap this project is built to close. It's a demonstration, using a real Google account and the real Gmail API (not a mock or toy example), of what a properly scoped AI-to-business-tool integration looks like: the AI gets exactly the access it needs for the job, nothing more, and the riskiest action (sending real email) requires an explicit extra step rather than happening automatically.
Related MCP server: gmail-mcp-server
How it stays safe, in plain terms
A specific, limited key — not the master key. Logging in grants three narrow permissions (read mail, draft/send mail, apply labels). There is no permission to delete anything, change account settings, or touch anything outside Gmail.
The key is locked in a safe. Once you log in, the credentials that let Claude access your inbox are encrypted on your own computer. They're never sent anywhere else, and the encryption key lives only in a local file that's never shared or uploaded.
Drafting and sending are two separate, deliberate steps. Claude can prepare a reply as a draft at any time — that's harmless and reversible, the same as you starting an email and not hitting send. Actually sending it is a separate action, clearly flagged to whatever app is running Claude as a sensitive one-way step, so it isn't something that happens as a side effect of Claude just being "helpful."
Labels can't be used to hide or destroy mail. Claude can tag messages with custom labels you create (e.g. "Needs Reply"), but it's structurally blocked from touching Gmail's built-in Trash/Spam/Archive controls through that same feature — a subtle way "just add a label" could otherwise be misused.
The full technical breakdown — exact permissions requested, what's
reversible vs. not, and what the honest residual risk is — is in
SECURITY.md.
Why build this instead of using Google's own Gmail MCP integration
Google has since released its own first-party remote MCP server for Gmail. For someone who just wants Gmail-in-Claude working today, that's the faster path. This project exists for a different reason: to show, on a tool everyone recognizes, the underlying skill of building this kind of integration from scratch — the login flow, the credential storage, the tool design, the safety boundaries — for the many business tools (CRMs, ad platforms, shipping, payments, internal systems) that don't have a ready-made AI integration and need someone to build one deliberately.
See it in action
One-time login: run the authorize command, sign in with Google in the browser that opens, and approve access.
Ask Claude: "Search my inbox for anything from [sender] this week" — it searches, nothing else.
Ask: "Check my inbox and tell me if anything looks urgent" — it pulls a fast summary of recent mail and reasons over it.
Ask: "Draft a reply to that saying I'll follow up tomorrow" — a real draft appears in Gmail. Nothing has been sent.
Only if you then say so, ask Claude to send it — that's the one deliberate, irreversible step in the whole flow.
Under the hood
Tools
Tool | Scope | Description |
| read | Search messages with Gmail search syntax |
| read | Fetch one message's full body |
| read | Fast metadata/snippet fetch for periodic triage |
| write | Create a draft (never sends) |
| write | Send a previously created draft |
| write | Attach a custom (non-system) label |
Setup
Install dependencies (requires Python 3.10+; this repo uses uv):
uv syncSet up Google OAuth and authorize an account — follow
workflows/setup_google_oauth.md. Short version:cp .env.example .env python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())" # paste the output into .env as TOKEN_ENCRYPTION_KEY # download credentials.json from Google Cloud Console into the project root python -m tools.gmail_mcp.authorize personalPoint Claude Desktop/Code at the server. Add to your MCP client config (e.g.
claude_desktop_config.json):{ "mcpServers": { "gmail": { "command": "/absolute/path/to/mcp-business-tools/.venv/bin/python", "args": ["-m", "tools.gmail_mcp.server"], "cwd": "/absolute/path/to/mcp-business-tools" } } }Restart Claude Desktop/Code so it picks up the new server.
Adding more accounts
See workflows/add_gmail_account.md.
Project layout
workflows/ SOPs: OAuth setup, adding accounts, inbox-summary pattern
tools/gmail_mcp/ the MCP server package
config.py env-driven settings, scopes
auth.py OAuth flow + encrypted token storage
gmail_client.py Gmail API wrapper functions
server.py MCP tool definitions
authorize.py one-time per-account OAuth CLI
tokens/ encrypted per-account tokens (gitignored)Available Tools
6 toolsgmail_apply_labelAIdempotent
Attach a custom label to a message (creating it first if needed).
Only user-created labels can be applied through this tool — system labels (TRASH, SPAM, INBOX, UNREAD, IMPORTANT, ...) are rejected, so this tool cannot be used to trash, spam, or archive a message. Returns the label id that was applied.
Inputs: label_name (required), message_id (required), account, create_if_missing. Returns: result
gmail_create_draftA
Create a draft email. This never sends anything.
Pass thread_id to draft a reply within an existing thread (the draft will pick up proper In-Reply-To/References headers automatically).
Inputs: to (required), body (required), subject (required), account, +1 more. Returns: object
gmail_list_recentARead-only
Fast, compact fetch of recent inbox messages for periodic triage.
Intentionally returns metadata + snippet only (no bodies) so it's cheap to call on a schedule. This tool does not decide what's "urgent" — it hands back enough signal (subject, sender, snippet, labels like IMPORTANT/STARRED/UNREAD) for the caller to make that judgment.
Inputs: query, account, max_results. Returns: result
gmail_read_messageBRead-only
Fetch one message in full, including its plain-text body.
Inputs: message_id (required), account. Returns: object
gmail_searchARead-only
Search messages using Gmail's search syntax (e.g. "from:boss is:unread").
Returns compact metadata (id, thread_id, from, subject, date, snippet, labels) — no message bodies. Use gmail_read_message for a full body.
Inputs: query (required), account, max_results. Returns: result
gmail_send_draftADestructive
Send a previously created draft. This is a real, irreversible send.
There is no tool to send arbitrary text directly — a draft must be created first via gmail_create_draft.
Inputs: draft_id (required), account. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Tools are mostly distinct: read/list/search handle retrieval with clear differences in scope, create_draft/send_draft separate drafting from sending, and apply_label handles labeling. One slight overlap exists between gmail_list_recent and gmail_search (both return compact metadata + snippets), though their intended use cases differ enough to disambiguate.
All tools follow a consistent gmail_verb_noun pattern (gmail_read_message, gmail_list_recent, gmail_create_draft, gmail_send_draft, gmail_apply_label, gmail_search). Naming is uniform, clear, and predictable throughout.
Six tools are well-scoped for a Gmail integration server. Each tool covers a distinct core Gmail operation (read, list, draft, send, label, search) without bloat or overlap, falling comfortably within the ideal 3-15 range.
Core read, list, search, draft, send, and label workflows are covered, but there are notable gaps: no update/modify message tools (trash, archive, mark read/unread), no delete draft tool, and no task to list or manage threads as a whole. The label tool explicitly rejects system labels, meaning agents cannot archive or trash messages at all, which is a significant dead end for common email workflows.
Maintenance
Related MCP Connectors
Connect any IMAP/SMTP mailbox to Claude & ChatGPT: search, read, sort, draft. Sends only with OK.
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Email for AI agents: send, receive with a safety verdict, reply and approve, as MCP tools.
Give AI agents their own email inboxes: list, read and send mail via scoped, revocable OAuth grants.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA minimal MCP server that enables Claude to search, read, and manage Gmail messages and threads using official Google API libraries. It supports actions like sending emails, creating drafts, replying to threads, and managing labels through secure OAuth2 authentication.MIT
- AlicenseNot gradedqualityDmaintenanceA secure MCP server that enables Claude to read, search, send, reply, forward, and manage Gmail messages and labels through natural language commands.128 npm1MIT
- AlicenseNot gradedqualityDmaintenanceA custom MCP server that gives Claude full Gmail control — send directly, read, reply, search, label, and delete emails.128 npmMIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that provides Claude with access to your Gmail, featuring a full OAuth 2.1 authorization server with dynamic client registration and tools to list, read, search, send, reply, draft, archive, trash, manage labels, and download attachments.280 npm1MIT