A Model Context Protocol (MCP) server that enables Claude and other AI assistants to send emails via Gmail API. This focused version only provides email sending capabilities.
This project creates an MCP server that allows AI assistants to:
- Send new emails
- Reply to existing emails
It's designed to be lightweight and easy to set up, using the Gmail API for email operations.
- Python 3.8 or higher
- A Google Cloud account with Gmail API enabled
- Docker (optional, for containerized deployment)
- Go to the Google Cloud Console
- Create a new project or select an existing one
- In the sidebar, navigate to "APIs & Services" > "Library"
- Search for "Gmail API" and enable it
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" and select "OAuth client ID"
- For application type, choose "Desktop app"
- Name your OAuth client
- Click "Create"
- Download the credentials JSON file
Clone this repository:
git clone https://github.com/abhishekloiwal/gmail-sender-mcp.git
cd gmail-sender-mcpInstall dependencies:
pip install -r requirements.txt- Rename the downloaded credentials file to
credentials.jsonand place it in the project root directory - Run the helper script to get a refresh token:
python get_refresh_token.py- Follow the authentication flow in your browser
- Copy the refresh token that appears in the terminal
- Create a
.envfile based on the example:
cp .env.example .env- Edit the
.envfile and fill in your credentials:
GMAIL_CLIENT_ID=your-client-id.apps.googleusercontent.com
GMAIL_CLIENT_SECRET=your-client-secret
GMAIL_REFRESH_TOKEN=your-refresh-token
[email protected]
python gmail_sender.pyThe server will start and listen for connections.
You can also run the server in a Docker container:
docker build -t gmail-sender-mcp .
docker run -d --name gmail-sender-mcp --env-file .env gmail-sender-mcpdocker-compose up -dTo use this MCP server with an AI assistant, you'll need to:
- Run the MCP server
- Connect your AI assistant to the MCP server (specific steps depend on your AI platform)
The MCP server provides the following tools:
Sends a new email.
Parameters:
to: Recipient email addresssubject: Email subject linebody: Email body content (HTML formatting supported)
Replies to an existing email.
Parameters:
email_id: ID of the email to reply tobody: Reply content (HTML formatting supported)
- Keep your
.envfile secure and never commit it to version control - The refresh token grants access to send emails from your account, so treat it like a password
- Consider using a dedicated Google account for this integration if you're concerned about security
Common issues:
- Authentication errors: Make sure your credentials in the
.envfile are correct - Permission errors: Verify that you've enabled the Gmail API in your Google Cloud project
- Token expired: If your refresh token stops working, generate a new one using the helper script
MIT
Contributions are welcome! Please feel free to submit a Pull Request.