gmail-mcp-server
Allows reading, searching, sending, and managing emails in Gmail, including attachments, labels, drafts, and privacy redaction.
Click on "Install 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-servershow me my latest emails"
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 comprehensive Model Context Protocol (MCP) server for Gmail, with 17 tools, an interactive CLI setup wizard, a browser-based Web UI wizard, and full Docker support.
Features
Tool | Description |
| List emails from inbox or any label with optional query filter |
| Read full email content (headers + decoded body) |
| Search using Gmail query syntax |
| List message attachments with policy-based safety checks |
| Validate one attachment against local file safety policy |
| Download attachment only if it passes safety policy checks |
| Redact sensitive text through local privacy pipeline |
| Read one email with privacy-redacted subject/snippet/body |
| Send plain-text or HTML emails |
| Create email drafts without sending |
| Reply to an email thread (preserves threading headers) |
| Trash or permanently delete an email |
| Mark email as read |
| Mark email as unread |
| Add/remove labels on an email |
| List all Gmail labels with message counts |
| Get authenticated user profile info |
Attachment safety policy defaults are defined in src/config/attachment-policy.json.
Privacy policy defaults are defined in src/config/privacy-policy.json.
Optional local privacy stack (vLLM + privacy orchestrator) can be started with Docker profiles:
docker compose --profile privacy up --buildThe privacy profile also enables optional persistent services:
Redis (
redis:6379) — token store for session-aware PII re-identification (future feature)SQLite (
audit.db) — audit log of all PII detections and redactions for compliance
See ARCHITECTURE.md for database design details.
Related MCP server: gmail-mcp
Prerequisites
Node.js 20+ (for local setup)
Docker (for containerised setup)
A Google Cloud project with Gmail API enabled and an OAuth2 Client ID (Desktop app type)
Google Cloud Setup (one-time)
Create or select a project
APIs & Services → Library → search "Gmail API" → Enable
APIs & Services → Credentials → Create Credentials → OAuth 2.0 Client ID
Application type: Desktop app
Add Authorized redirect URIs:
http://localhost:3333/oauth/callback← for CLI wizardhttp://localhost:3000/oauth/callback← for Web UI wizard
Note your Client ID and Client Secret (or download
credentials.json)
Quick Start
Option A — CLI Wizard (recommended for developers)
# 1. Install dependencies and build
npm install
npm run build
# 2. Run the interactive CLI setup wizard
npm run setup:cli
# 3. Start the MCP server
npm startThe CLI wizard will:
Guide you through credential input (file / paste JSON / manual entry)
Let you choose Gmail permission scopes
Open your browser for Google sign-in
Automatically capture the OAuth callback and save tokens
Validate the connection and print your email + next steps
Option B — Web UI Wizard (browser-based)
# 1. Install dependencies and build
npm install
npm run build
# 2. Start the setup wizard UI
npm run setup:ui
# 3. Open http://localhost:3000 in your browser
# Complete the 4-step wizard, then start the server:
npm startThe Web UI provides a guided 4-step flow:
Enter OAuth2 credentials
Select permission scopes
Click Authorize Gmail Access → completes Google sign-in flow
Success page with connection stats and next steps
Option C — Manual .env (CI / Docker production)
# Copy and fill in the template
cp .env.example .env
# Edit .env: set GMAIL_CLIENT_ID, GMAIL_CLIENT_SECRET, GMAIL_REFRESH_TOKEN
npm install
npm run build
npm startDocker
Build the image
docker build -t gmail-mcp-server .Run the MCP server (with env vars)
# Copy .env.example → .env and fill in credentials
cp .env.example .env
docker compose upOr pass credentials inline:
docker run -i \
-e GMAIL_CLIENT_ID=your-client-id \
-e GMAIL_CLIENT_SECRET=your-secret \
-e GMAIL_REFRESH_TOKEN=your-refresh-token \
gmail-mcp-serverRun the Web UI Setup Wizard via Docker
docker compose -f docker-compose.setup.yml upThen open http://localhost:3000 — credentials are written back to ./credentials/ on the host via volume mount.
Mount credentials files instead of env vars
docker run -i \
-v ./credentials:/app/credentials:ro \
gmail-mcp-serverEnvironment Variables
Variable | Required | Description |
| Yes* | Google OAuth2 Client ID |
| Yes* | Google OAuth2 Client Secret |
| Yes* | Long-lived refresh token (from setup wizard) |
| No | Override redirect URI (default: |
| No | Web UI setup server port (default: |
* Required when using env vars. Alternatively, use credentials/credentials.json + credentials/token.json (written by the setup wizards).
Add to MCP Client (e.g. Claude Desktop)
Edit your MCP client config:
{
"mcpServers": {
"gmail": {
"command": "node",
"args": ["/absolute/path/to/gmail-mcp-server/dist/index.js"]
}
}
}Or use Docker:
{
"mcpServers": {
"gmail": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "GMAIL_CLIENT_ID=...",
"-e", "GMAIL_CLIENT_SECRET=...",
"-e", "GMAIL_REFRESH_TOKEN=...",
"gmail-mcp-server"
]
}
}
}Project Structure
├── src/
│ ├── index.ts # MCP server entry point
│ ├── gmail/
│ │ ├── auth.ts # OAuth2 credential + token management
│ │ └── client.ts # Gmail API client factory (singleton)
│ ├── tools/
│ │ ├── emails.ts # list_emails, read_email, search_emails
│ │ ├── compose.ts # send_email, create_draft, reply_to_email
│ │ ├── manage.ts # delete_email, mark_as_read/unread, set_labels
│ │ └── meta.ts # get_labels, get_profile
│ └── setup/
│ ├── oauth.ts # Shared OAuth2 URL generation + token exchange
│ ├── cli.ts # Interactive CLI setup wizard
│ └── ui-server.ts # Express Web UI setup server
├── public/
│ └── setup/
│ └── index.html # 4-step Web UI wizard (vanilla HTML/CSS/JS)
├── credentials/ # Runtime secrets — gitignored
│ └── .gitkeep
├── Dockerfile # Multi-stage build (build + runtime)
├── docker-compose.yml # MCP server runtime
├── docker-compose.setup.yml # Web UI setup wizard runtime
├── .env.example # Environment variable template
└── tsconfig.jsonSecurity Notes
credentials/is gitignored — never commitcredentials.jsonortoken.jsonCredentials are not baked into the Docker image — always injected via env vars or volume mounts
The Web UI server and CLI callback server bind to
127.0.0.1only (not publicly accessible)The runtime Docker container runs as a non-root user (
mcp)
Troubleshooting
Problem | Solution |
| Run |
| Re-run the setup wizard to re-authorize |
| Check that Client ID and Secret are correct |
| Ensure the redirect URI is added in Google Cloud Console exactly as shown in the wizard |
| Kill the process using port 3333, or temporarily change |
Token expired / | Re-run the setup wizard to get a fresh refresh token |
Docker: | Mount |
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/enoch-sit/gmail-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server