Gmail MCP Server

$pip install -e .
README.md

Enables AI assistants to interact with Gmail accounts for managing emails.

Gmail MCP Server

A Model Context Protocol (MCP) server that provides comprehensive Gmail functionality through FastMCP. This server enables AI assistants like Claude to interact with Gmail accounts, manage emails, send messages, and perform various Gmail operations using OAuth2 authentication via Nango.

Features

Core Gmail Operations

  • Message Management: List, search, read, and delete emails
  • Send Emails: Send messages with or without attachments
  • Message Actions: Mark messages as read, manage labels
  • Advanced Search: Filter by sender, subject, date, attachments, read status
  • Account Statistics: Get Gmail account overview and metrics
  • Thread Support: Handle Gmail conversation threads
  • Attachment Support: Send emails with file attachments

Authentication & Security

  • OAuth2 Integration: Secure authentication via Nango
  • Token Management: Automatic token refresh and validation
  • Multi-account Support: Handle multiple Gmail accounts
  • Secure Credential Storage: Environment-based configuration

Prerequisites

  • Python 3.13+
  • Gmail account with API access enabled
  • Google Cloud Project with Gmail API enabled
  • Nango account for OAuth2 management (optional but recommended)

Installation

  1. Clone or create the project structure:
mkdir gmail-mcp-server
cd gmail-mcp-server
  1. Create a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -e .

Configuration

Environment Variables

Create a .env file in the project root:

# Nango Configuration (Recommended)
NANGO_BASE_URL=https://api.nango.dev
NANGO_SECRET_KEY=your_nango_secret_key
NANGO_CONNECTION_ID=your_NANGO_CONNECTION_ID
NANGO_INTEGRATION_ID=google

# Alternative: Direct Google OAuth (if not using Nango)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REFRESH_TOKEN=your_refresh_token

Google Cloud Setup

  1. Create a Google Cloud Project:

  2. Enable Gmail API:

    • Navigate to "APIs & Services" > "Library"
    • Search for "Gmail API" and enable it
  3. Create OAuth2 Credentials:

    • Go to "APIs & Services" > "Credentials"
    • Click "Create Credentials" > "OAuth 2.0 Client IDs"
    • Choose "Desktop application" or "Web application"
    • Note the Client ID and Client Secret
  4. Configure OAuth Scopes:

    • Add the following scopes:
      • https://www.googleapis.com/auth/gmail.readonly
      • https://www.googleapis.com/auth/gmail.send
      • https://www.googleapis.com/auth/gmail.modify

Nango Setup (Recommended)

  1. Create Nango Account: Sign up at nango.dev
  2. Create Google Integration: Set up Google OAuth2 integration
  3. Configure Connection: Create a connection for your Gmail account
  4. Get Credentials: Note your connection ID and provider config key

Claude Desktop Configuration

Add this configuration to your Claude Desktop config file:

Location:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
With Nango
{
  "mcpServers": {
    "gmail": {
      "command": "uvx",
      "args": ["git+https://github.com/ampcome-mcps/gmail-mcp.git"],
      "env": {
        "NANGO_BASE_URL": "https://api.nango.dev",
        "NANGO_SECRET_KEY": "your_nango_secret_key",
        "NANGO_CONNECTION_ID": "your_nango_connection_id",
        "NANGO_INTEGRATION_ID": "google-mail"
      }
    }
  }
}

Notes:

  • On Windows, use backslashes in paths: C:\\path\\to\\your\\gmail-mcp-server\\main.py
  • For virtual environment on Windows: .venv\\Scripts\\python.exe
  • Replace placeholder values with your actual credentials

Available Tools

The MCP server provides the following tools for Claude:

Message Operations

  • gmail_list_messages - List Gmail messages with optional search query
  • gmail_get_message - Get details of a specific message
  • gmail_search_messages - Advanced search with multiple criteria
  • gmail_send_message - Send a new email message
  • gmail_send_message_with_attachment - Send email with file attachment

Message Management

  • gmail_mark_as_read - Mark messages as read
  • gmail_delete_messages - Delete messages permanently

Account Information

  • gmail_get_stats - Get Gmail account statistics and overview

Usage Examples

Once configured with Claude, you can use natural language commands like:

Basic Operations

  • "Show me my latest 10 emails"
  • "Search for emails from john@example.com sent this week"
  • "Get the full content of message ID xyz123"
  • "Send an email to sarah@example.com with subject 'Meeting Tomorrow'"

Advanced Operations

  • "Find all unread email

Tools (8)

gmail_list_messagesList Gmail messages with optional search query
gmail_get_messageGet details of a specific message
gmail_search_messagesAdvanced search with multiple criteria
gmail_send_messageSend a new email message
gmail_send_message_with_attachmentSend email with file attachment
gmail_mark_as_readMark messages as read
gmail_delete_messagesDelete messages permanently
gmail_get_statsGet Gmail account statistics and overview

Environment Variables

NANGO_BASE_URLBase URL for Nango API
NANGO_SECRET_KEYSecret key for Nango authentication
NANGO_CONNECTION_IDSpecific connection ID for the Gmail account
GOOGLE_CLIENT_IDDirect Google OAuth client ID
GOOGLE_CLIENT_SECRETDirect Google OAuth client secret

Configuration

claude_desktop_config.json
{"mcpServers": {"gmail": {"command": "uvx", "args": ["git+https://github.com/ampcome-mcps/gmail-mcp.git"], "env": {"NANGO_BASE_URL": "https://api.nango.dev", "NANGO_SECRET_KEY": "your_nango_secret_key", "NANGO_CONNECTION_ID": "your_nango_connection_id", "NANGO_INTEGRATION_ID": "google-mail"}}}}

Try it

Show me my latest 10 emails
Search for emails from john@example.com sent this week
Send an email to sarah@example.com with subject 'Meeting Tomorrow'
Get the full content of message ID xyz123
Find all unread emails with attachments

Frequently Asked Questions

What are the key features of Gmail MCP Server?

Comprehensive message management including list, search, read, and delete. Support for sending emails with or without file attachments. Advanced filtering by sender, subject, date, and read status. Secure OAuth2 authentication via Nango or direct Google Cloud credentials. Account statistics and conversation thread support.

What can I use Gmail MCP Server for?

Automating email triage by marking specific senders as read. Drafting and sending professional replies based on conversation history. Extracting data from specific email threads for reporting. Managing multiple Gmail accounts through a single AI interface.

How do I install Gmail MCP Server?

Install Gmail MCP Server by running: pip install -e .

What MCP clients work with Gmail MCP Server?

Gmail MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Use Gmail MCP Server with Conare

Manage MCP servers visually, upload persistent context, and never start from zero with Claude Code & Codex.

Try Free