Skip to main content

Gmail MCP server for Claude CLI — API (OAuth) and SMTP/IMAP backends

Project description

claude-gmail-mcp

PyPI

A super tiny Gmail MCP server for Claude Code. Lets Claude send, search, and read Gmail on your behalf.

Two backends are supported and auto-selected at startup:

  • Gmail API (OAuth) — recommended. No app password. Batch search. Direct Gmail web URLs on every result.
  • SMTP/IMAP (app password) — simpler setup. Fallback when the OAuth token isn't present.

I needed something for my projects — there were a bunch around which seemed super complicated. So why not have Claude CLI build one for me :-p

Prerequisites

  • uv installed
  • One of:
    • A Google Cloud OAuth client (Desktop app) — for the API backend, OR
    • A Gmail App Password — for the SMTP/IMAP backend

Install (Gmail API backend — recommended)

  1. In Google Cloud Console, create a project, enable the Gmail API, and configure the OAuth consent screen (External, add your Gmail as a test user). Create an OAuth client of type Desktop app and download the credentials JSON.

  2. Run the auth helper, pointing at the downloaded file:

    uvx --from claude-gmail-mcp claude-gmail-mcp-auth /path/to/credentials.json
    

    Browser opens → sign in → approve (scope: gmail.modify). Refresh token is saved to ~/.config/claude-gmail-mcp/token.json (perms 600).

  3. Register the MCP server with Claude Code (no env vars needed):

    claude mcp add gmail --scope user -- uvx claude-gmail-mcp
    

Install (SMTP/IMAP backend — fallback)

claude mcp add gmail --scope user \
  -e GMAIL_ADDRESS=you@gmail.com \
  -e GMAIL_APP_PASSWORD=your-app-password \
  -- uvx claude-gmail-mcp

Replace you@gmail.com and your-app-password with your actual credentials. Drop --scope user to install only for the current project directory.

Verify

claude mcp list

You should see gmail listed as a configured server. To see which backend is active, run:

uvx claude-gmail-mcp 2>&1 | head -1

Expected: [gmail-mcp] backend=api or [gmail-mcp] backend=imap. Ctrl-C to exit.

Backend selection

At startup the server picks exactly one backend:

  1. Token file at GMAIL_TOKEN_PATH (default ~/.config/claude-gmail-mcp/token.json) exists → API backend.
  2. Else GMAIL_ADDRESS + GMAIL_APP_PASSWORD env vars set → IMAP backend.
  3. Else tools return a "no backend configured" error.

To force a switch to the IMAP backend when a token file exists, set GMAIL_TOKEN_PATH to a non-existent path (or delete the token file).

Usage

Ask Claude to send an email:

Send an email to alice@example.com with subject "Hello" and body "Hi from Claude!"

Tools exposed:

  • send_emailto, subject, body, optional cc/bcc, html, attachments (local file paths; unreadable files are skipped with a warning).
  • search_emailsqueries (single string or list of strings), max_results (per query when a list is passed). Results include the Gmail message ID in hex and a direct Gmail web URL per hit.
  • read_emailuid (the hex ID from search_emails). Output includes the Gmail web URL at the top.

Batch search example:

Search Gmail for "is:unread from:alice" and "is:unread from:bob" — show me both side by side.

Claude passes both queries in a single tool call. The response is sectioned per query. API backend executes the list step in one HTTP roundtrip; IMAP backend iterates.

Attachment example:

Send an email to alice@example.com with subject "Report" and attach ~/Documents/report.pdf

Publishing to PyPI

python -m build && twine upload dist/*

For Development

git clone https://github.com/pliablepixels/claude-gmail-mcp.git
cd claude-gmail-mcp
uv sync
uv run pytest

Run the server locally:

uv run claude-gmail-mcp

Test with Claude Code using your local copy instead of the published package:

claude mcp add gmail --scope user \
  -- uv run --directory /path/to/claude-gmail-mcp claude-gmail-mcp

(For the IMAP backend add -e GMAIL_ADDRESS=... -e GMAIL_APP_PASSWORD=....)

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

claude_gmail_mcp-0.2.0.tar.gz (83.1 kB view details)

Uploaded Source

Built Distribution

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

claude_gmail_mcp-0.2.0-py3-none-any.whl (99.5 kB view details)

Uploaded Python 3

File details

Details for the file claude_gmail_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: claude_gmail_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 83.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for claude_gmail_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 83506260fc4cf08b0110d64e7a001773aa31496136cfd8d357e55cf9e788ab51
MD5 b6daab038c80fca62e12609dcc56f6b1
BLAKE2b-256 9e22c8b0cc6e482120cbae7846e6e113678871ecf36ca477b67280cecc4a729f

See more details on using hashes here.

File details

Details for the file claude_gmail_mcp-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_gmail_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff831b297d4894f49154c2f762be53d0d9ff0dadcd7bc19332cd430db0530c36
MD5 817daeaf899773373bd391e9e8d4f5d9
BLAKE2b-256 849e37ceb30a07e6b3decccf74cb0cef714c098c9c9126542a6093ffe5fab04c

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