Skip to main content

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

Project description

Gmail MCP Server

Production-quality Model Context Protocol server for Gmail.

๐Ÿ“ง Send emails โ€” compose and send with CC support ๐Ÿ“ฅ Read emails โ€” fetch from any label (INBOX, SENT, etc.) ๐Ÿ” Search emails โ€” full Gmail query syntax ๐Ÿ“ Manage drafts โ€” create and send drafts ๐Ÿท๏ธ Organize labels โ€” list, add, remove labels ๐Ÿงต View threads โ€” get full conversation threads

Installation

pip install workos-gmail-mcp-server

Or install from source:

cd gmail_mcp_server
pip install -e .

Quick Start

export GOOGLE_CREDENTIALS_PATH=/path/to/credentials.json
export GOOGLE_TOKEN_PATH=/path/to/token.json
gmail-mcp-server

Configuration

Variable Required Description
GOOGLE_CREDENTIALS_PATH โœ… Path to OAuth2 credentials.json from Google Cloud Console
GOOGLE_TOKEN_PATH โœ… Path to token.json (generated after first OAuth consent)

OAuth Setup Guide

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 scope: https://www.googleapis.com/auth/gmail.modify

3. Create OAuth2 Credentials

  1. Go to APIs & Services โ†’ Credentials
  2. Click Create Credentials โ†’ OAuth client ID
  3. Application type: Desktop app
  4. Download the JSON file as credentials.json

4. Generate token.json

Run this one-time script to authorize and generate token.json:

from google_auth_oauthlib.flow import InstalledAppFlow

SCOPES = ["https://www.googleapis.com/auth/gmail.modify"]

flow = InstalledAppFlow.from_client_secrets_file("credentials.json", SCOPES)
creds = flow.run_local_server(port=0)

with open("token.json", "w") as f:
    f.write(creds.to_json())

print("token.json created successfully!")

5. Set Environment Variables

export GOOGLE_CREDENTIALS_PATH=/absolute/path/to/credentials.json
export GOOGLE_TOKEN_PATH=/absolute/path/to/token.json

Connecting to AI Agents

Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "gmail": {
      "command": "gmail-mcp-server",
      "env": {
        "GOOGLE_CREDENTIALS_PATH": "/path/to/credentials.json",
        "GOOGLE_TOKEN_PATH": "/path/to/token.json"
      }
    }
  }
}

Cursor / VS Code

Add to .mcp.json in your project root:

{
  "mcpServers": {
    "gmail": {
      "command": "gmail-mcp-server",
      "env": {
        "GOOGLE_CREDENTIALS_PATH": "/path/to/credentials.json",
        "GOOGLE_TOKEN_PATH": "/path/to/token.json"
      }
    }
  }
}

Available Tools

# Tool Description
1 gmail_send_email Send an email (to, subject, body, optional cc)
2 gmail_read_emails Read recent emails from a label
3 gmail_get_email Get a single email by message ID
4 gmail_search_emails Search emails using Gmail query syntax
5 gmail_mark_read Mark an email as read
6 gmail_mark_unread Mark an email as unread
7 gmail_create_draft Create a draft email
8 gmail_send_draft Send an existing draft
9 gmail_list_labels List all Gmail labels
10 gmail_add_label Add a label to a message
11 gmail_remove_label Remove a label from a message
12 gmail_get_thread Get a full email thread

Development

# Install in development mode
pip install -e .

# Run tests
pytest tests/ -v

# Run the server
gmail-mcp-server

Project Structure

gmail_mcp_server/
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ server.json
โ”œโ”€โ”€ src/gmail_mcp_server/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ __main__.py
โ”‚   โ”œโ”€โ”€ config.py
โ”‚   โ”œโ”€โ”€ client.py
โ”‚   โ”œโ”€โ”€ server.py
โ”‚   โ””โ”€โ”€ tools/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ messages.py
โ”‚       โ”œโ”€โ”€ drafts.py
โ”‚       โ”œโ”€โ”€ labels.py
โ”‚       โ””โ”€โ”€ threads.py
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ conftest.py
    โ”œโ”€โ”€ test_client.py
    โ””โ”€โ”€ test_messages.py

License

MIT

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.0.tar.gz (14.1 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.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: workos_gmail_mcp_server-2.0.0.tar.gz
  • Upload date:
  • Size: 14.1 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.0.tar.gz
Algorithm Hash digest
SHA256 c82fa56f3817839d27587cb33a55c2189b5f4eebcefa40b7aeaa083db13cbea5
MD5 61141d6d82c985544e4bb64cfba52fe0
BLAKE2b-256 1f3349210bca35f2c23324a47044b316532e00ad84c4af2b55ea03e1c3b3f8db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for workos_gmail_mcp_server-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c06f8bb166684ba83a649f18dea0564e47860c3b23d58c593cad69f72b705ce
MD5 66cc6598070eff5a99d3ab295e9ef843
BLAKE2b-256 6759791f21c0b68e52d8d42f67ad8dfee143d8b28ef6ed289db743dd0649bc0f

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