Gmail MCP Server
A powerful and flexible Gmail integration server built using the MCP (Message Control Protocol) framework. This server provides a robust interface to interact with Gmail APIs, offering functionality for reading, sending, and managing emails programmatically.
Features
- Read emails from multiple Gmail accounts
- Send emails with attachments
- Search emails with advanced query options
- Download email attachments
- Handle email conversations and threads
- Real-time email monitoring
- Support for multiple Gmail accounts
Prerequisites
Before running the Gmail MCP server, ensure you have the following:
- Python 3.12 or higher
- Google Cloud Project with Gmail API enabled
- OAuth 2.0 Client ID credentials
- Required Python packages (specified in pyproject.toml)
Installation
Installing via Smithery
To install Gmail Integration Server for Claude Desktop automatically via Smithery:
- Clone the repository:
- Create and activate a virtual environment:
- Install dependencies:
Running on Ubuntu
- Install Python 3.12 and create a virtual environment if you haven't already:
- Place your downloaded
client_secret.json
in the project root. - Generate an OAuth token for the Gmail account you want to use. Copy the URL
printed by the script into a web browser and complete the sign-in process:
- Start the server:
Setup Google Cloud Project
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API for your project
- Create OAuth 2.0 credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Choose "Desktop app" as application type
- Download the client configuration file
- Rename the downloaded file to
client_secret.json
and place it in the project root directory
Configuration
- Set up email identifiers in
gmail_token_creator.py
:
- Run the token creator to authenticate your Gmail accounts:
The script prints an authorization URL. Copy this URL into your web browser,
complete the Google consent flow, and copy the verification code back into the
terminal if prompted. A token file will be created inside token_files/
for
future use.
- Repeat the process for each Gmail account you want to integrate
Server Structure
gmail_server.py
: Main MCP server implementationgmail_api.py
: Gmail API interaction functionsgoogle_apis.py
: Google API authentication utilities- Supporting files:
read_emails.py
: Email reading functionalitysearch_emails.py
: Email search functionalitysend_emails.py
: Email sending functionality
Usage
Starting the Server
Running with Docker
You can also build a container image using the provided Dockerfile
:
The container runs the same server and stores authentication tokens in the
token_files
directory on the host so they persist between runs.
Available Tools
- Send Email:
- Search Emails:
- Read Latest Emails:
- Download Attachments:
Security Considerations
- Store
client_secret.json
securely and never commit it to version control - Keep token files secure and add them to
.gitignore
- Use environment variables for sensitive information
- Regularly rotate OAuth credentials
- Monitor API usage and set appropriate quotas
Error Handling
The server includes comprehensive error handling and logging:
- Logs are written to
gmail_mcp.log
- Both file and console logging are enabled
- Detailed error messages for debugging
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
Apachelicense2.0
Support
For issues and feature requests, please use the GitHub issue tracker.
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
通过 Gmail API 与 Gmail 交互,阅读、发送和管理电子邮件。支持多个 Gmail 帐户,并提供实时监控以及电子邮件搜索和附件处理的高级功能。
Related Resources
Related MCP Servers
- -securityAlicense-qualityIntegrates with Gmail to enable sending, reading, drafting, and managing emails via the Model Context Protocol (MCP), allowing users to interact with email tasks through automated client prompts.Last updated -2GPL 3.0
- -securityFlicense-qualityEnables users to manage Gmail accounts using AI agent-assisted operations via an MCP protocol, supporting email search, reading, deletion, and sending with a voice-powered interface.Last updated -1410
- -securityAlicense-qualityProvides comprehensive Gmail integration with LLM processing capabilities, allowing users to read, search, filter emails and handle attachments through the Model Context Protocol.Last updated -31MIT License
- AsecurityAlicenseAqualityManage your emails effortlessly with a standardized interface for drafting, sending, retrieving, and organizing messages. Streamline your email workflow with complete Gmail API coverage, including label and thread management.Last updated -6413429MIT License