Gmail MCP Server
Allows AI agents to search, read, send, draft, and manage Gmail messages, labels, and attachments through the Gmail REST API.
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 Serverfind my latest emails from Sarah"
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
Production-ready Model Context Protocol (MCP) server for Gmail. Exposes search, read, send, draft, attachment, label, and delete operations to AI agents via FastMCP and the Google Gmail REST API.
Architecture
AI Agent (Claude, Cursor, VS Code)
│
▼
MCP Protocol (stdio)
│
▼
FastMCP Server (app.py)
│
┌────┴────┬──────────┐
▼ ▼ ▼
Tools Resources Prompts
│ │ │
└────┬────┴──────────┘
▼
GmailClient (gmail_client.py)
│
▼
Authentication (auth.py)
│
▼
Google Gmail REST APIDesign principles:
MCP tools never call Google APIs directly — all requests go through
GmailClientAuthentication lives exclusively in
auth.pyConfiguration lives exclusively in
config.pyBusiness logic is separated from the MCP layer
Related MCP server: Gmail Streamable MCP Server
Features
Tools
Tool | Description |
| Search by sender, recipient, subject, label, date, attachments, unread, or custom query |
| Read full email with subject, body, attachments, labels, thread ID |
| Send plain text or HTML with CC, BCC, attachments |
| Create drafts with HTML and attachments |
| Download a single attachment |
| Download all attachments from a message |
| Save attachment to local disk |
| List all Gmail labels |
| Create a new label |
| Delete a user label |
| Update label properties |
| Permanently delete a message |
| Move message to trash |
| Restore message from trash |
Resources (read-only)
URI | Description |
| Recent inbox messages |
| Unread messages |
| All labels |
| Draft messages |
| Messages from the last 7 days |
Prompts
Prompt | Description |
| Search unread → read → summarize workflow |
| Find invoices → download PDFs → return metadata |
Installation
Prerequisites
Python 3.11+
A Google Cloud project with Gmail API enabled
OAuth 2.0 Desktop client credentials
Setup
# Clone or navigate to the project
cd gmail_mcp_server
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .envPlace your OAuth client secrets file at credentials.json in the project root (or set GMAIL_CREDENTIALS_PATH in .env).
Docker (recommended)
Run the server in a container — no local Python virtualenv required.
Prerequisites
Docker and Docker Compose
credentials.jsonin the project roottouch token.jsonbefore first run (empty file so Docker can mount it)
First-time OAuth (inside Docker)
docker compose --profile auth run --rm --service-ports gmail-authOpens a browser on your machine. After sign-in, token.json is saved on the host.
Run the MCP server
docker compose run --rm -i gmail-mcpConnect Cursor via Docker
{
"mcpServers": {
"gmail": {
"command": "docker",
"args": [
"compose",
"-f",
"/Users/varunnegi/gmail_mcp_server/docker-compose.yml",
"run",
"--rm",
"-i",
"gmail-mcp"
]
}
}
}Use the absolute path to your docker-compose.yml.
Docker vs local venv
Approach | Pros | Cons |
Docker | Reproducible, no local Python setup, easy cleanup | Slightly slower startup, OAuth needs one extra step |
Local venv | Faster startup, simpler OAuth in browser | Must manage Python version and dependencies |
You can delete .venv if you use Docker exclusively.
Local Installation (without Docker)
Prerequisites
Python 3.11+
A Google Cloud project with Gmail API enabled
OAuth 2.0 Desktop client credentials
Setup
# Clone or navigate to the project
cd gmail_mcp_server
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .envPlace your OAuth client secrets file at credentials.json in the project root.
Go to Google Cloud Console
Create a new project (or select an existing one)
Enable the Gmail API: APIs & Services → Library → search "Gmail API" → Enable
Configure OAuth consent screen: APIs & Services → OAuth consent screen
Choose External (or Internal for Workspace)
Add scopes:
gmail.readonly,gmail.send,gmail.modify,gmail.labels,gmail.composeAdd your email as a test user (while in testing mode)
Create credentials: APIs & Services → Credentials → Create Credentials → OAuth client ID
Application type: Desktop app
Download the JSON file and save as
credentials.json
OAuth Setup
On first run, the server opens a browser window for Google OAuth consent. After approval, a token.json file is created and reused on subsequent runs. Tokens refresh automatically.
python app.pyTo force re-authentication, delete token.json and restart.
Running the Server
source .venv/bin/activate
python app.pyThe server uses stdio transport — it communicates over stdin/stdout with the MCP host.
Connecting Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"gmail": {
"command": "/path/to/gmail_mcp_server/.venv/bin/python",
"args": ["/path/to/gmail_mcp_server/app.py"]
}
}
}Restart Claude Desktop after saving.
Connecting Cursor
Add to Cursor MCP settings (.cursor/mcp.json or Settings → MCP):
{
"mcpServers": {
"gmail": {
"command": "/path/to/gmail_mcp_server/.venv/bin/python",
"args": ["/path/to/gmail_mcp_server/app.py"]
}
}
}Connecting VS Code
Add to .vscode/mcp.json in your workspace:
{
"servers": {
"gmail": {
"type": "stdio",
"command": "/path/to/gmail_mcp_server/.venv/bin/python",
"args": ["/path/to/gmail_mcp_server/app.py"]
}
}
}Example MCP Tool Calls
Search unread emails from a sender:
{
"tool": "search_email",
"arguments": {
"sender": "billing@example.com",
"unread": true,
"max_results": 10
}
}Read a specific email:
{
"tool": "read_email",
"arguments": {
"message_id": "18abc123def456"
}
}Send an email:
{
"tool": "send_email",
"arguments": {
"to": "recipient@example.com",
"subject": "Hello from MCP",
"body": "This email was sent via the Gmail MCP Server."
}
}Troubleshooting
Issue | Solution |
| Download OAuth client JSON from Google Cloud Console |
Browser auth fails | Ensure redirect URI |
| Delete |
| Re-auth with updated scopes; delete old |
Server not appearing in host | Verify absolute paths in MCP config; check |
Empty search results | Confirm Gmail query syntax; try |
Enable debug logging:
LOG_LEVEL=DEBUG python app.pySecurity
OAuth tokens and email bodies are never logged
Attachment contents are never logged
Gmail queries are sanitized before API calls
Never commit
credentials.json,token.json, or.env
Project Structure
gmail_mcp_server/
├── app.py # FastMCP entry point
├── config.py # Configuration and constants
├── auth.py # OAuth2 authentication
├── gmail_client.py # Gmail API business layer
├── requirements.txt
├── .env.example
├── tools/ # MCP tool modules
├── resources/ # MCP read-only resources
├── prompts/ # MCP prompt templates
└── utils/ # Parser, formatter, logger, exceptionsFuture Roadmap
Google Drive MCP integration
Microsoft Outlook MCP integration
Slack MCP integration
Notion MCP integration
SharePoint MCP integration
Batch email operations
Pub/Sub push notification support
Multi-account support
HTTP transport for remote deployment
License
Apache 2.0
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
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/varun00391/mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server