Gmail MCP Server
Provides tools to read and write Gmail messages, manage labels, search emails, create drafts, and send emails.
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 MCP Serversearch for unread emails from last week"
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 self-hostable Model Context Protocol server that exposes Gmail read and write tools. Connect it to Claude Code or Claude.ai to let Claude manage your email.
Prerequisites
Node.js 20+
A Google Cloud project with Gmail API enabled
OAuth 2.0 credentials (Desktop app type)
Related MCP server: Gmail MCP Server
Setup
1. Create Google Cloud Credentials
Go to the Google Cloud Console
Create a new project (or select an existing one)
Enable the Gmail API:
Navigate to APIs & Services > Library
Search for "Gmail API" and click Enable
Create OAuth credentials:
Navigate to APIs & Services > Credentials
Click Create Credentials > OAuth client ID
Select Desktop app as the application type
Name it (e.g., "Gmail MCP Server")
Click Create
Copy the Client ID and Client Secret
2. Configure Environment
cd gmail-mcp
cp .env.example .envEdit .env and fill in your credentials:
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret3. Install Dependencies
npm install4. Authenticate with Gmail
npm run authThis opens your browser for Google's OAuth consent screen. After granting access, the refresh token is automatically saved to .env.
Note: If you've previously authorized and need to re-authenticate, revoke access at Google Account Permissions first, then run
npm run authagain.
5. Start the Server
For Claude Code (stdio transport):
npm startFor Claude.ai (HTTP/SSE transport):
npm run start:httpConnecting to Claude Code
Add to your Claude Code MCP config (~/.claude.json or project .mcp.json):
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": ["tsx", "/absolute/path/to/gmail-mcp/src/index.ts"],
"env": {
"GOOGLE_CLIENT_ID": "your-client-id",
"GOOGLE_CLIENT_SECRET": "your-client-secret",
"GOOGLE_REFRESH_TOKEN": "your-refresh-token"
}
}
}
}Or if you prefer it to read from .env automatically, use a wrapper:
{
"mcpServers": {
"gmail": {
"command": "npm",
"args": ["start", "--prefix", "/absolute/path/to/gmail-mcp"]
}
}
}Connecting to Claude.ai
Start the HTTP server:
npm run start:httpThe server listens on
http://127.0.0.1:3000by default (changePORTin.env)If you need remote access, use a tunnel (e.g.,
ngrok http 3000or Cloudflare Tunnel)In Claude.ai, add the SSE endpoint URL as a custom MCP server:
http://localhost:3000/sse
Available Tools
Read Tools
Tool | Description |
| Search Gmail using Gmail search syntax. Params: |
| Read a full message with decoded body. Params: |
| Read all messages in a thread. Params: |
| List all Gmail labels (system + user) with IDs |
| Get email address and message/thread counts |
Write Tools (all marked MUTATING)
Tool | Description |
| Add/remove labels on a message. Params: |
| Add/remove labels on a thread. Params: |
| Archive a message (removes INBOX label). Params: |
| Archive a thread. Params: |
| Move to Trash (auto-deleted after 30 days). Params: |
| Create a new label. Params: |
| Send an email (or reply). Params: |
| Create a draft (or reply draft). Params: |
Gmail Search Syntax Examples
from:alice@example.com # Messages from a specific sender
to:bob@example.com # Messages to a specific recipient
subject:meeting # Subject contains "meeting"
has:attachment # Messages with attachments
is:unread # Unread messages
is:starred # Starred messages
label:INBOX # Messages in Inbox
label:Subscriptions # Messages with a user label
after:2025/01/01 # Messages after a date
before:2025/06/01 # Messages before a date
newer_than:7d # Messages from the last 7 days
from:alice subject:project # Combine multiple criteriaYour Labels
System labels: INBOX, SENT, DRAFT, TRASH, SPAM, STARRED, IMPORTANT, CATEGORY_PERSONAL, CATEGORY_SOCIAL, CATEGORY_PROMOTIONS, CATEGORY_UPDATES, CATEGORY_FORUMS
User labels: Subscriptions, My Finance, Receipts, My Travel, Taxes, DFL, Integral Function, PV 2025, Scotland, mini-split, eclips
Tip: Use
list_labelsto get the exact label IDs needed forlabel_messageandlabel_threadoperations.
Security Notes
The refresh token in
.envgrants access to your Gmail. Never commit.envto version control.The HTTP server binds to
127.0.0.1only (localhost). Use a tunnel for remote access.The
gmail.modifyscope is used — this allows reading, labeling, archiving, trashing, and sending, but does not allow permanent message deletion.
This server cannot be deployed
Maintenance
Related MCP Connectors
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Connect any mailbox to Claude, ChatGPT & AI: read, send, reply, schedule & search emails.
Manage Gmail messages, threads, labels, drafts, and settings from your workflows. Send and organiz…
Your mailboxes in ChatGPT and Claude: Gmail, iCloud, Fastmail, any IMAP. Passwords stay yours.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables reading, sending, searching, and managing Gmail through Claude using the official Google Gmail API.144 npm3MIT
- 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
- FlicenseNot gradedqualityDmaintenanceProvides Claude with Gmail capabilities including sending emails, managing drafts, and searching messages.-
- AlicenseNot gradedqualityDmaintenanceEnables Gmail integration with Claude Code for reading, sending, searching emails, and managing labels through natural language.2,341 npmMIT