A comprehensive Model Context Protocol (MCP) server for Gmail integration with SIYA/Claude Desktop and other MCP-compatible clients. Features on-demand authentication, multi-user support, and complete Gmail API access.
- ✨ Features
- 📦 Quick Start
- 🔧 Gmail API Setup
- 🎯 Authentication Methods
- 🚀 How It Works
- 📧 Available Tools
- 💡 Usage Examples
- 🎯 Common Use Cases
- 👥 Multi-User Mode
- 🛠️ NPX Troubleshooting
- 🔍 Debug & Troubleshooting
- 📋 Command Line Options
- 🔒 Security & Privacy
- 🏗️ Advanced Configuration
- 📚 API Reference
- 🔐 On-Demand Authentication - Only authenticates when you use Gmail tools
- 📧 Complete Gmail Operations - Send, read, search, organize emails
- 📝 Draft Management - Create, edit, and manage email drafts
- 👥 Multi-User Support - Handle multiple Gmail accounts simultaneously
- 🛡️ Secure OAuth2 - Industry-standard Google authentication
- 🔧 Flexible Configuration - Multiple credential methods
- 🚀 Zero-Config Startup - Server starts immediately, authenticates when needed
- 📎 Attachment Support - Handle email attachments with full MIME support
- 🌍 International Support - Full UTF-8 and international character support
Add to your siya_desktop_config.json
or claude_desktop_config.json
:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"gmail-mcp-server@latest",
"--client-id", "your-google-oauth2-client-id",
"--client-secret", "your-google-oauth2-client-secret"
]
}
}
}
Optional: Add custom redirect URI if needed:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"gmail-mcp-server@latest",
"--client-id", "your-google-oauth2-client-id",
"--client-secret", "your-google-oauth2-client-secret",
"--redirect-uri", "http://localhost:8080/oauth2callback"
]
}
}
}
npx gmail-mcp-server@latest --help
- Go to Google Cloud Console
- Create or select a project
- Enable the Gmail API
- Go to Credentials → Create Credentials → OAuth 2.0 Client ID
- Choose Desktop Application
- Note your Client ID and Client Secret
-
Default: Add
http://localhost:44000/oauth2callback
to authorized redirect URIs -
Custom: If using
--redirect-uri
orGMAIL_REDIRECT_URI
, add your custom URI -
Multi-user: Add
http://localhost:44000/oauth2callback
throughhttp://localhost:44010/oauth2callback
Examples of redirect URIs to add:
http://localhost:44000/oauth2callback (default)
http://localhost:8080/oauth2callback (custom port)
https://yourdomain.com/oauth2callback (production)
The server supports three ways to provide credentials:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"gmail-mcp-server@latest",
"--client-id", "676239218521-example.apps.googleusercontent.com",
"--client-secret", "GOCSPX-example-secret",
"--redirect-uri", "http://localhost:8080/oauth2callback"
]
}
}
}
Note: The --redirect-uri
is optional and defaults to http://localhost:44000/oauth2callback
.
export GMAIL_CLIENT_ID="your-client-id"
export GMAIL_CLIENT_SECRET="your-client-secret"
export GMAIL_REDIRECT_URI="http://localhost:8080/oauth2callback" # Optional, defaults to http://localhost:44000/oauth2callback
npx gmail-mcp-server@latest
# Download OAuth2 JSON from Google Cloud Console
mkdir -p ~/.gmail-mcp
cp /path/to/credentials.json ~/.gmail-mcp/credentials.json
npx gmail-mcp-server@latest
Once authenticated, you stay signed in for months! The server automatically:
- Refreshes expired access tokens using stored refresh tokens
- Maintains long-term authentication without requiring re-authentication
- Only prompts for new authentication if refresh tokens become invalid
This means you authenticate once and use Gmail tools seamlessly for months without interruption.
The server starts immediately without requiring authentication upfront:
📧 Gmail MCP Server starting...
🔐 Authentication will be handled when you use Gmail tools or call "quick_authenticate"
First time you try any Gmail operation, you'll see:
🔐 **Authentication Required**
To use Gmail tools, please authenticate first:
**Option 1:** Use the `gmail_authenticate` tool with mode='auto' for automatic authentication
**Option 2:** Use the `gmail_authenticate` tool with mode='manual' to get a clickable authentication link
After authentication, you can use all Gmail tools!
Once authenticated, you have access to:
- gmail_send_email - Send emails with attachments and HTML
- gmail_read_email - Read email content and metadata
- gmail_search_emails - Advanced Gmail search with filters
- gmail_mark_email - Mark as read/unread
- gmail_move_email - Move between folders/labels
- gmail_delete_email - Permanently delete emails
- gmail_get_attachment - Download email attachments
- gmail_draft - Comprehensive draft management with actions: create, list, get, update, delete, send
- gmail_authenticate - Authentication with auto/manual modes
- gmail_logout - Sign out and clear credentials
- gmail_authenticate_user - Add new user accounts
- gmail_manage_session - Manage user sessions (info/remove)
{
"tool": "gmail_send_email",
"arguments": {
"to": ["recipient@example.com"],
"subject": "Hello from SIYA!",
"text": "This is a plain text email.",
"html": "<h1>Hello!</h1><p>This is an <strong>HTML</strong> email.</p>"
}
}
{
"tool": "gmail_draft",
"arguments": {
"action": "create",
"to": ["recipient@example.com"],
"subject": "Draft Email",
"text": "This will be saved as a draft.",
"attachments": [
{
"filename": "document.pdf",
"content": "base64-encoded-content",
"contentType": "application/pdf"
}
]
}
}
{
"tool": "gmail_search_emails",
"arguments": {
"query": "is:unread has:attachment",
"maxResults": 10
}
}
{
"tool": "gmail_draft",
"arguments": {
"action": "list",
"maxResults": 20
}
}
{
"tool": "gmail_draft",
"arguments": {
"action": "update",
"draftId": "draft_id_here",
"to": ["updated@example.com"],
"subject": "Updated Draft Subject",
"text": "Updated draft content"
}
}
{
"tool": "gmail_draft",
"arguments": {
"action": "send",
"draftId": "draft_id_here"
}
}
- Newsletter Management - Send bulk emails with personalized content
- Notification Systems - Automated alerts and status updates
- Customer Communication - Automated responses and follow-ups
- Draft Workflows - Create, review, and collaborate on email content
- Template Management - Save and reuse email templates as drafts
- Content Scheduling - Prepare emails in advance for later sending
- Inbox Monitoring - Track unread emails and important messages
- Attachment Processing - Extract and process email attachments
- Search & Filter - Find specific emails based on complex criteria
- Team Collaboration - Manage multiple team member accounts
- Client Communication - Handle emails from different business accounts
- Personal/Business Separation - Organize multiple Gmail accounts
Enable multiple Gmail accounts with the --multi-user
flag:
npx gmail-mcp-server@latest --multi-user --client-id "your-id" --client-secret "your-secret"
-
Start server with
--multi-user
flag -
Add users with
gmail_authenticate_user
-
Use tools with
userId
parameter for each operation -
Manage sessions with
gmail_manage_session
{
"tool": "gmail_authenticate_user",
"arguments": {
"userEmail": "user1@gmail.com"
}
}
After authentication, use the returned userId
for operations:
{
"tool": "gmail_send_email",
"arguments": {
"userId": "user_12345",
"to": ["recipient@example.com"],
"subject": "Email from User 1",
"text": "This email is sent from user1@gmail.com account"
}
}
If you get "spawn npx ENOENT" error on macOS with NVM:
# Create wrapper directory
mkdir -p ~/bin
# Create NPX wrapper script
echo '#!/bin/bash' > ~/bin/npx
echo 'exec ~/.nvm/versions/node/v22.14.0/bin/npx "$@"' >> ~/bin/npx
chmod +x ~/bin/npx
# Update SIYA/Claude Desktop config
Updated SIYA/Claude Desktop Config:
{
"mcpServers": {
"gmail": {
"command": "/Users/yourusername/bin/npx",
"args": [
"gmail-mcp-server@latest",
"--client-id", "your-client-id",
"--client-secret", "your-client-secret"
]
}
}
}
Replace /Users/yourusername/
with your actual home directory path.
node --version # e.g., v22.14.0
ls ~/.nvm/versions/node/ # List available versions
npx gmail-mcp-server@latest --debug --client-id "your-id" --client-secret "your-secret"
"Gmail credentials not configured"
- Use
npm uninstall -g gmail-mcp-server
to clear cache - Use
npx gmail-mcp-server@latest
to force latest version
"spawn npx ENOENT"
- Follow NPX Troubleshooting above
- Ensure NPX wrapper has correct Node.js path
"Duplicate tools showing up"
- Update to version 1.0.17+ which fixes duplicate tool issues
- Use
npx gmail-mcp-server@latest
to get latest version
Authentication popup on startup
- Update to version 1.0.11+ for on-demand authentication
- Use
npx gmail-mcp-server@latest
to get latest version
npx gmail-mcp-server@latest --help # Shows current version info
npx gmail-mcp-server@latest [options]
Options:
--client-id <id> OAuth2 client ID
--client-secret <secret> OAuth2 client secret
--redirect-uri <uri> OAuth2 redirect URI (default: http://localhost:44000/oauth2callback)
--multi-user Enable multi-user mode
--setup-auth Interactive credential setup
--reset-auth Clear stored authentication
--debug Enable debug logging
--non-interactive Run without prompts
--help Show help information
# Custom port
npx gmail-mcp-server@latest --client-id "your-id" --client-secret "your-secret" --redirect-uri "http://localhost:8080/oauth2callback"
# Production domain
npx gmail-mcp-server@latest --client-id "your-id" --client-secret "your-secret" --redirect-uri "https://myapp.com/gmail/callback"
# Environment variable (alternative)
export GMAIL_REDIRECT_URI="http://localhost:3000/auth/callback"
npx gmail-mcp-server@latest --client-id "your-id" --client-secret "your-secret"
- OAuth2 Standard - Uses Google's official authentication
-
Local Storage - Tokens stored locally in
~/.gmail-mcp/
- No Data Collection - Your emails stay on Google's servers
- Secure Scopes - Only requests necessary Gmail permissions
The server supports flexible redirect URI configuration for different deployment scenarios:
Default Configuration:
- Uses
http://localhost:44000/oauth2callback
- Automatically starts callback server on port 44000
Custom Port Example:
# Command line
npx gmail-mcp-server@latest --redirect-uri "http://localhost:8080/oauth2callback"
# Environment variable
export GMAIL_REDIRECT_URI="http://localhost:8080/oauth2callback"
npx gmail-mcp-server@latest
Production Deployment:
# For production with custom domain
npx gmail-mcp-server@latest --redirect-uri "https://myapp.com/gmail/callback"
Key Features:
- Auto Port Detection: Server automatically uses the port from your redirect URI
-
Custom Paths: Use any callback path (not just
/oauth2callback
) - HTTPS Support: Works with production HTTPS domains
- Flexible Configuration: Command line args override environment variables
export GMAIL_TOKEN_DIR="/custom/path/to/tokens"
npx gmail-mcp-server@latest
npx gmail-mcp-server@latest --non-interactive --client-id "id" --client-secret "secret"
npx gmail-mcp-server@latest --reset-auth
- All operations support both single-user and multi-user modes
- Multi-user operations require
userId
parameter - Comprehensive error handling and validation
- Support for international characters and attachments
- Complete draft lifecycle management
- Create, read, update, delete, and send drafts
- Full content preservation including attachments
- Seamless integration with email workflow
-
Gmail search syntax support (
is:unread
,has:attachment
, etc.) -
Date range filtering (
after:2024/01/01
,before:2024/12/31
) - Advanced filters (sender, recipient, subject, labels)
- Pagination support for large result sets
- Label-based organization (INBOX, SENT, DRAFT, TRASH, SPAM)
- On-demand authentication - No upfront auth required
- Automatic token refresh - Seamless credential management
- Multi-account support - Handle multiple Gmail accounts
- Secure token storage - Local encrypted credential storage
- Manual/automatic modes - Flexible authentication options
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details.
- Issues: GitHub Issues
- Documentation: Check README.md and setup guides
-
Latest Version: Always use
@latest
tag for newest features
📧 Happy emailing with SIYA/Claude Desktop! 🚀