Gmail Multi-Account MCP Server
Provides tools to manage multiple Gmail accounts and interact with Gmail: send emails with attachments/CC/BCC, search and read messages, modify labels and read state, delete messages, perform batch operations, manage labels and filters, and reply to email threads.
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.
Gmail Multi-Account MCP Server
A Model Context Protocol (MCP) server that enables Claude Desktop to interact with multiple Gmail accounts through secure OAuth 2.0 authentication.
This project is a fork of AlexHramovich/gmail-mcp, extended with additional features inspired by GongRzhe/Gmail-MCP-Server. Full credit to both authors for their original work.
Features
Multiple Account Support - Add, remove, and switch between multiple Gmail accounts
Default Account Management - Set a default account for quick access
Send Emails - Plain text, HTML, multipart, with CC/BCC and file attachments
Search Emails - Use Gmail's powerful search operators (from, subject, has:attachment, newer_than, is:unread, etc.)
Read Emails - Retrieve full email content with attachment metadata
Email Modification - Modify labels, mark as read/unread, delete messages
Batch Operations - Bulk modify labels or delete messages with configurable batch sizes
Attachment Support - Send attachments and download them with path security validation
Label Management - Create, update, delete, and list Gmail labels
Filter Management - Create, list, get, delete filters with pre-built templates
Thread Replies - Reply to email threads with In-Reply-To/References headers
Secure OAuth 2.0 Authentication - No passwords stored; tokens auto-refresh
Security Hardening - MIME header injection prevention, sensitive path blocking, path traversal protection
MCP Inspector - Built-in development tool for testing and debugging
Related MCP server: Gmail MCP Server
Quick Start
Setup Google Cloud Console (see detailed steps below):
Create a project and enable Gmail API
Create OAuth 2.0 Desktop App credentials
Configure OAuth consent screen and add test users
Download credentials as
credentials.json
Install and Build:
bun install bun run buildAdd a Gmail account via CLI:
bun src/cli.ts add your-email@gmail.comThis opens your browser for OAuth consent. Tokens are saved in the project's
accounts/directory.Configure Claude Desktop (see detailed steps below):
Add the MCP server entry to
claude_desktop_config.jsonRestart Claude Desktop
Start Using:
Send an email to john@example.com with subject "Hello" and body "Testing Gmail MCP"
Prerequisites
Bun (latest version) - Install from bun.sh
Claude Desktop application installed
Gmail account with API access enabled
Google Cloud Console project with Gmail API enabled
Setup Instructions
1. Google Cloud Console Setup
Step 1: Create a Google Cloud Project
Go to Google Cloud Console
Click the project dropdown at the top of the page
Click New Project
Enter a project name (e.g., "Gmail MCP Server") and click Create
Make sure the new project is selected in the project dropdown
Step 2: Enable the Gmail API
In the left sidebar, go to APIs & Services > Library
Search for Gmail API
Click on it and click Enable
Step 3: Create OAuth 2.0 Credentials
In the left sidebar, go to APIs & Services > Credentials
Click + Create Credentials at the top
Select Create credentials > choose the Gmail API from the "Select an API" dropdown
Under "What data will you be accessing?", select User data (not "Application data")
Click Next
Step 4: Configure the OAuth Consent Screen
When prompted to configure the OAuth consent screen:
App name: Enter any name (e.g., "Gmail MCP")
User support email: Select your email from the dropdown
App logo: Skip this - leave it blank
Developer contact email: Enter your email address
Click Save and continue
Step 5: Set Scopes (Optional)
On the "Scopes" screen, you can skip this - just click Save and continue
The required scopes are requested at runtime by the MCP server code during the OAuth flow
Step 6: Create the OAuth Client ID
On the "OAuth Client ID" screen, select Desktop app as the application type
Enter a name (e.g., "Gmail MCP Desktop Client") or leave the default
Click Create
Step 7: Download Credentials
Click the Download button to download the credentials JSON file
Rename the downloaded file to
credentials.jsonClick Done
Step 8: Add Test Users
Since the app has a "Testing" publishing status, only registered test users can authenticate:
In the left sidebar, go to APIs & Services > OAuth consent screen (this redirects to the Google Auth Platform Audience page)
Scroll down to the Test users section
Click + Add users
Enter the Gmail address(es) you want to use with the MCP server
You can add multiple test users if you plan to use the multi-account feature
Click Save
2. Project Setup
Clone and Install:
git clone https://github.com/Konadu-Akwasi-Akuoko/gmail-multi-mcp.git cd gmail-multi-mcp bun installBuild the Project:
bun run buildTest the Setup (optional but recommended):
bun run inspectThis opens the MCP Inspector for testing tools before connecting to Claude Desktop.
3. Claude Desktop Integration
Step 1: Open Claude Desktop's config directory
The config directory path contains a space (Application Support), so you need to quote or escape it:
macOS:
cd ~/Library/Application\ Support/Claude/
# or
cd "$HOME/Library/Application Support/Claude/"Note: Tools like
zoxide(z) don't handle spaces in paths well. Use the standardcdcommand with escaping as shown above.
Windows (PowerShell):
cd "$env:APPDATA\Claude\"Linux:
cd ~/.config/claude/Step 2: Place your Google credentials
Place the credentials.json file in the project root directory (not Claude Desktop's config directory):
# From wherever you downloaded it
cp ~/Downloads/credentials.json /path/to/gmail-multi-mcp/Verify it's there:
ls /path/to/gmail-multi-mcp/credentials.jsonStep 3: Edit claude_desktop_config.json
Open the config file in your editor:
# macOS
nano ~/Library/Application\ Support/Claude/claude_desktop_config.json
# or with VS Code
code ~/Library/Application\ Support/Claude/claude_desktop_config.jsonIf the file already has content (like existing preferences), add mcpServers as a sibling key - don't overwrite what's already there. For example, if your file looks like this:
{
"preferences": {
"quickEntryDictationShortcut": "off",
"coworkScheduledTasksEnabled": false,
"sidebarMode": "chat"
}
}Update it to:
{
"preferences": {
"quickEntryDictationShortcut": "off",
"coworkScheduledTasksEnabled": false,
"sidebarMode": "chat"
},
"mcpServers": {
"gmail": {
"command": "bun",
"args": ["/absolute/path/to/your/gmail-multi-mcp/src/index.ts"]
}
}
}If the file is empty or doesn't exist, create it with:
{
"mcpServers": {
"gmail": {
"command": "bun",
"args": ["/absolute/path/to/your/gmail-multi-mcp/src/index.ts"]
}
}
}Important: Replace
/absolute/path/to/your/gmail-multi-mcp/with the actual absolute path to your cloned project. You can get this by runningpwdfrom inside the project directory.
Step 4: Verify bun is accessible
The MCP server uses bun to run. Make sure it's installed and in your PATH:
which bun
# Should output something like: /Users/yourname/.bun/bin/bunIf bun is not found, install it from bun.sh.
Step 5: Restart Claude Desktop
Fully quit Claude Desktop (not just close the window) and reopen it. On macOS, right-click the dock icon and choose Quit, or use Cmd+Q.
After restarting, the Gmail MCP tools should be available in Claude Desktop.
CLI Account Management
The CLI tool manages Gmail accounts separately from the MCP server. This is necessary because the MCP server runs as a background process under Claude Desktop, where a browser OAuth flow can't work.
Why a separate CLI?
When Claude Desktop spawns the MCP server, process.cwd() resolves to Claude Desktop's own directory -- not the project root. The CLI and MCP server both use import.meta.dir to resolve paths relative to the source file, so they always agree on where credentials.json and accounts/ live (the project root).
Commands
# Add a new Gmail account (opens browser for OAuth)
bun src/cli.ts add user@gmail.com
# List all configured accounts
bun src/cli.ts list
# Get or set the default account
bun src/cli.ts default # show current default
bun src/cli.ts default user@gmail.com # set new default
# Re-authenticate an expired token
bun src/cli.ts reauth user@gmail.com
# Remove an account
bun src/cli.ts remove user@gmail.com
# Show the resolved data directory
bun src/cli.ts pathAfter building
If you've run bun run build, you can also use the compiled binary:
bun build/cli.js listEnvironment variable
Set GMAIL_MCP_DATA_DIR to override where the CLI and MCP server look for credentials.json and accounts/:
GMAIL_MCP_DATA_DIR=/custom/path bun src/cli.ts listFirst-Time Authentication
Account setup is done via the CLI tool before connecting to Claude Desktop:
Run
bun src/cli.ts add your-email@gmail.comfrom the project directoryA browser window opens for Google OAuth consent
Sign in and grant the requested permissions
Authentication tokens are stored in the
accounts/directory within the project rootTokens auto-refresh and are valid for 6 months of inactivity
The MCP server reads these pre-existing tokens at runtime (no browser flow needed)
Available Tools
Email Operations
Tool | Description |
| Send emails with HTML, attachments, CC/BCC, and thread reply support |
| Search emails using Gmail search operators |
| Read a specific email by message ID with attachment info |
Email Modification
Tool | Description |
| Add or remove labels on a message |
| Permanently delete a message |
| Mark a message as read |
| Mark a message as unread |
Batch Operations
Tool | Description |
| Bulk add/remove labels on multiple messages |
| Bulk delete multiple messages |
Attachments
Tool | Description |
| Download an email attachment to disk |
Label Management
Tool | Description |
| List all system and user labels |
| Create a new label with visibility options |
| Update a label's name or visibility |
| Delete a user-created label |
| Get existing label or create if missing |
Filter Management
Tool | Description |
| Create a filter with custom criteria and actions |
| List all Gmail filters |
| Get details of a specific filter |
| Delete a filter by ID |
| Create from pre-built templates (fromSender, withSubject, withAttachments, largeEmails, containingText, mailingList) |
Account Management
Tool | Description |
| List all configured Gmail accounts |
| Add a new Gmail account |
| Remove a configured Gmail account |
| Set the default Gmail account |
Development
# Development mode with hot reload
bun run dev
# Test with MCP Inspector
bun run inspect
# Build for production
bun run build
# Type-check without emitting
bun run typecheckArchitecture
Built with TypeScript and follows MCP specifications:
Entry Point:
src/index.ts- MCP server setup and tool definitionsCLI:
src/cli.ts- Commander.js CLI for terminal-based account managementGmail Client:
src/gmail-client.ts- Gmail API wrapper (send, search, read, modify, delete, batch ops, attachments)Account Manager:
src/account-manager.ts- Multi-account credential storage and switchingEmail Utils:
src/email-utils.ts- MIME encoding, email validation, path security, Nodemailer integrationLabel Manager:
src/label-manager.ts- CRUD operations for Gmail labelsFilter Manager:
src/filter-manager.ts- Gmail filter CRUD and pre-built templatesAuthentication:
src/auth.ts- OAuth 2.0 credential managementTypes:
src/types.ts- TypeScript interfaces and type definitions
Troubleshooting
Common Issues
"No account specified and no default account set":
Add an account using the CLI:
bun src/cli.ts add user@gmail.com
"Authentication failed":
Check if
credentials.jsonexists in the project root (bun src/cli.ts pathshows the resolved directory)Verify Gmail API is enabled in Google Cloud Console
Re-authenticate:
bun src/cli.ts reauth user@gmail.com
"Token expired":
Re-authenticate via CLI:
bun src/cli.ts reauth user@gmail.com
Claude Desktop not detecting MCP server:
Verify the absolute path in
claude_desktop_config.jsonis correctMake sure
bunis in your PATH (which bun)Check that
mcpServersis a top-level key in the config, not nested insidepreferencesEnsure the JSON is valid (no trailing commas, proper bracket matching)
Restart Claude Desktop fully (Quit + Reopen, not just close the window)
Check Claude Desktop logs for MCP server errors
zoxide / z can't find the Claude config directory:
The path contains a space (
Application Support). Usecdwith quotes or backslash escaping instead:cd ~/Library/Application\ Support/Claude/
Development and Testing
Test tools without Claude Desktop:
bun run inspectDevelopment mode with hot reload:
bun run devView server logs:
Check Claude Desktop logs for MCP server output
Use Inspector tool for detailed request/response debugging
File Structure
Project Directory:
gmail-multi-mcp/
├── build/ # Compiled JavaScript (auto-generated)
├── accounts/ # Account tokens (auto-generated by CLI)
├── credentials.json # Google OAuth credentials (you provide)
├── src/
│ ├── index.ts # MCP server entry point and tool definitions
│ ├── cli.ts # Commander.js CLI for account management
│ ├── gmail-client.ts # Gmail API wrapper
│ ├── account-manager.ts # Multi-account management
│ ├── email-utils.ts # MIME, validation, security, Nodemailer
│ ├── label-manager.ts # Label CRUD operations
│ ├── filter-manager.ts # Filter CRUD and templates
│ ├── auth.ts # OAuth 2.0 credential management
│ ├── bun.d.ts # Bun-specific type declarations
│ └── types.ts # TypeScript interfaces
├── package.json
└── CLAUDE.mdClaude Desktop Config Directory (only claude_desktop_config.json lives here):
# macOS
~/Library/Application Support/Claude/claude_desktop_config.json
# Linux
~/.config/claude/claude_desktop_config.json
# Windows
%APPDATA%\Claude\claude_desktop_config.jsonSecurity
Uses minimal required Gmail scopes
Tokens stored locally with automatic refresh
No email content stored permanently
All operations performed locally
Attachment paths validated against sensitive directories (~/.ssh, ~/.aws, ~/.env, credentials, etc.)
MIME header injection prevention via CR/LF stripping
Path traversal protection on attachment downloads
Limitations
Rate limits: Gmail API has daily quotas
Token expiry: Tokens expire after 6 months of inactivity
License
MIT
Credits
AlexHramovich/gmail-mcp - Original Gmail MCP server
GongRzhe/Gmail-MCP-Server - Additional feature inspiration
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
Multiple Google accounts (Gmail, Calendar, Drive, Contacts, Tasks) in one Claude connector.
Multiple Google accounts (Gmail, Calendar, Drive, Contacts, Tasks) in one Claude connector.
Connect any IMAP/SMTP mailbox to Claude & ChatGPT: search, read, sort, draft. Sends only with OK.
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI-powered inbox management with natural language commands through Claude Desktop. Supports sending, reading, searching, organizing emails, and managing labels using Gmail API with automatic authentication.8MIT
- 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
- AlicenseAqualityDmaintenanceConnects multiple Gmail accounts to Claude Desktop via MCP, enabling email search, labeling, drafts, and confirmed sending through natural language.13MIT
- FlicenseNot gradedqualityDmaintenanceEnables Claude to read and manage your Gmail account, including listing, searching, sending, drafting, replying to, archiving, labeling, and trashing emails via the Gmail API.-