navbuildz

Multi-account Gmail MCP Server

Community navbuildz
Updated

Multi-account Gmail MCP server: connect multiple Gmail accounts to Claude, Cursor, Windsurf and any MCP client. Search all inboxes at once, archive, label, send, one-click unsubscribe.

Multi-account Gmail MCP Server

Gmail for AI Agents & Assistants

A Gmail MCP server for multiple accounts: connect two, five or ten Gmail inboxes and search them all in one call. This open-source Model Context Protocol (MCP) server gives Claude, Cursor, Windsurf and other AI agents full read and write access to Gmail: search, archive, label, draft, send, and unsubscribe from newsletters.

Website and setup guide · Tools · FAQ · Security · Report an issue

Multi-account Gmail MCP server for Claude, Cursor and Windsurf

Works with Claude, OpenClaw, Cursor, Windsurf, Cline, Continue, and any MCP-compatible client.

Deploy on Railway

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.

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_accounts List all connected Gmail accounts
list_emails Search and list emails using Gmail query syntax. Supports account="all"
get_email Get full email content, headers, and parsed unsubscribe links
archive_email Archive an email by removing it from the inbox
apply_label Apply a label to an email. Creates the label if it doesn't exist
create_draft Create a draft (new or a reply in the thread). Nothing is sent
send_email Send a new email or reply, or send an existing draft by draft_id
unsubscribe_email Unsubscribe from a mailing list (one-click POST or mailto), or return the link to click
batch_process Fetch a batch of emails for triage. Supports account="all"

Setup Guide: Deploy in 5 Minutes

Prefer a shorter walkthrough? The website has the same four steps with copy-paste config for Claude, Cursor and Windsurf.

Prerequisites

  1. A Google Cloud project with the Gmail API enabled
  2. OAuth 2.0 credentials (Web application type)
  3. A hosting platform (Railway, your own server, or Docker)

Step 1: Google Cloud Setup

  1. Go to Google Cloud Console and create a new project
  2. Enable the Gmail API (APIs & Services → Library → search "Gmail API" → Enable)
  3. Configure the OAuth consent screen:
    • User type: External
    • Add scopes: gmail.readonly, gmail.modify
    • Add your Gmail addresses as test users
  4. Create OAuth credentials:
    • APIs & Services → Credentials → Create Credentials → OAuth client ID
    • Application type: Web application
    • Authorized redirect URI: https://your-server-url/oauth/callback
    • Save the Client ID and Client Secret

Step 2: Deploy

Option A: Deploy to Vercel (free)
  1. Import this repo in Vercel. vercel.json sets the Express preset
  2. In the project, go to Storage and add Upstash for Redis (free plan). This sets KV_REST_API_URL and KV_REST_API_TOKEN, which is where connected accounts are saved (Vercel's disk does not persist)
  3. Add the environment variables from the table below, with SERVER_URL set to https://<project>.vercel.app and no PORT
  4. Add https://<project>.vercel.app/oauth/callback as an Authorized redirect URI in Google Cloud Console
  5. Deploy
Option B: Deploy to Railway
  1. Click the Deploy button above, or create a new project on Railway connected to this repo
  2. Add these environment variables:
Variable Value
GOOGLE_CLIENT_ID Your OAuth Client ID
GOOGLE_CLIENT_SECRET Your OAuth Client Secret
ENCRYPTION_KEY Any random string (32+ characters)
ADMIN_PASSWORD Password for the setup page
MCP_SECRET A long random string (openssl rand -hex 24). The MCP endpoint is /mcp/<MCP_SECRET>; without it every MCP request returns 404
SERVER_URL Your app URL (e.g., https://your-app.railway.app)
PORT 3000
  1. Generate a domain in Railway (Service → Settings → Networking → Generate Domain)
  2. Update SERVER_URL with the generated domain
  3. Update 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 start
Option 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-server
Keep your accounts across Docker restarts

The container stores connected accounts (encrypted) in /app/data. Mount that folder on a volume, or every new container starts with no accounts:

docker run -p 3000:3000 -v gmail-mcp-data:/app/data \
  -e GOOGLE_CLIENT_ID=... -e GOOGLE_CLIENT_SECRET=... \
  -e ENCRYPTION_KEY=... -e ADMIN_PASSWORD=... \
  -e MCP_SECRET=... -e SERVER_URL=https://your-domain.com \
  gmail-mcp-server

With Docker Compose:

services:
  gmail-mcp:
    image: gmail-mcp-server
    ports: ["3000:3000"]
    env_file: .env
    volumes:
      - gmail-mcp-data:/app/data
volumes:
  gmail-mcp-data:

Docker Swarm, Kubernetes or any setup where the container can move between nodes: a local volume stays on one node. Either use shared storage for /app/data (NFS, a cloud volume), or skip the disk and set KV_REST_API_URL and KV_REST_API_TOKEN from a free Upstash Redis database. The server then keeps accounts in Redis and works the same wherever it runs. Keep ENCRYPTION_KEY the same across restarts, or stored tokens cannot be decrypted.

Step 3: Connect Gmail Accounts

  1. Visit https://your-server-url/setup
  2. Enter your admin password
  3. Click + Add Gmail Account
  4. Sign in with Google and grant permissions
  5. 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

  1. Go to Claude → Settings → Connectors
  2. Click + → Add custom connector
  3. 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
  4. Click Add
  5. 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": "[email protected]"
  • Search all accounts at once: "account": "all" (list_emails and batch_process only; 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 [email protected]"
  • "Find newsletters in each of my accounts and unsubscribe"
  • "Find emails with attachments from the last week in [email protected]"

Unsubscribe from Newsletters with AI

The unsubscribe_email tool tries, in order:

  1. One-click POST (RFC 8058) when the email has List-Unsubscribe plus List-Unsubscribe-Post. A 2xx response counts as confirmed.
  2. mailto: sends the unsubscribe email from the account that received the newsletter.
  3. 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
OpenClaw Supported MCP configuration
Cursor Supported .cursor/mcp.json
Windsurf Supported MCP configuration
Cline Supported MCP settings
Continue Supported MCP configuration
Any MCP-compatible client Supported Point to the /mcp/<MCP_SECRET> endpoint

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) and userinfo.email (to know which account was connected). No full mail.google.com access, so nothing is ever permanently deleted
  • No 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 password
  • Sending is explicit. create_draft never sends; send_email does, immediately. Set send_email to require approval in your MCP client if you want a confirmation step
  • Password-protected setup. The /setup page requires admin authentication
  • Revocable 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
is:unread Unread emails
is:unread newer_than:2d Unread emails from the last 2 days
from:[email protected] Emails from a specific sender
subject:invoice Emails with "invoice" in the subject
has:attachment Emails with attachments
category:promotions Promotional emails
newer_than:7d Emails from the last week
after:2025/01/01 before:2025/02/01 Emails in a date range
label:important is:unread Unread important emails
larger:5M Emails larger than 5MB

FAQ

Can I use multiple Gmail accounts with Claude?

Yes. Connect each account once on the /setup page, then add the server to Claude as a custom connector. Every tool takes an account parameter, and list_emails and batch_process accept "account": "all" to search every inbox in one call.

How is this Gmail MCP server for multiple accounts different from the built-in Gmail connector?

The built-in connector works with one account. This server holds as many as you connect, searches across all of them at once, unsubscribes from newsletters, and works with Cursor, Windsurf, Cline and any other MCP client, not just Claude.

Does it work with Claude Desktop?

Yes, through Claude's custom connector. In Claude go to Settings, then Connectors, then Add custom connector, and paste your /mcp/<MCP_SECRET> URL. The server runs on your own host (Vercel, Railway, Docker or a VPS); a local mode that Claude Desktop launches directly is not built yet.

Does it work with Google Workspace accounts?

It is built and tested with personal Gmail accounts. Workspace support is on the to-do list below.

Is it safe to give an MCP server access to Gmail?

It asks only for gmail.readonly and gmail.modify, never full mail.google.com access, so nothing is permanently deleted. Refresh tokens are encrypted with AES-256-GCM, and you can revoke access any time from your Google Account permissions. See Security.

Can it unsubscribe from newsletters?

Yes. See Unsubscribe from Newsletters with AI. It only reports success when the sender accepted the request.

More answers, with the same questions as structured data, are on the website FAQ.

Contributing

Want to help make this better? Here are some open ideas:

  • Add email attachment download support
  • Add delete_email tool
  • Add mark_as_read / mark_as_unread tools
  • Add remove_label tool
  • Add support for Google Workspace accounts

PRs are welcome. See CONTRIBUTING.md for guidelines.

Tech Stack

License

MIT

If this project is useful to you, give it a star. It helps others find it. Website: multi-account-gmail-mcp.vercel.app.

MCP Server · Populars

MCP Server · New

    postgres-ai

    PostgresAI

    postgresai – Postgres observability built for humans and AI agents

    Community postgres-ai
    auto-mobile-oss

    AutoMobile

    Mobile automation suite of tools including an MCP and libraries for test authoring & execution

    Community auto-mobile-oss
    clearframes

    MCP Observatory

    Free, MIT-licensed MCP security testing from ClearFrame. Scan, audit, compare, and review locally; continue in the ClearFrame CLI or Mac app.

    Community clearframes
    umutkeltek

    healthsave-observatory

    Self-hosted health-data observatory: sync Apple Health, early wearable plugins, and Garmin/Samsung imports into a canonical TimescaleDB record; view baseline-linked findings and query a private API. Docker-ready, local-first, default-deny egress.

    Community umutkeltek
    atilaahmettaner

    TradingMCP: Market Data & Technical Analysis for AI Assistants

    MCP server for market analysis in AI assistants: quotes, options, smart-money analysis, walk-forward backtests and news sentiment for stocks, crypto, FX and metals. 13 tools. Self-host free, or use the hosted version, TradingMCP.

    Community atilaahmettaner