gmail-mcp
Enables AI assistants to manage Gmail accounts programmatically, including sending emails, managing labels, creating filters, and handling attachments via OAuth2 authentication.
README
<div align="center"> <img src="images/banner.png" alt="Gmail MCP Server Banner" /> </div>
Gmail MCP Server
MCP server for Gmail API with OAuth2 authentication. Provides programmatic access to Gmail for sending emails, managing labels, creating filters, and handling attachments through AI assistants.
💡 Built for Your IDE: This MCP server is designed to work seamlessly with Cursor Cloud Geminis and other IDE-integrated AI assistants. Experience native email management directly within your development environment—no need to switch between applications. You can also use it with desktop tools like Claude Desktop, but the native IDE integration provides the smoothest experience.
Requirements
- Node.js 18.0.0+
- Google Cloud Project with Gmail API enabled
- OAuth 2.0 credentials (Desktop application or Web application type)
Quick Start
The easiest way to get started is using the setup command:
git clone https://github.com/pouyanafisi/gmail-mcp.git
cd gmail-mcp
npm install
npm run build
npm run setup # Automatically configures MCP for Cursor IDE
npm run auth # Authenticate with Gmail
The npm run setup command automatically:
- ✅ Creates the MCP configuration file for Cursor IDE
- ✅ Provides instructions for Claude Desktop setup
- ✅ Verifies your build and credentials
After setup, restart your IDE and start managing Gmail directly from your AI assistant!
Installation
Install from npm (Recommended)
npm install -g @pouyanafisi/gmail-mcp
Or install locally:
npm install @pouyanafisi/gmail-mcp
Install from source
git clone https://github.com/pouyanafisi/gmail-mcp.git
cd gmail-mcp
npm install
npm run build
npm run setup # Automatically configures MCP for your IDE
Google Cloud Setup
- Enable Gmail API in Google Cloud Console
- Create OAuth 2.0 credentials (Desktop application or Web application)
- Download credentials JSON
- Save as
gcp-oauth.keys.jsonin project root or~/.gmail-mcp/
Configuration
Using npm package
If installed globally:
{
"mcpServers": {
"gmail": {
"command": "gmail-mcp"
}
}
}
If installed locally, use npx:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": ["-y", "gmail-mcp"]
}
}
}
Using source installation
{
"mcpServers": {
"gmail": {
"command": "node",
"args": ["/absolute/path/to/gmail-mcp/dist/index.js"]
}
}
}
See MCP_SETUP.md for platform-specific instructions.
Authentication
Using npm package
If installed globally:
gmail-mcp auth
Or with npx:
npx gmail-mcp auth
Using source installation
npm run auth
For cloud environments with custom callback URL:
npm run auth https://your-domain.com/oauth2callback
Credentials are saved to ~/.gmail-mcp/credentials.json and auto-refreshed.
Operations
19 operations available for comprehensive Gmail management.
Email Operations (10)
- send_email: Send emails with optional attachments (plain text, HTML, or multipart)
- draft_email: Create email drafts with attachments support
- read_email: Read email content with full MIME parsing and attachment information
- search_emails: Search emails using Gmail query syntax
- count_emails: Get exact email count for a label using Gmail API label metadata (provides total and unread counts)
- modify_email: Modify email labels (add/remove labels)
- delete_email: Permanently delete emails
- download_attachment: Download email attachments to local filesystem
- batch_modify_emails: Modify labels for multiple emails in batches
- batch_delete_emails: Delete multiple emails in batches
Label Management (5)
- list_email_labels: List all Gmail labels (system and user)
- create_label: Create a new Gmail label with visibility settings
- update_label: Update label properties (name, visibility)
- delete_label: Delete a user-created label
- get_or_create_label: Get existing label by name or create if it doesn't exist
Filter Management (5)
- create_filter: Create a custom Gmail filter with criteria and actions
- list_filters: List all Gmail filters
- get_filter: Get details of a specific filter
- delete_filter: Delete a Gmail filter
- create_filter_from_template: Create a filter using pre-built templates
Native IDE Integration
The Gmail MCP server integrates seamlessly with your IDE's AI assistant, allowing you to manage Gmail through natural language conversations. Here are examples of how it works:
Example 1: Conversational Email Management
Ask your AI assistant questions and give commands in plain English:
<div align="center"> <img src="images/screenshot_example_2.png" alt="Conversational email management in IDE" /> </div>
The assistant can:
- Check your inbox status ("How many unread emails do I have?")
- Send emails with natural language ("Send a birthday email to...")
- Provide proactive suggestions for organizing your inbox
- Execute operations transparently with clear feedback
Example 2: Automated Email Organization
The MCP server can handle complex workflows automatically:
<div align="center"> <img src="images/screenshot_example_1.png" alt="Automated email organization workflow" /> </div>
This example shows:
- Batch Processing: Automatically processing 164+ emails in rate-limit-compliant batches
- Smart Labeling: Creating labels and applying them to existing emails
- Filter Creation: Setting up automatic filters for future emails
- Transparent Feedback: Clear visibility into what operations were performed
- Error Handling: Graceful handling of API rate limits with automatic compensation
All operations happen natively within your IDE—no external tools or context switching required.
Usage
Send an email
Send an email to user@example.com with subject "Meeting" and body "Let's meet tomorrow"
Search emails
Search for emails from boss@company.com with attachments from the last month
Organize with labels
Create a label "Work - Urgent" and apply it to all emails from manager@company.com
Create filters
Create a filter to archive all emails from newsletter@company.com
Features
- ✅ Full Email Support: Send, draft, read, search, modify, and delete emails
- ✅ Attachment Handling: Send and download email attachments
- ✅ Label Management: Complete label CRUD operations
- ✅ Filter Management: Create and manage Gmail filters with templates
- ✅ Batch Operations: Efficiently process multiple emails
- ✅ OAuth2 Authentication: Secure authentication with auto-browser launch
- ✅ Modern Architecture: Object-oriented design with clear separation of concerns
- ✅ Type Safety: Full TypeScript strict mode compliance
Project Structure
gmail-mcp/
├── src/
│ ├── index.ts # Entry point
│ ├── server/ # MCP server setup
│ ├── services/ # Business logic services
│ ├── builders/ # Message builders
│ ├── tools/ # MCP tool handlers
│ ├── types/ # TypeScript types
│ ├── schemas/ # Zod validation schemas
│ └── utils/ # Utility functions
├── tests/ # Test files
├── dist/ # Compiled output
└── package.json
Development
npm run build # Build
npm run setup # Setup MCP configuration
npm run start # Run server
npm run auth # Authenticate
npm run type-check # Type checking
npm test # Run tests
npm run test:run # Run tests once
npm run test:ui # Test UI
npm run test:coverage # Coverage report
Documentation
- CLAUDE.md - Guidelines for using with Claude
- GEMINI.md - Guidelines for using with Gemini
- MCP_SETUP.md - Setup instructions for different platforms
- CONTRIBUTING.md - Contribution guidelines
- PROJECT_DEFINITION.md - Project architecture
- TASK_DOCUMENT.md - Implementation tasks
Troubleshooting
Authentication fails: Run npm run auth separately. Verify gcp-oauth.keys.json exists and is valid.
Permission errors: Verify OAuth scopes include gmail.modify and gmail.settings.basic. Check account has access to Gmail.
API errors: Check Gmail API quotas and rate limits. Verify message IDs are correct.
Build errors: Node.js 18+, run npm install, verify TypeScript config.
Attachment issues: Verify file paths are correct and accessible. Check Gmail's 25MB attachment limit.
Gmail IDs
- Message ID: Long alphanumeric string (e.g.,
182ab45cd67ef) - Label ID: System labels use uppercase (e.g.,
INBOX,UNREAD), user labels useLabel_prefix - Thread ID: Used to maintain conversation context
Find message IDs using search_emails or from email URLs.
Architecture
The project follows object-oriented principles:
- Services: Business logic separated by domain (Email, Label, Filter)
- Builders: Message construction (EmailBuilder)
- Utilities: Validation and error handling
- Type Safety: Full TypeScript strict mode, no
anytypes - Error Handling: Custom error classes with proper error codes
License
MIT
Acknowledgments
This project is a rebuild and improvement of the original Gmail MCP server, modernized with:
- MCP SDK v2
- Object-oriented architecture
- Comprehensive type safety
- Improved error handling
- Better separation of concerns
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。