gmail-mcp
Provides tools for managing multiple Gmail accounts: listing signed-in accounts and their send-as aliases, searching threads with Gmail query syntax, reading conversations as plain text, downloading and saving attachments, and creating, updating, listing, and deleting drafts that thread and reply from the correct alias. Reviewed drafts can then be sent.
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-mcpcheck unread emails to support@example.com and draft replies"
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
A local MCP server that gives Claude Code access to several Gmail accounts at once, and replies to customers from the alias they wrote to (for example support@example.com).
1. What it does
Tool | Purpose |
| Signed-in accounts and the "Send mail as" addresses of each. |
| Search one account with Gmail syntax ( |
| Read a conversation as plain text, including the list of attachments. |
| Download an attachment to the inbox folder and return its local path. |
| Write a draft, optionally with files from the outbox. As a reply, it threads correctly and picks the right alias. Nothing is sent. |
| Revise a draft in place (same draft id). Pass only what changes; existing attachments are kept. |
| Find drafts, e.g. ones created in an earlier session. |
| Discard a draft. Permanent: drafts skip the Trash. |
| Send a draft you reviewed. |
Every tool takes an account. You can pass the account address or one of its aliases: support@example.com resolves to owner@example.com. A new (non-reply) message is then sent from that alias.
Related MCP server: multi-gmail-mcp-server
2. Setup
You do steps 2.1–2.3 once. You repeat step 2.5 for each Google account.
2.1 Gmail: allow sending from each alias
For every alias you want to reply from (support@, sales@, …):
Open Gmail as the account that owns the aliases.
Go to Settings → See all settings → Accounts → Send mail as → Add another email address.
Enter the alias. Leave Treat as an alias ticked.
Because these are aliases of your own Workspace user, Gmail adds them without SMTP setup.
New app later? Add the alias in the Workspace Admin console, and add it here. Receiving needs the first; replying needs the second.
2.2 Google Cloud: create an OAuth client
Open console.cloud.google.com and create a project, e.g.
gmail-mcp.APIs & Services → Library → enable the Gmail API.
Google Auth Platform → Branding: set an app name and your support email.
Audience:
User type: External (needed so personal
@gmail.comaccounts can sign in).Publishing status: click Publish app → In production.
Data Access → add these scopes:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.compose
Clients → Create client → type Desktop app → download the JSON.
Save it as
~/.config/gmail-mcp/client_secret.json:mkdir -p ~/.config/gmail-mcp && chmod 700 ~/.config/gmail-mcpmv ~/Downloads/client_secret_*.json ~/.config/gmail-mcp/client_secret.json
Why "In production"? In "Testing" mode Google expires refresh tokens after 7 days, so you'd have to sign in again every week. In production the app stays unverified, which is fine for personal use. You'll see a warning when signing in (step 2.5).
2.3 Install and build
npm installnpm run build2.4 Register with Claude Code
claude mcp add gmail --scope user -- node <path-to-repo>/dist/index.jsRecommended permissions in ~/.claude/settings.json. Reading and drafting run freely; sending and deleting always ask:
{
"permissions": {
"allow": [
"mcp__gmail__list_accounts",
"mcp__gmail__search_threads",
"mcp__gmail__get_thread",
"mcp__gmail__save_attachment",
"mcp__gmail__list_drafts",
"mcp__gmail__create_draft",
"mcp__gmail__update_draft"
],
"ask": ["mcp__gmail__send_draft", "mcp__gmail__delete_draft"]
}
}2.5 Sign in each account
Run once per account. The address is optional; it only pre-selects the account in the browser.
npm run login -- owner@example.comnpm run login -- you@gmail.comOn the "Google hasn't verified this app" screen, click Advanced → Go to gmail-mcp. This screen appears because you are the app's developer and its only users.
New accounts show up right away; you don't need to restart.
3. How the reply address is chosen
When create_draft gets a replyToMessageId, it decides the From address in this order:
fromargument, if given. It must be a "Send mail as" address.Your own message? If you're following up on a message you sent, it reuses that sender.
The alias the customer wrote to. It takes the first "Send mail as" address found in the original message's
To, thenCc, thenDelivered-Toheaders.The account default as a fallback.
The result always includes from and fromReason, so the choice is never silent.
The reply also:
goes to the customer's
Reply-Toif set, otherwise to the sender;keeps the original subject (with
Re:) and setsIn-Reply-To/References, so Gmail threads it;quotes the original message underneath (turn off with
quoteOriginal: false).
update_draft keeps all of this. It keeps the sender, recipients and threading headers unless you override them. A new body replaces the old text, and reply drafts get the original quoted again underneath.
4. Attachments
Two local folders, created on first start with owner-only access:
Folder | Default | Used for |
Inbox |
|
|
Outbox |
| The only folder files can be attached from. |
4.1 Reading an attachment
get_threadlists each attachment with its name, type, size andpartId.save_attachmentwith themessageIdandpartIddownloads it and returns the path.Claude opens the file from that path (images, PDFs and text files work directly).
Files are never overwritten: saving the same attachment again returns the existing file.
4.2 Attaching a file
Put the file in the outbox, e.g.
~/gmail-mcp/outbox/guide.pdf.Ask Claude to attach it.
create_drafttakesattachments: ["guide.pdf"];update_drafttakesaddAttachmentsandremoveAttachments(by filename).
The combined size limit is Gmail's 25 MB.
4.3 Changing the folders
Create ~/.config/gmail-mcp/config.json and set either key:
{
"inboxDir": "~/Documents/Mail/inbox",
"outboxDir": "~/Documents/Mail/outbox"
}Paths must be absolute or start with ~/. Restart Claude Code sessions to apply.
5. Security model
Concern | How it's handled |
What the server can do | Scopes are |
Accidental sending | Replies are drafts. |
Discarding drafts |
|
Token storage |
|
Leaking local files | Attachments come only from the outbox. Paths outside it, including via |
Untrusted downloads | Attachments are only saved, never opened or run. File names are cleaned so they can't point outside the inbox folder. |
Header injection | Header values with line breaks are rejected. Recipients are validated as email addresses. |
Revoking access | Remove the app at myaccount.google.com/permissions and delete the token file. |
6. Development
npm run checkThis runs typecheck, lint and tests together.
Path | Responsibility |
| Entry point: wires config, auth and the MCP server over stdio. |
| Tool definitions (input schemas, descriptions) → |
| Gmail API calls for every tool. |
| Pure reply planning: recipients, subject, threading, quote. |
| Pure alias selection. |
| Builds the RFC 2822 message, multipart when files are attached. |
| Reads headers and body text out of Gmail payloads. |
| Filename cleanup, outbox path check, inbox saving. |
| Optional |
| OAuth client, token storage, refresh persistence. |
| Browser sign-in (loopback redirect + PKCE). |
The pure modules have no I/O and are covered by unit tests. GmailService is tested against a fake Gmail API in test/service.test.ts.
7. Troubleshooting
Symptom | Fix |
| Admin console → Security → Access and data control → API controls → Manage third-party app access → add your OAuth client ID as Trusted. |
| Copy the file into the outbox first (see section 4.2). |
| Add the alias in Gmail (step 2.1). The server picks up new aliases within 10 minutes. |
| Run |
Tools missing in Claude Code | Run |
This server cannot be deployed
Maintenance
Related MCP Connectors
Multiple Google accounts (Gmail, Calendar, Drive, Contacts, Tasks) in one Claude connector.
Multiple Google accounts (Gmail, Calendar, Drive, Contacts, Tasks) in one Claude connector.
Multiple Gmail accounts, editable Google Sheets & Docs for AI agents. Deny-by-default access rules.
Your mailboxes in ChatGPT and Claude: Gmail, iCloud, Fastmail, any IMAP. Passwords stay yours.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables Claude to read, search, send, label, and trash emails in any Gmail account via Google's Gmail API, using OAuth2 authentication with automatic token refresh.67 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables searching and summarizing emails across multiple Gmail accounts simultaneously through Claude.1MIT
- AlicenseAqualityDmaintenanceConnects multiple Gmail accounts to Claude Desktop via MCP, enabling email search, labeling, drafts, and confirmed sending through natural language.13167 npmMIT
- FlicenseNot gradedqualityBmaintenanceEnables reading, searching, drafting, and sending customer support emails via Gmail directly through Claude, eliminating manual copy-pasting.-