Provides comprehensive Gmail functionality, allowing users to list, search, read, and delete emails, send messages with or without attachments, manage labels, handle conversation threads, and access account statistics.
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 Serversearch for emails from john@example.com about the project"
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
A Model Context Protocol (MCP) server that provides comprehensive Gmail functionality through FastMCP. This server enables AI assistants like Claude to interact with Gmail accounts, manage emails, send messages, and perform various Gmail operations using OAuth2 authentication via Nango.
Features
Core Gmail Operations
Message Management: List, search, read, and delete emails
Send Emails: Send messages with or without attachments
Message Actions: Mark messages as read, manage labels
Advanced Search: Filter by sender, subject, date, attachments, read status
Account Statistics: Get Gmail account overview and metrics
Thread Support: Handle Gmail conversation threads
Attachment Support: Send emails with file attachments
Authentication & Security
OAuth2 Integration: Secure authentication via Nango
Token Management: Automatic token refresh and validation
Multi-account Support: Handle multiple Gmail accounts
Secure Credential Storage: Environment-based configuration
Prerequisites
Python 3.13+
Gmail account with API access enabled
Google Cloud Project with Gmail API enabled
Nango account for OAuth2 management (optional but recommended)
Installation
Clone or create the project structure:
Create a virtual environment:
Install dependencies:
Configuration
Environment Variables
Create a .env file in the project root:
Google Cloud Setup
Create a Google Cloud Project:
Go to Google Cloud Console
Create a new project or select existing one
Enable Gmail API:
Navigate to "APIs & Services" > "Library"
Search for "Gmail API" and enable it
Create OAuth2 Credentials:
Go to "APIs & Services" > "Credentials"
Click "Create Credentials" > "OAuth 2.0 Client IDs"
Choose "Desktop application" or "Web application"
Note the Client ID and Client Secret
Configure OAuth Scopes:
Add the following scopes:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.sendhttps://www.googleapis.com/auth/gmail.modify
Nango Setup (Recommended)
Create Nango Account: Sign up at nango.dev
Create Google Integration: Set up Google OAuth2 integration
Configure Connection: Create a connection for your Gmail account
Get Credentials: Note your connection ID and provider config key
Claude Desktop Configuration
Add this configuration to your Claude Desktop config file:
Location:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
With Nango
Notes:
On Windows, use backslashes in paths:
C:\\path\\to\\your\\gmail-mcp-server\\main.pyFor virtual environment on Windows:
.venv\\Scripts\\python.exeReplace placeholder values with your actual credentials
Available Tools
The MCP server provides the following tools for Claude:
Message Operations
gmail_list_messages- List Gmail messages with optional search querygmail_get_message- Get details of a specific messagegmail_search_messages- Advanced search with multiple criteriagmail_send_message- Send a new email messagegmail_send_message_with_attachment- Send email with file attachment
Message Management
gmail_mark_as_read- Mark messages as readgmail_delete_messages- Delete messages permanently
Account Information
gmail_get_stats- Get Gmail account statistics and overview
Usage Examples
Once configured with Claude, you can use natural language commands like:
Basic Operations
"Show me my latest 10 emails"
"Search for emails from john@example.com sent this week"
"Get the full content of message ID xyz123"
"Send an email to sarah@example.com with subject 'Meeting Tomorrow'"
Advanced Operations
"Find all unread emails with attachments from the last 7 days"
"Mark all emails from newsletter@company.com as read"
"Delete the email with ID abc456"
"Send a report to my manager with the quarterly-report.pdf attachment"
"Show me my Gmail account statistics"
Search Capabilities
"Find emails about 'project alpha' from last month"
"Show unread emails from important@client.com"
"List emails with attachments sent after 2024/01/01"
Project Structure
Running the Server
With Claude Desktop
The server automatically starts when Claude Desktop loads the configuration.
Standalone Testing
For development and testing:
Tool Specifications
gmail_list_messages
gmail_search_messages
gmail_send_message
Development
Key Components
main.py: FastMCP server with tool definitions
gmail_auth.py: OAuth2 authentication handling
gmail_operations.py: Gmail API client wrapper
Nango Integration: Secure credential management
Adding New Features
Add Gmail Operation: Extend
GmailClientclass ingmail_operations.pyDefine MCP Tool: Add
@mcp.tool()decorator inmain.pyAdd Validation: Include parameter validation and error handling
Update Documentation: Add usage examples and tool specifications
Dependencies
google-api-python-client- Official Google API clientgoogle-auth- Google authentication librarymcp[cli]- Model Context Protocol frameworkpython-dotenv- Environment variable managementpydantic- Data validationrequests- HTTP client for Nango integration
Troubleshooting
Common Issues
Authentication Errors:
Verify Nango credentials are correct
Check Gmail API is enabled in Google Cloud
Ensure OAuth scopes are properly configured
Permission Errors:
Verify OAuth2 scopes include required permissions
Check if Gmail account has necessary access
Message Not Found:
Ensure message IDs are valid Gmail message IDs
Check if messages haven't been deleted
Rate Limiting:
Gmail API has quotas and rate limits
Implement retry logic for production use
Debug Mode
Enable debug logging by setting environment variable:
Testing Nango Connection
Security Considerations
Environment Variables: Never commit
.envfiles with credentialsToken Storage: Tokens are handled securely by Nango
API Quotas: Monitor Gmail API usage to avoid quota exhaustion
Scope Limitations: Use minimal required OAuth scopes
Access Control: Limit MCP server access to authorized clients
Performance Optimization
Batch Operations: Use batch requests when possible
Caching: Implement message caching for frequently accessed data
Pagination: Handle large result sets with proper pagination
Connection Pooling: Reuse HTTP connections for API calls
Error Handling
The server implements comprehensive error handling:
Validation Errors: Parameter validation with descriptive messages
API Errors: Gmail API error handling and retry logic
Authentication Errors: Token refresh and re-authentication
Network Errors: Connection timeout and retry mechanisms
Contributing
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Make your changes and add tests
Commit your changes (
git commit -m 'Add amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support and questions:
Check the troubleshooting section
Review Gmail API documentation: Gmail API Guide
Open an issue in the project repository
Check Nango documentation: Nango Docs
Acknowledgments
FastMCP: Simplified MCP server implementation
Google API Python Client: Official Gmail API integration
Nango: OAuth2 authentication management
Model Context Protocol: Standard for AI tool integration