Skip to main content

MCP server for Gmail - search emails, read messages, download attachments

Project description

Gmail MCP Server

An MCP (Model Context Protocol) server that provides Gmail integration for AI assistants like Claude. Search emails, read messages, and download attachments directly from your Gmail account.

Features

  • Search emails using Gmail's powerful search syntax (from:, subject:, has:attachment, etc.)
  • Read full email content including body and attachment metadata
  • Download attachments to your local filesystem

Requirements

  • Python 3.10+
  • uv (recommended) or pip
  • A Google Cloud project with Gmail API enabled

Installation

1. Clone and install dependencies

git clone https://github.com/yourusername/gmail-mcp.git
cd gmail-mcp
uv sync

2. Set up Google Cloud credentials

  1. Go to Google Cloud Console
  2. Create a new project (or select existing)
  3. Enable the Gmail API
  4. Go to APIs & Services > Credentials
  5. Click Create Credentials > OAuth client ID
  6. Select Desktop app as application type
  7. Download the JSON file

3. Configure credentials

Save the downloaded credentials file:

mkdir -p ~/.gmail-mcp
mv ~/Downloads/client_secret_*.json ~/.gmail-mcp/gcp-oauth.keys.json

Or set via environment variable:

export GMAIL_CREDENTIALS_PATH=/path/to/your/credentials.json

4. First-time authorization

Run the server once to complete OAuth:

uv run python -m gmail_mcp

A browser window will open for you to authorize access. The token is saved to ~/.gmail-mcp/token.json for future use.

Usage with Claude Desktop

Add to your Claude Desktop configuration (claude_desktop_config.json):

macOS/Linux:

{
  "mcpServers": {
    "gmail": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/gmail-mcp", "python", "-m", "gmail_mcp"]
    }
  }
}

Windows:

{
  "mcpServers": {
    "gmail": {
      "command": "uv",
      "args": ["run", "--directory", "C:/path/to/gmail-mcp", "python", "-m", "gmail_mcp"]
    }
  }
}

Available Tools

search_emails

Search Gmail using Gmail search syntax.

search_emails(query="from:example@gmail.com", max_results=10)

Query examples:

  • from:example@gmail.com - emails from specific sender
  • subject:invoice - emails with subject containing "invoice"
  • has:attachment - emails with attachments
  • after:2024/01/01 - emails after date
  • is:unread - unread emails
  • label:important - emails with specific label

get_email

Get full email content by message ID.

get_email(message_id="abc123")

Returns: id, from, to, subject, date, body, attachments

download_attachment

Download email attachment to specified path.

download_attachment(
    message_id="abc123",
    attachment_id="xyz789",
    save_path="/path/to/save/file.pdf"
)

Development

# Run with MCP inspector
uv run mcp dev src/gmail_mcp/server.py

# Run tests
uv run pytest

# Lint
uv run ruff check src/

Security Notes

  • Only gmail.readonly scope is used - this server cannot send or modify emails
  • OAuth tokens are stored locally in ~/.gmail-mcp/token.json
  • Never commit credentials or tokens to version control

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

mcp_gmail_reader-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

mcp_gmail_reader-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_gmail_reader-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_gmail_reader-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_gmail_reader-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d40542087c1c7517380bb4b098a53c7121f24885cf55e92195c2ac8090f71faa
MD5 a7e0462444def142f26818c735d8e360
BLAKE2b-256 06bd46c2fbf401ce8f453257a0bc04fa77cba8c01b9217c625aa735233e68131

See more details on using hashes here.

File details

Details for the file mcp_gmail_reader-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_gmail_reader-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_gmail_reader-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8b3e889ab3bc295082402d5bd96ea48d917c85ac376ef63efbfec24559f2cba
MD5 93eea1a6270826de8af0e5ccc88ca277
BLAKE2b-256 95e43948b023f9112b2a88c79e162d3afedf72cd78f16726bb68527d203fa417

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