This MCP server allows you to send emails through Gmail's SMTP server using AI agents. It provides multiple ways to handle email attachments and is designed with resilience features for reliable operation.
Install the required packages:
pip install mcp python-dotenv requests
git clone <remote-repository-URL>
cd gmail-mcp-server
Create a .env
file in the root directory with your Gmail SMTP credentials:
[email protected]
SMTP_PASSWORD=your_app_password
Note: If you use 2-Step Verification on your Gmail account, you must generate and use an App Password.
For pre-staged attachments, create a directory named available_attachments
in the root directory. The server will automatically create a temp_attachments
directory when downloading files from URLs.
Start the MCP server with:
python server.py
The server will run on 127.0.0.1:5000
.
You can also install the Gmail MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @MaitreyaM/gmail-mcp-server --client claude
To configure Claude Desktop to use this MCP server:
claude_desktop_config.json
{
"mcpServers": {
"gmail-mcp": {
"command": "python",
"args": ["PATH_TO_gmail_mcp.py"],
"host": "127.0.0.1",
"port": 5000,
"timeout": 30000
}
}
}
You can send emails using the send_email_tool
with the following parameters:
recipient
: Email address of the recipientsubject
: Email subjectbody
: Email body textattachment_path
(optional): Direct file path to the attachmentattachment_url
(optional): Public URL from which to download the attachmentattachment_name
(optional): Filename to use for the attachment (required when using URL-based or pre-staged attachments){
"recipient": "[email protected]",
"subject": "Hello with attachment",
"body": "Please see the attached document.",
"attachment_path": "C:\\path\\to\\document.pdf"
}
{
"recipient": "[email protected]",
"subject": "Hello with attachment",
"body": "Please see the attached image.",
"attachment_url": "https://example.com/image.png",
"attachment_name": "image.png"
}
Place your file in the available_attachments
directory and reference it by name:
{
"recipient": "[email protected]",
"subject": "Hello with attachment",
"body": "Please see the attached file.",
"attachment_name": "document.pdf"
}
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.