gmail-mcp-server
Enables AI-powered inbox management with natural language commands through Claude Desktop. Supports sending, reading, searching, organizing emails, and managing labels using Gmail API with automatic authentication.
README
Gmail MCP Server
The Gmail MCP server that actually works - No OpenAI API required, rock-solid authentication, zero configuration hassles
Transform your Gmail into an AI-powered inbox with natural language commands through Claude Desktop. Send emails, manage labels, automate organization, download attachments - all without leaving your conversation.
✨ Key Highlights:
- 🔐 Bulletproof Authentication - Intelligent token management with auto-refresh
- 🚀 Production Ready - TypeScript, comprehensive error handling, battle-tested
- 💰 100% Free - No OpenAI API costs, no hidden fees
- 🔒 Privacy First - Direct Gmail API, no third-party AI dependencies
- 📦 Feature Complete - Attachments, labels, filters, batch operations, and more
Why choose this over alternatives? | See it in action | Start in 5 minutes
📚 Documentation
- Complete API Reference - Detailed documentation for all tools
- Troubleshooting Guide - Solutions for common issues
- Example Use Cases - Practical examples and workflows
- Comparison with Alternatives - Why choose this server
- Showcase - See what you can build
- Contributing Guide - How to contribute
- Code of Conduct - Community guidelines
- Security Policy - Security best practices
- Changelog - Version history and updates
Why This Project?
Traditional Gmail integrations struggle with authentication complexity and token management. This server solves those problems with:
- Intelligent Token Management: Automatic validation and refresh - no more expired credential errors
- User-Friendly Error Handling: Clear, actionable error messages with step-by-step solutions
- Comprehensive Email Operations: Send, read, search, organize, and automate your inbox
- Production-Ready: Built with TypeScript, proper error handling, and extensive testing
Quick Start
Prerequisites
- Node.js 16 or higher
- A Google Cloud Platform account
- Claude Desktop application
Installation
Option 1: Run Directly (Recommended for Testing)
git clone https://github.com/devdattatalele/gmail-mcp-server.git
cd gmail-mcp-server
npm install
npm run build
Option 2: Install as Package
npm install -g @devdattatalele/gmail-mcp-server
Google Cloud Setup
Before using this server, you need to set up OAuth credentials:
1. Create a Google Cloud Project
Navigate to Google Cloud Console and:
- Create a new project (or select existing)
- Enable the Gmail API for your project
- Note your project ID for later
2. Configure OAuth Consent Screen
This is the most critical step - skip it and you'll get authentication errors:
- Go to APIs & Services → OAuth consent screen
- Select External user type
- Fill in required fields:
- App name: Gmail MCP Server
- User support email: Your email
- Developer contact email: Your email
- Add these authorized scopes:
https://www.googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/gmail.settings.basic
- Add yourself as a test user:
- Scroll to "Test users" section
- Click "ADD USERS"
- Enter your Gmail address
- Click "Save"
Critical: Without adding yourself as a test user, you'll encounter "Error 403: Access blocked" during authentication.
3. Create OAuth Credentials
- Go to APIs & Services → Credentials
- Click Create Credentials → OAuth client ID
- Choose application type:
- Web application (recommended)
- Configure authorized redirect URIs:
- Add:
http://localhost:3000/oauth2callback
- Add:
- Download the JSON credentials file
- Rename it to
gcp-oauth.keys.json - Place it in your project directory or
~/.gmail-mcp/
Authentication
First-Time Setup
# Navigate to project directory
cd gmail-mcp-server
# Run authentication
node dist/index.js auth
The server will:
- Display a helpful pre-flight checklist
- Open your browser for Google authentication
- Save credentials to
~/.gmail-mcp/credentials.json - Automatically validate and refresh tokens as needed
Re-authentication
If you need to switch accounts or fix authentication issues:
node dist/index.js auth --force
The --force flag removes existing credentials and starts fresh.
Configure Claude Desktop
Add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"gmail": {
"command": "node",
"args": ["/absolute/path/to/gmail-mcp-server/dist/index.js"]
}
}
}
Replace /absolute/path/to/gmail-mcp-server with your actual project path.
Features
Email Operations
Sending & Drafting
- Send emails with attachments, CC, BCC
- Draft emails for later editing
- HTML and plain text support
- Reply to threads with threading support
- Attachment handling up to 25MB per email
Reading & Searching
- Read emails with full MIME structure parsing
- Search using Gmail's powerful query syntax
- Download attachments to local filesystem
- View attachment metadata (filename, size, type, ID)
Organization
- Label management: Create, update, delete, list
- Batch operations: Process multiple emails efficiently
- Email filters: Automate inbox organization
- Archive, delete, mark as read/unread
Advanced Features
Smart Authentication
// Automatic token validation on server start
// Auto-refresh expired tokens
// Clear error messages for common issues
// Force re-authentication option
Batch Processing
// Process up to 50 emails at once
// Automatic retry on individual failures
// Detailed success/failure reporting
Filter Templates
Pre-built templates for common scenarios:
- Auto-organize by sender
- Filter by subject keywords
- Handle large attachments
- Manage mailing lists
- Content-based filtering
API Reference
Available Tools
send_email
Send an email immediately.
Parameters:
to(string[]): Recipient email addressessubject(string): Email subjectbody(string): Email body (plain text)htmlBody(string, optional): HTML version of bodycc(string[], optional): CC recipientsbcc(string[], optional): BCC recipientsattachments(string[], optional): File paths to attachthreadId(string, optional): Reply to thread
Example:
{
"to": ["colleague@example.com"],
"subject": "Project Update",
"body": "Here's the latest on the project...",
"attachments": ["/path/to/report.pdf"]
}
draft_email
Create a draft email without sending.
Same parameters as send_email.
read_email
Retrieve email content by ID.
Parameters:
messageId(string): Gmail message ID
Returns: Full email content with headers, body, and attachment info.
search_emails
Search for emails using Gmail query syntax.
Parameters:
query(string): Gmail search querymaxResults(number, optional): Maximum results (default: 10)
Example Queries:
from:boss@company.com after:2024/01/01
has:attachment subject:invoice
is:unread label:important
modify_email
Change email labels (move, archive, etc.).
Parameters:
messageId(string): Gmail message IDaddLabelIds(string[], optional): Labels to addremoveLabelIds(string[], optional): Labels to remove
delete_email
Permanently delete an email.
Parameters:
messageId(string): Gmail message ID
list_email_labels
Get all available Gmail labels (system and user-created).
No parameters required.
create_label
Create a new Gmail label.
Parameters:
name(string): Label namemessageListVisibility('show' | 'hide', optional)labelListVisibility('labelShow' | 'labelShowIfUnread' | 'labelHide', optional)
batch_modify_emails
Modify labels for multiple emails at once.
Parameters:
messageIds(string[]): Array of message IDsaddLabelIds(string[], optional)removeLabelIds(string[], optional)batchSize(number, optional): Batch size (default: 50)
batch_delete_emails
Delete multiple emails at once.
Parameters:
messageIds(string[]): Array of message IDsbatchSize(number, optional): Batch size (default: 50)
create_filter
Create a Gmail filter with custom criteria.
Parameters:
criteria: Match conditions (from, to, subject, query, hasAttachment, size, etc.)action: Actions to perform (addLabelIds, removeLabelIds, forward)
download_attachment
Download an email attachment to local filesystem.
Parameters:
messageId(string): Gmail message IDattachmentId(string): Attachment ID (from read_email)savePath(string, optional): Download directoryfilename(string, optional): Custom filename
Troubleshooting
Authentication Issues
Error: "403: Access blocked"
Cause: Your app is in "Testing" mode and you're not added as a test user.
Solution:
- Visit OAuth Consent Screen
- Scroll to "Test users"
- Click "ADD USERS"
- Enter your Gmail address
- Save and retry authentication
Error: "400: invalid_request" or "doesn't comply with OAuth 2.0 policy"
Cause: OAuth consent screen is missing required fields (usually privacy policy).
Solution:
- Go to OAuth consent screen configuration
- Add Privacy Policy URL (can use
https://policies.google.com/privacyas placeholder) - Ensure Developer contact email is filled
- Save and retry
Error: "Credentials are invalid or expired"
Solution:
node dist/index.js auth --force
This removes old credentials and starts fresh authentication.
Error: "Port 3000 already in use"
Solution:
# macOS/Linux
lsof -ti:3000 | xargs kill
# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F
Operation Issues
Attachment Won't Send
Possible causes:
- File path is incorrect or inaccessible
- File exceeds 25MB Gmail limit
- Permission issues reading the file
Solution:
- Verify file path is absolute
- Check file permissions
- Ensure file size is under 25MB
Token Refresh Failed
The server automatically refreshes expired tokens. If this fails:
- Check your internet connection
- Verify OAuth credentials are still valid in Google Cloud Console
- Run
node dist/index.js auth --forceto re-authenticate
Development
Project Structure
gmail-mcp-server/
├── src/
│ ├── index.ts # Main server implementation
│ ├── utl.ts # Email utilities
│ ├── label-manager.ts # Label operations
│ ├── filter-manager.ts # Filter operations
│ └── evals/ # Evaluation tests
├── dist/ # Compiled JavaScript
├── gcp-oauth.keys.json # Your OAuth credentials (gitignored)
├── package.json
├── tsconfig.json
└── README.md
Building from Source
git clone https://github.com/devdattatalele/gmail-mcp-server.git
cd gmail-mcp-server
npm install
npm run build
Running in Development
npm run dev # Watch mode - rebuilds on changes
Testing Authentication
npm run auth # Equivalent to: node dist/index.js auth
Security Considerations
- OAuth credentials are stored in
~/.gmail-mcp/with user-only permissions - Never commit
gcp-oauth.keys.jsonorcredentials.jsonto version control - Tokens are auto-refreshed - no need to manually handle expiration
- Attachments are processed locally and never stored by the server
- Review access regularly in Google Account Settings
Contributing
Contributions are welcome! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Build and test:
npm run build - Commit:
git commit -m 'Add amazing feature' - Push:
git push origin feature/amazing-feature - Open a Pull Request
Reporting Issues
Found a bug or have a suggestion? Open an issue with:
- Clear description of the problem
- Steps to reproduce
- Expected vs actual behavior
- Your environment (OS, Node version, etc.)
License
MIT License - see LICENSE file for details.
Acknowledgments
Built using:
Support
- Documentation: Full API Reference
- Troubleshooting: Common Issues & Solutions
- Examples: Practical Use Cases
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: Report Vulnerabilities
- Email: taleledevdatta@gmail.com
Star History
If this project helped you, please consider giving it a ⭐!
Made with ❤️ by Devdatta Talele
Special thanks to all contributors who make this project better!
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。