Gmail MCP Server
MCP server that lets AI assistants send, read, and manage Gmail through natural language, including email sending, inbox management, and template-based outreach.
README
Gmail MCP Server
<p align="center"> <img src="https://img.shields.io/badge/Node.js-18+-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="Node.js" /> <img src="https://img.shields.io/badge/MCP-Protocol-000000?style=for-the-badge&logo=anthropic&logoColor=white" alt="MCP" /> <img src="https://img.shields.io/badge/Gmail_API-EA4335?style=for-the-badge&logo=gmail&logoColor=white" alt="Gmail API" /> <img src="https://img.shields.io/badge/License-MIT-blue?style=for-the-badge" alt="License" /> </p>
<p align="center"> <strong>A Model Context Protocol (MCP) server that lets AI assistants send, read, and manage Gmail — through natural language.</strong> </p>
<p align="center"> Built with Node.js · Compatible with Claude Desktop & other MCP clients </p>
Overview
Gmail MCP Server bridges AI assistants and Gmail. Instead of switching tabs or writing scripts, you ask your AI client to send an email, list unread messages, archive inbox clutter, or fill a reusable template — and the server handles the rest over stdio.
| Capability | How it works |
|---|---|
| Send mail | Gmail SMTP via Nodemailer + App Password |
| Read & manage | Gmail API v1 via OAuth2 refresh token |
| Templates | Mustache variables in local .txt files |
| Transport | MCP over stdio (no HTTP server required) |
Features
- Send custom emails — plain text or HTML
- Introduction emails — one-shot professional outreach
- Template engine — Mustache-powered reusable email bodies
- Inbox tools — list labels, list unread (with Gmail search queries), fetch by ID
- Mailbox actions — archive (remove from Inbox) or move to trash
- Config check — verify SMTP credentials before sending
- Secure by design — secrets stay in
.env; never committed to git
Architecture
+------------------+ stdio / JSON-RPC +---------------------+
| MCP Client | <------------------------------> | Gmail MCP Server |
| Claude Desktop | | index.js |
| Cursor, etc. | +----------+----------+
+------------------+ |
+----------------------------+----------------------------+
| | |
v v v
+---------------+ +---------------+ +---------------+
| Nodemailer | | Gmail API | | Templates |
| SMTP send | | OAuth2 read | | Mustache |
+---------------+ +---------------+ +---------------+
Tech Stack
| Layer | Technology |
|---|---|
| Runtime | Node.js (ES Modules) |
| Protocol | Model Context Protocol over stdio |
| MCP SDK | @modelcontextprotocol/sdk |
| Sending | nodemailer → Gmail SMTP |
| Reading / managing | googleapis → Gmail API v1 |
| Auth | Gmail App Password (send) · OAuth2 refresh token (read/manage) |
| Config | dotenv |
| Templating | mustache |
Project Structure
gmail-mcp-server/
├── index.js # MCP server entry — tool registration & handlers
├── lib/
│ └── gmail.js # OAuth2 client + Gmail API helpers
├── templates/
│ ├── introduction.txt # Intro email template
│ └── follow_up.txt # Follow-up email template
├── .env.example # Environment variable template
├── package.json
└── README.md
Available Tools
| Tool | Description | Auth |
|---|---|---|
send_email |
Send a custom email (text or HTML) | App Password |
send_introduction_email |
Send a professional introduction | App Password |
send_template_email |
Send from a Mustache template | App Password |
check_gmail_config |
Validate SMTP credentials | App Password |
list_email_templates |
List templates in /templates |
None |
list_labels |
List Gmail labels | OAuth2 |
list_unread_emails |
List unread mail (optional query) | OAuth2 |
get_email |
Fetch a full message by ID | OAuth2 |
archive_email |
Remove a message from Inbox | OAuth2 |
delete_email |
Move a message to Trash | OAuth2 |
list_attachments |
List attachments on a message | OAuth2 |
download_attachment |
Download an attachment to disk | OAuth2 |
Getting Started
Prerequisites
- Node.js 18 or later
- A Gmail account
- An MCP client (e.g. Claude Desktop)
1. Clone & install
git clone https://github.com/Abhitkumar89/Gmail_MCP_Tool.git
cd Gmail_MCP_Tool
npm install
2. Configure environment
cp .env.example .env
Edit .env with your values:
# Required for sending
GMAIL_USER=your_email@gmail.com
GMAIL_APP_PASSWORD=your_16_char_app_password
# Required for reading / archiving / deleting
GMAIL_CLIENT_ID=your_client_id
GMAIL_CLIENT_SECRET=your_client_secret
GMAIL_REDIRECT_URI=https://developers.google.com/oauthplayground
GMAIL_REFRESH_TOKEN=your_refresh_token
<details> <summary><strong>How to get a Gmail App Password</strong></summary>
- Open Google Account → Security
- Enable 2-Step Verification
- Open App passwords → create one for Mail
- Paste the 16-character password into
GMAIL_APP_PASSWORD
</details>
<details> <summary><strong>How to get OAuth2 credentials</strong></summary>
- Create a project in Google Cloud Console
- Enable the Gmail API
- Create OAuth 2.0 Client credentials
- Use OAuth 2.0 Playground (or your own flow) to obtain a refresh token
- Recommended scope:
https://www.googleapis.com/auth/gmail.modify - Fill in
GMAIL_CLIENT_ID,GMAIL_CLIENT_SECRET,GMAIL_REDIRECT_URI, andGMAIL_REFRESH_TOKEN
Note: Sending uses App Password (SMTP). Inbox tools require OAuth2. For the full toolset, configure both.
</details>
3. Run the server
npm start
You should see:
Gmail MCP Server running on stdio
The process waits on stdin — that is expected for MCP servers.
MCP Client Configuration
Add the server to your Claude Desktop config (or any MCP-compatible client).
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"gmail": {
"command": "node",
"args": ["/absolute/path/to/gmail-mcp-server/index.js"],
"cwd": "/absolute/path/to/gmail-mcp-server"
}
}
}
Set
cwdto the project root so.envandtemplates/resolve correctly. Restart the client after saving.
Usage Examples
Once connected, try prompts like:
Send an introduction email to someone@example.com
Check if my Gmail configuration is working
Send an email to someone@example.com with subject "Hello" and body "Test message"
List unread emails
List unread emails with query "from:recruiter"
Get email with id 18c5b9b1a2e3a4b5
Archive email with id 18c5b9b1a2e3a4b5
Delete email with id 18c5b9b1a2e3a4b5
List email templates
Send a template email to user@example.com using template introduction
with variables {"name":"Alex","recipientName":"Jordan","customMessage":"Great meeting you."}
Email Templates
Templates live in templates/ as .txt files. An optional first line sets the subject:
Subject: Introduction - {{name}}
Dear {{recipientName}},
I hope this message finds you well. I'm {{name}}, reaching out to introduce myself...
{{customMessage}}
Best regards,
{{name}}
Pass variables through the send_template_email tool; Mustache replaces {{placeholders}}.
Security
- Never commit
.env— it is listed in.gitignore - Use App Passwords and OAuth refresh tokens only on trusted machines
- Prefer least-privilege Gmail scopes where possible
delete_emailmoves messages to Trash (recoverable), not permanent delete
Scripts
| Command | Description |
|---|---|
npm start |
Start the MCP server |
npm run dev |
Start with Node --watch for local development |
License
MIT — feel free to use and adapt for your own MCP projects.
<p align="center"> Built to explore the Model Context Protocol · Node.js · Gmail API </p>
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。