Gmail MCP server

Provides direct access to Gmail accounts for reading, sending, drafting, archiving, and organizing emails through the Google API with comprehensive search and filter management capabilities.
Back to servers
Provider
theposch
Release date
Mar 01, 2025
Language
Python
Stats
2 stars

The Enhanced Gmail MCP Server provides a comprehensive integration with Gmail, allowing AI assistants like Claude to manage emails through natural language. This implementation enables everything from sending and reading emails to managing labels, drafts, folders, and advanced search capabilities.

Prerequisites

Before you begin, ensure you have:

  • Python 3.8 or higher
  • A Google Cloud project with Gmail API enabled
  • OAuth 2.0 credentials

Installation

# Clone the repository
git clone https://github.com/theposch/gmail-mcp.git
cd gmail-mcp

# Set up a virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install the package
pip install -e .

Google Cloud Setup

1. Create a Google Cloud Project

Create a new project at the Google Cloud Console.

2. Enable the Gmail API

Navigate to the API Library and enable the Gmail API for your project.

3. Configure OAuth Consent

Set up the OAuth consent screen:

  • Select "External" user type
  • Add your email as a test user
  • Add the scope: https://www.googleapis.com/auth/gmail/modify

4. Create Credentials

Generate OAuth 2.0 credentials:

  • Choose "Desktop app" as the application type
  • Download the JSON credentials file

Configuration

Store your credentials in a secure location:

# Create a directory for credentials
mkdir -p ~/.gmail-mcp

# Move your downloaded credentials file
mv ~/Downloads/client_secret_*.json ~/.gmail-mcp/credentials.json

Running the Server

With Claude Desktop

Add the MCP server configuration to your Claude Desktop config file (typically at ~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "gmail": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/gmail-mcp",
        "run",
        "gmail",
        "--creds-file-path",
        "/absolute/path/to/credentials.json",
        "--token-path",
        "/absolute/path/to/tokens.json"
      ]
    }
  }
}

Testing with MCP Inspector

For testing and debugging purposes:

npx @modelcontextprotocol/inspector uv run /path/to/gmail-mcp/src/gmail/server.py --creds-file-path /path/to/credentials.json --token-path /path/to/tokens.json

Usage Examples

Once connected, you can use natural language to interact with Gmail. Try these example prompts with Claude:

  • "Show me my unread emails"
  • "Search for emails from [email protected] with attachments"
  • "Create a new label called 'Important Projects'"
  • "Draft an email to [email protected] about the upcoming meeting"
  • "Archive all emails from [email protected]"
  • "Create a filter to automatically label emails from my team"

Available Features

Email Management

  • Send emails with custom subject, content, and recipients
  • Read and retrieve email content with full metadata
  • Move emails to trash with confirmation
  • Mark emails as read/unread
  • Open emails directly in browser

Draft Management

  • Create draft emails for later review
  • List all draft emails
  • Edit existing drafts

Label Management

  • List all available labels
  • Create custom labels
  • Apply/remove labels from emails
  • Rename existing labels
  • Delete unused labels
  • Search emails by label

Folder Organization

  • Create new folders (implemented as Gmail labels)
  • Move emails between folders
  • List all available folders

Search & Filtering

  • Search emails using Gmail's advanced query syntax
  • Create, manage, and delete email filters
  • Filter by sender, recipient, subject, content, and more
  • Customize search results with flexible parameters

Archive Management

  • Archive emails (remove from inbox without deleting)
  • Batch archive multiple emails matching search criteria
  • List all archived emails
  • Restore archived emails to inbox

Security Considerations

  • Never commit credentials or token files to version control
  • Store credentials in a secure location with appropriate permissions
  • The server will request user confirmation before performing sensitive actions
  • Review Google Cloud Console regularly for unusual activity
  • Consider using environment variables for sensitive paths

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