Gmail MCP Server
Provides full read and write access to Gmail, including searching, archiving, labeling, auto-unsubscribing, and multi-account support.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Multi-account Gmail MCP Server
Gmail for AI Agents & Assistants
An open-source Model Context Protocol (MCP) server that gives AI agents and assistants full read and write access to Gmail. Connect multiple Gmail accounts, search emails, archive, label, and auto-unsubscribe. All through one server.

Works with Claude, OpenClaw, Cursor, Windsurf, Cline, Continue, and any MCP-compatible client.
Why This Exists
Most AI tools ship with a Gmail integration tied to a single account, with no way to unsubscribe, and they only work inside one app. If you use multiple Gmail accounts, or want the same email tools in Claude, Cursor and your own agents, you're out of luck.
This MCP server fixes that. One server, all your accounts, full read and write access.
Related MCP server: Gmail MCP
Gmail MCP Server vs Built-in Connectors
Feature | Built-in Gmail (Claude) | Gmail MCP Server |
Read and search emails | Yes | Yes |
Drafts, send, labels | Yes | Yes |
Multiple Gmail accounts at once | No | Yes |
Search across all accounts in one call | No | Yes |
Unsubscribe (RFC 8058 one-click + mailto) | No | Yes |
Works with OpenClaw, Cursor, Windsurf, Cline | No | Yes |
Self-hosted, open source | No | Yes |
What is an MCP Server?
Model Context Protocol (MCP) is an open standard that lets AI agents and assistants connect to external tools and data sources. An MCP server exposes tools that any compatible client can call. Think of it as a plugin system for AI.
This Gmail MCP server turns any MCP-compatible AI client into a full-featured email agent.
Gmail MCP Server Features
Multi-account support. Connect multiple Gmail accounts and pick one per call, or search all of them at once.
Full read and write access. Not just reading emails. Archive, label, draft, send, and unsubscribe.
Gmail search syntax. Use Gmail's query language:
is:unread,from:,newer_than:7d,has:attachment, and more.Honest unsubscribe. Uses the RFC 8058 one-click POST or sends the
mailto:request from the right account, and only reports success when the sender accepted it. Anything that needs a human click comes back as a link to open.Batch operations. Fetch batches of emails for AI-powered triage and bulk actions.
Secure by design. OAuth 2.0 authentication, AES-256-GCM encrypted token storage, minimal Gmail scopes.
Deploy anywhere. Vercel (free), Railway, Docker, or your own server.
Available Tools
Tool | Description |
| List all connected Gmail accounts |
| Search and list emails using Gmail query syntax. Supports |
| Get full email content, headers, and parsed unsubscribe links |
| Archive an email by removing it from the inbox |
| Apply a label to an email. Creates the label if it doesn't exist |
| Create a draft (new or a reply in the thread). Nothing is sent |
| Send a new email or reply, or send an existing draft by |
| Unsubscribe from a mailing list (one-click POST or mailto), or return the link to click |
| Fetch a batch of emails for triage. Supports |
Setup Guide: Deploy in 5 Minutes
Prerequisites
A Google Cloud project with the Gmail API enabled
OAuth 2.0 credentials (Web application type)
A hosting platform (Railway, your own server, or Docker)
Step 1: Google Cloud Setup
Go to Google Cloud Console and create a new project
Enable the Gmail API (APIs & Services → Library → search "Gmail API" → Enable)
Configure the OAuth consent screen:
User type: External
Add scopes:
gmail.readonly,gmail.modifyAdd your Gmail addresses as test users
Create OAuth credentials:
APIs & Services → Credentials → Create Credentials → OAuth client ID
Application type: Web application
Authorized redirect URI:
https://your-server-url/oauth/callbackSave the Client ID and Client Secret
Step 2: Deploy
Option A: Deploy to Vercel (free)
Import this repo in Vercel.
vercel.jsonsets the Express presetIn the project, go to Storage and add Upstash for Redis (free plan). This sets
KV_REST_API_URLandKV_REST_API_TOKEN, which is where connected accounts are saved (Vercel's disk does not persist)Add the environment variables from the table below, with
SERVER_URLset tohttps://<project>.vercel.appand noPORTAdd
https://<project>.vercel.app/oauth/callbackas an Authorized redirect URI in Google Cloud ConsoleDeploy
Option B: Deploy to Railway
Click the Deploy button above, or create a new project on Railway connected to this repo
Add these environment variables:
Variable | Value |
| Your OAuth Client ID |
| Your OAuth Client Secret |
| Any random string (32+ characters) |
| Password for the setup page |
| A long random string ( |
| Your app URL (e.g., |
|
|
Generate a domain in Railway (Service → Settings → Networking → Generate Domain)
Update
SERVER_URLwith the generated domainUpdate the Authorized redirect URI in Google Cloud Console to
https://your-domain.railway.app/oauth/callback
Option C: Self-Host
git clone https://github.com/navbuildz/gmail-mcp-server.git
cd gmail-mcp-server
npm install
cp .env.example .env
# Edit .env with your values
npm run build
npm startOption D: Docker
docker build -t gmail-mcp-server .
docker run -p 3000:3000 \
-e GOOGLE_CLIENT_ID=your-client-id \
-e GOOGLE_CLIENT_SECRET=your-client-secret \
-e ENCRYPTION_KEY=your-random-string \
-e ADMIN_PASSWORD=your-password \
-e MCP_SECRET=your-long-random-secret \
-e SERVER_URL=https://your-domain.com \
gmail-mcp-serverStep 3: Connect Gmail Accounts
Visit
https://your-server-url/setupEnter your admin password
Click + Add Gmail Account
Sign in with Google and grant permissions
Repeat for each Gmail account you want to connect
Railway users without Redis: After adding accounts, copy the
TOKENS_DATA=value from the server logs and add it as an environment variable in Railway. This keeps your accounts connected across redeploys.
How to Connect Gmail MCP Server to Claude
Go to Claude → Settings → Connectors
Click + → Add custom connector
Fill in:
Name:
Gmail(or any name you prefer)Remote MCP server URL:
https://your-server-url/mcp/<MCP_SECRET>(choose "No sign-in"; the secret in the path is the credential)Leave OAuth fields blank
Click Add
Start a new conversation and try: "List my connected Gmail accounts"
How to Connect Gmail MCP Server to Cursor
Add to your Cursor MCP settings (.cursor/mcp.json):
{
"mcpServers": {
"gmail": {
"url": "https://your-server-url/mcp/<MCP_SECRET>"
}
}
}How to Connect Gmail MCP Server to Windsurf
Add to your Windsurf MCP configuration:
{
"mcpServers": {
"gmail": {
"serverUrl": "https://your-server-url/mcp/<MCP_SECRET>"
}
}
}Multi-Account Gmail Setup
Connect as many Gmail accounts as you need. Every tool takes an account parameter:
Use a specific email:
"account": "user@gmail.com"Search all accounts at once:
"account": "all"(list_emailsandbatch_processonly; tools that change or send mail act on one account at a time)
Example prompts you can try:
"Show me unread emails from the last 2 days across all accounts"
"Archive all promotional emails in user@gmail.com"
"Find newsletters in each of my accounts and unsubscribe"
"Find emails with attachments from the last week in work@gmail.com"
Unsubscribe from Newsletters with AI
The unsubscribe_email tool tries, in order:
One-click POST (RFC 8058) when the email has
List-UnsubscribeplusList-Unsubscribe-Post. A 2xx response counts as confirmed.mailto: sends the unsubscribe email from the account that received the newsletter.
Manual links. If neither works, it returns the unsubscribe links (from the header and the body) for you to open. It never opens a link and calls that success, because most landing pages still need a click.
Every call returns a status: confirmed (one-click accepted), sent (mailto sent), needs_manual_click (links returned), or failed (no unsubscribe mechanism found).
Try it: "Find newsletters from the last month and unsubscribe from all of them"
Supported MCP Clients
Client | Status | Configuration |
Claude (Web, Desktop, Code) | Supported | Custom connector → Remote MCP server URL |
Supported | MCP configuration | |
Supported |
| |
Supported | MCP configuration | |
Supported | MCP settings | |
Supported | MCP configuration | |
Any MCP-compatible client | Supported | Point to the |
Architecture
AI Agent / Assistant (Claude, OpenClaw, Cursor, Windsurf, Cline)
↓ MCP Protocol (Streamable HTTP)
Gmail MCP Server (Vercel / Railway / Self-hosted / Docker)
├── /mcp/<secret> MCP endpoint (tools)
├── /setup Admin page (add/remove accounts)
├── /oauth/callback Google OAuth callback
└── Token Store Encrypted refresh tokens (Upstash Redis, or a file)
↓
Gmail API (per-account OAuth tokens)Security
OAuth 2.0 for authentication with Google
AES-256-GCM encrypted refresh token storage
Scopes:
gmail.readonly,gmail.modify(which also covers drafts and sending) anduserinfo.email(to know which account was connected). No fullmail.google.comaccess, so nothing is ever permanently deletedNo passwords stored. Your Gmail password never touches the server
Secret MCP endpoint.
/mcp/<MCP_SECRET>is the only way in; anyone with that URL can use every tool, so treat it like a passwordSending is explicit.
create_draftnever sends;send_emaildoes, immediately. Setsend_emailto require approval in your MCP client if you want a confirmation stepPassword-protected setup. The
/setuppage requires admin authenticationRevocable anytime from Google Account Permissions
Gmail Search Query Examples
The list_emails and batch_process tools accept Gmail's full search syntax:
Query | What it finds |
| Unread emails |
| Unread emails from the last 2 days |
| Emails from a specific sender |
| Emails with "invoice" in the subject |
| Emails with attachments |
| Promotional emails |
| Emails from the last week |
| Emails in a date range |
| Unread important emails |
| Emails larger than 5MB |
Contributing
Want to help make this better? Here are some open ideas:
Add email attachment download support
Add
delete_emailtoolAdd
mark_as_read/mark_as_unreadtoolsAdd
remove_labeltoolAdd support for Google Workspace accounts
PRs are welcome. See CONTRIBUTING.md for guidelines.
Tech Stack
Runtime: Node.js 20+
Language: TypeScript
MCP SDK: @modelcontextprotocol/sdk
Gmail API: googleapis
HTTP: Express 5
Auth: Google OAuth 2.0
License
If this project is useful to you, give it a star. It helps others find it.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Give AI agents their own email inboxes: list, read and send mail via scoped, revocable OAuth grants.
Email for AI agents: read, search and send from your Gmail, Outlook, Yahoo, iCloud or IMAP inbox.
Gmail, Outlook, Drive, OneDrive and calendars for AI agents. Many accounts, one endpoint, audit log.
Multiple Gmail accounts, editable Google Sheets & Docs for AI agents. Deny-by-default access rules.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to manage Gmail through natural language, including search, read, send, label, and draft operations via the Model Context Protocol.-
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to send, read, search, and manage Gmail emails, drafts, and labels via the Model Context Protocol.5MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to read, filter, send emails, and check unread counts via the Model Context Protocol using Gmail SMTP/IMAP.-
- AlicenseBqualityDmaintenanceMulti-account Gmail integration for AI assistants via the Model Context Protocol (MCP).35128 npmMIT