Gmail MCP server

Enables sending emails through Gmail's SMTP service with support for attachments from local files, pre-staged files, or URLs downloaded during conversation.
Back to servers
Provider
Maitreya M
Release date
Mar 16, 2025
Language
Python
Stats
5 stars

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.

Installation

Prerequisites

  • Python 3.x
  • Required Python packages:
    • fastMCP
    • python-dotenv
    • requests

Install the required packages:

pip install mcp python-dotenv requests

Setup Steps

  1. Clone the repository:
git clone <remote-repository-URL>
cd gmail-mcp-server
  1. Configure Gmail credentials:

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.

  1. (Optional) Set up attachment directories:

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.

Running the Server

Start the MCP server with:

python server.py

The server will run on 127.0.0.1:5000.

Installing via Smithery

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

Configuring Claude Desktop

To configure Claude Desktop to use this MCP server:

  1. Open Claude > Settings > MCP > Configure
  2. Open claude_desktop_config.json
  3. Paste the following configuration (update the path to your script):
{
  "mcpServers": {
    "gmail-mcp": {
      "command": "python",
      "args": ["PATH_TO_gmail_mcp.py"],
      "host": "127.0.0.1",
      "port": 5000,
      "timeout": 30000
    }
  }
}

Usage Examples

Sending Emails

You can send emails using the send_email_tool with the following parameters:

  • recipient: Email address of the recipient
  • subject: Email subject
  • body: Email body text
  • attachment_path (optional): Direct file path to the attachment
  • attachment_url (optional): Public URL from which to download the attachment
  • attachment_name (optional): Filename to use for the attachment (required when using URL-based or pre-staged attachments)

Example 1: Direct File Attachment

{
  "recipient": "[email protected]",
  "subject": "Hello with attachment",
  "body": "Please see the attached document.",
  "attachment_path": "C:\\path\\to\\document.pdf"
}

Example 2: URL-Based Attachment

{
  "recipient": "[email protected]",
  "subject": "Hello with attachment",
  "body": "Please see the attached image.",
  "attachment_url": "https://example.com/image.png",
  "attachment_name": "image.png"
}

Example 3: Pre-Staged Attachment

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"
}

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later