Skip to main content

MCP server for Gmail — send, search, read emails, manage drafts and labels via Google OAuth2.

Project description

Gmail MCP Server

A production-ready Model Context Protocol (MCP) server for Gmail operations. Connect any AI agent to Gmail — send emails, search your inbox, manage drafts, organize with labels, reply to threads, and more.

This is an independent, generalized MCP server. It is not tied to any specific project and can be connected to any AI agent that supports MCP (Claude Desktop, Cursor, WorkOS, or custom agents).

Features

  • 📨 Send & Reply: Compose emails, reply to threads, with CC support
  • 📥 Read Inbox: Fetch emails from any label (INBOX, SENT, STARRED, etc.)
  • 🔍 Search: Full Gmail query syntax (from:, subject:, has:attachment, etc.)
  • 📝 Drafts: Create, list, and send drafts
  • 🏷️ Labels: List, add, and remove labels on messages
  • 🧵 Threads: View full conversation threads
  • Read/Unread: Mark messages as read or unread

Installation

Recommended — no pre-install required (uses uv):

# uv manages a temporary isolated environment automatically
uvx --from workos-gmail-mcp-server gmail-mcp-server

Or install permanently with pip:

pip install workos-gmail-mcp-server

Or install from source:

git clone https://github.com/workos/workos-gmail-mcp-server
cd workos-gmail-mcp-server
pip install -e .

Quick Start

export GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
export GOOGLE_CLIENT_SECRET="GOCSPX-your-secret"
export GOOGLE_REFRESH_TOKEN="1//your-refresh-token"

# Recommended: run via uvx (no install needed)
uvx --from workos-gmail-mcp-server gmail-mcp-server

# Or if installed via pip
gmail-mcp-server

# Or run as a Python module
python -m gmail_mcp_server

Configuration

Environment Variables

Variable Required Description
GOOGLE_CLIENT_ID ✅ Yes OAuth2 Client ID from Google Cloud Console
GOOGLE_CLIENT_SECRET ✅ Yes OAuth2 Client Secret
GOOGLE_REFRESH_TOKEN ✅ Yes OAuth2 Refresh Token (generated once, used to auto-refresh access tokens)

Getting Google OAuth2 Credentials

1. Create a Google Cloud Project

  1. Go to Google Cloud Console
  2. Create a new project (or select existing)
  3. Enable the Gmail API under APIs & Services → Library

2. Configure OAuth Consent Screen

  1. Go to APIs & Services → OAuth consent screen
  2. Choose External user type
  3. Fill in app name and email
  4. Add scopes: https://www.googleapis.com/auth/gmail.modify, https://www.googleapis.com/auth/gmail.compose

3. Create OAuth2 Credentials

  1. Go to APIs & Services → Credentials
  2. Click Create CredentialsOAuth client ID
  3. Application type: Desktop app
  4. Note down the Client ID and Client Secret

4. Generate a Refresh Token

Option A — Using Google OAuth Playground:

  1. Go to OAuth 2.0 Playground
  2. Click ⚙️ Settings → check Use your own OAuth credentials → enter your Client ID & Secret
  3. In Step 1, add scopes: https://www.googleapis.com/auth/gmail.modify and https://www.googleapis.com/auth/gmail.compose
  4. Click Authorize APIs → sign in → grant access
  5. In Step 2, click Exchange authorization code for tokens
  6. Copy the Refresh Token

Option B — Using the included helper script:

python MCP_servers/get_google_token.py \
  --client-id "YOUR_CLIENT_ID" \
  --client-secret "YOUR_CLIENT_SECRET"

Connecting to AI Agents

Note: Use uvx --from workos-gmail-mcp-server gmail-mcp-server in all configs below. The --from flag is needed because the PyPI package name (workos-gmail-mcp-server) differs from the CLI entry point (gmail-mcp-server). You must have uv installed (brew install uv on macOS).

Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "gmail": {
      "command": "uvx",
      "args": ["--from", "workos-gmail-mcp-server", "gmail-mcp-server"],
      "env": {
        "GOOGLE_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
        "GOOGLE_CLIENT_SECRET": "GOCSPX-your-secret",
        "GOOGLE_REFRESH_TOKEN": "1//your-refresh-token"
      }
    }
  }
}

Alternative — if you have installed via pip install workos-gmail-mcp-server and prefer not to use uvx, use the full absolute path to the binary instead:

{ "command": "/path/to/your/bin/gmail-mcp-server" }

Find the path with: which gmail-mcp-server

Cursor

Edit ~/.cursor/mcp.json (global) or .cursor/mcp.json (project):

{
  "mcpServers": {
    "gmail": {
      "command": "uvx",
      "args": ["--from", "workos-gmail-mcp-server", "gmail-mcp-server"],
      "env": {
        "GOOGLE_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
        "GOOGLE_CLIENT_SECRET": "GOCSPX-your-secret",
        "GOOGLE_REFRESH_TOKEN": "1//your-refresh-token"
      }
    }
  }
}

VS Code (GitHub Copilot / MCP extension)

Edit .vscode/mcp.json in your project:

{
  "servers": {
    "gmail": {
      "type": "stdio",
      "command": "uvx",
      "args": ["--from", "workos-gmail-mcp-server", "gmail-mcp-server"],
      "env": {
        "GOOGLE_CLIENT_ID": "${input:googleClientId}",
        "GOOGLE_CLIENT_SECRET": "${input:googleClientSecret}",
        "GOOGLE_REFRESH_TOKEN": "${input:googleRefreshToken}"
      }
    }
  },
  "inputs": [
    {
      "id": "googleClientId",
      "type": "promptString",
      "description": "Google OAuth2 Client ID"
    },
    {
      "id": "googleClientSecret",
      "type": "promptString",
      "description": "Google OAuth2 Client Secret",
      "password": true
    },
    {
      "id": "googleRefreshToken",
      "type": "promptString",
      "description": "Google OAuth2 Refresh Token",
      "password": true
    }
  ]
}

WorkOS / Custom Agents

Add to .mcp.json in your project root:

{
  "mcpServers": {
    "gmail": {
      "transport": "stdio",
      "command": "uvx",
      "args": ["--from", "workos-gmail-mcp-server", "gmail-mcp-server"],
      "env": {
        "GOOGLE_CLIENT_ID": "${GOOGLE_CLIENT_ID}",
        "GOOGLE_CLIENT_SECRET": "${GOOGLE_CLIENT_SECRET}",
        "GOOGLE_REFRESH_TOKEN": "${GOOGLE_REFRESH_TOKEN}"
      }
    }
  }
}

Available Tools (14)

Messages

Tool Description
gmail_send_email Send an email (to, subject, body, optional cc)
gmail_reply_email Reply to an email by message ID
gmail_read_emails Read recent emails from a label (with pagination)
gmail_get_email Get a single email by message ID
gmail_search_emails Search emails using Gmail query syntax
gmail_mark_read Mark an email as read
gmail_mark_unread Mark an email as unread

Drafts

Tool Description
gmail_create_draft Create a draft email
gmail_list_drafts List draft emails
gmail_send_draft Send an existing draft

Labels

Tool Description
gmail_list_labels List all Gmail labels
gmail_add_label Add a label to a message
gmail_remove_label Remove a label from a message

Threads

Tool Description
gmail_get_thread Get a full email thread

Development

git clone https://github.com/workos/workos-gmail-mcp-server
cd workos-gmail-mcp-server
pip install -e .

# Run tests
pytest

# Run the server locally
GOOGLE_CLIENT_ID=... GOOGLE_CLIENT_SECRET=... GOOGLE_REFRESH_TOKEN=... python -m gmail_mcp_server

Publishing

To PyPI

pip install build twine
rm -rf dist/ build/ src/*.egg-info
python -m build
pip install "packaging>=24.2"   # required for Metadata 2.4 support in twine
twine check dist/*              # validate before uploading
twine upload dist/*

To MCP Registry

mcp-publisher login github
mcp-publisher publish

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

workos_gmail_mcp_server-2.0.1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

workos_gmail_mcp_server-2.0.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file workos_gmail_mcp_server-2.0.1.tar.gz.

File metadata

  • Download URL: workos_gmail_mcp_server-2.0.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for workos_gmail_mcp_server-2.0.1.tar.gz
Algorithm Hash digest
SHA256 4029ddc44508b2f8565f079ffee959c520d0a56be28bddd4c5df903be9e6d689
MD5 b3eb8e47c8b1c4b2c9bbfc9a8ebdd176
BLAKE2b-256 4dfa8bcf60b34b5be4f8869caa0d966c675d6e47ff08eac3b65ae30db172ab55

See more details on using hashes here.

File details

Details for the file workos_gmail_mcp_server-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for workos_gmail_mcp_server-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c744a36999c422395e8ec313d6d2d60edb1a42c978f1b4d29882788bd4b0d142
MD5 4138fbb8bcb61a08784cdd4181e085f8
BLAKE2b-256 a32d9c31e011bbd6d0527a0f5688fd56752b6252c6b10af978cb38ca406e84b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page