Gmail MCP Server

Gmail MCP Server

A local MCP server that provides tool-level access to Gmail, allowing Claude to search, read, send, and manage emails using the Gmail API.

Category
访问服务器

README

Gmail MCP Server

CI codecov Python 3.14+ License: MIT

A local MCP server that gives Claude native, tool-level access to Gmail. Runs locally via stdio transport — all tokens and credentials stay on your machine.

Prerequisites

  • Python 3.14+
  • uv for dependency management
  • A Google account with the Gmail API enabled

Quick Start

# Clone the repo
git clone https://github.com/stevesimpson418/gmail-mcp-server.git
cd gmail-mcp-server

# Install dependencies (creates .venv/ in the project directory)
uv sync

New to uv? uv sync reads pyproject.toml, creates a .venv/ virtualenv inside the project folder, and installs all dependencies into it. You don't need to activate it — uv run <command> handles that automatically.

Setting up Gmail

1. Create a Google Cloud project

Go to the Google Cloud Console and create a new project (or select an existing one).

2. Enable the Gmail API

Navigate to APIs & Services > Library, search for Gmail API, and click Enable.

3. Configure the OAuth consent screen

Before creating credentials, Google requires you to configure the OAuth consent screen. Go to APIs & Services > OAuth consent screen (or Google Auth Platform if prompted).

  1. Click Get Started (or Configure Consent Screen)
  2. Fill in the required fields:
    • App name — a name for your own reference (e.g. "Gmail MCP Server")
    • User support email — your email address
  3. Select an Audience:
    • Internal — only available if you're in a Google Workspace organisation
    • External — select this for personal Google accounts. The app starts in testing mode, which is fine for personal use — you just need to add yourself as a test user
  4. Contact information — your email (Google uses this to notify you of project changes)
  5. Click Save

About testing mode: External apps in testing mode are limited to users you explicitly add to the test user list. This is perfectly fine for a local MCP server — you only need your own account. Tokens for test users expire after 7 days, requiring re-consent. If this becomes inconvenient, you can publish the app (no verification needed for sensitive scopes used with fewer than 100 users in testing mode, but publishing removes the 7-day expiry).

4. Add test users

Go to APIs & Services > OAuth consent screen > Test users (or Audience in the new Google Auth Platform UI) and add your Google account email address.

5. Add OAuth scopes

Go to APIs & Services > OAuth consent screen > Scopes (or Data Access in the new UI) and add the following scope:

<!-- markdownlint-disable MD013 -->

Scope Why it's needed
https://www.googleapis.com/auth/gmail.modify Read messages, modify labels (archive, star, mark read/unread, apply/remove labels), manage drafts, send emails, and move messages to trash. This is the minimum single scope that covers all server operations — narrower scopes like gmail.readonly or gmail.send don't cover label modification or trash.

<!-- markdownlint-enable MD013 -->

This server does not request mail.google.com (full unrestricted access) — gmail.modify is scoped to read/write operations and cannot permanently delete messages.

6. Create OAuth 2.0 credentials

  1. Go to APIs & Services > Credentials
  2. Click Create Credentials > OAuth client ID
  3. Application type: Desktop app
  4. Give it a name for your own reference (e.g. "Gmail MCP — My Laptop")
  5. Click Create, then Download JSON
  6. Save the file as credentials/gmail_credentials.json in this project

Security note: The credentials/ directory is gitignored — your credentials and tokens will never be committed to the repository.

7. Run the OAuth consent flow

uv run gmail-mcp-auth

A browser window will open — sign in with the Google account you added as a test user and grant the requested permissions. The token is saved to credentials/token.json and auto-refreshes after this.

To use custom paths:

uv run gmail-mcp-auth --credentials /path/to/creds.json --token /path/to/token.json

Adding to Claude Desktop

Add the following to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS).

Tip: Run uv run which python from the project directory to get the exact path for command.

{
  "mcpServers": {
    "gmail": {
      "command": "/Users/you/gmail-mcp-server/.venv/bin/python",
      "args": ["-m", "gmail_mcp.server"],
      "env": {
        "GMAIL_CREDENTIALS_PATH": "/Users/you/gmail-mcp-server/credentials/gmail_credentials.json",
        "GMAIL_TOKEN_PATH": "/Users/you/gmail-mcp-server/credentials/token.json"
      }
    }
  }
}

The env block tells the server where to find your credentials at runtime. No .env file is needed — the config passes these values directly.

Restart Claude Desktop after saving. You should see all Gmail tools in the tools menu.

Adding to Claude Code CLI

Use the claude mcp add command to register the server. This works from any directory.

claude mcp add --scope user gmail-mcp-server \
  --transport stdio \
  --env GMAIL_CREDENTIALS_PATH=/path/to/gmail-mcp-server/credentials/gmail_credentials.json \
  --env GMAIL_TOKEN_PATH=/path/to/gmail-mcp-server/credentials/token.json \
  -- /path/to/gmail-mcp-server/.venv/bin/python -m gmail_mcp.server

Replace /path/to/gmail-mcp-server with the actual path where you cloned the repo.

Tip: Run uv run which python from the project directory to get the exact .venv/bin/python path for the command.

The --scope user flag saves to ~/.claude.json so the server is available across all projects. Without it, the command defaults to local scope (tied to whatever directory you run it from). To scope it to a single project instead, use --scope project which writes to .mcp.json in the project root.

To verify the server is registered:

claude mcp list

Restart Claude Code after adding. The Gmail tools should appear in the /mcp menu.

Note: Claude Code CLI uses a different configuration from Claude Desktop. The claude mcp add command is the recommended way to register MCP servers — do not add them to ~/.claude/settings.json as that file is used for permissions and hooks only.

Updating

To pull the latest version and update dependencies:

cd /path/to/gmail-mcp-server
git pull
uv sync

Restart Claude Desktop or Claude Code CLI after updating.

If a new version changes OAuth scopes, you'll need to re-consent by running uv run gmail-mcp-auth again.

Available Tools

Tool Description
search_gmail(query, max_results?) Search messages using Gmail query syntax (e.g. is:unread in:inbox)
read_gmail_message(message_id) Read a full message including body text
read_gmail_thread(thread_id) Read all messages in a thread
list_gmail_labels() List all labels (system and user-created)
list_gmail_attachments(message_id) List attachments on a message
read_gmail_attachment(message_id, attachment_id, filename, mime_type) Read attachment content inline
archive_gmail_messages(message_ids) Archive messages (remove from inbox)
bulk_archive_gmail(query) Search and archive all matching messages in one call
apply_gmail_label(message_ids, label_name) Apply a label to messages
remove_gmail_label(message_ids, label_name) Remove a label from messages
create_gmail_label(name, text_color?, background_color?) Create a new label
mark_gmail_read(message_ids) Mark messages as read
mark_gmail_unread(message_ids) Mark messages as unread
star_gmail_message(message_ids) Star messages
mark_gmail_important(message_ids) Mark messages as important
create_gmail_draft(to, subject, body, thread_id?, cc?) Create a draft email
send_gmail(to, subject, body, cc?) Send an email directly
send_gmail_draft(draft_id) Send a previously created draft
trash_gmail_messages(message_ids) Move messages to trash (recoverable for 30 days)

Usage Examples

Triage your inbox:

1. search_gmail(query="is:unread in:inbox")          → see what's new
2. read_gmail_message(message_id="msg_123")           → read the full message
3. archive_gmail_messages(message_ids=["msg_123"])     → archive after reading

Bulk cleanup:

bulk_archive_gmail(query="from:noreply@marketing.com in:inbox")
bulk_archive_gmail(query="is:unread in:inbox older_than:7d subject:newsletter")

Draft a reply:

create_gmail_draft(
    to="alice@example.com",
    subject="Re: Meeting",
    body="Sounds good, see you then!",
    thread_id="thread_abc"
)

Development

# Install dev dependencies
uv sync --dev

# Run tests
uv run pytest -v

# Run tests with coverage
uv run pytest --cov=gmail_mcp --cov-report=term-missing

# Lint
uv run ruff check src/ tests/

# Format
uv run ruff format src/ tests/

# Install git hooks
lefthook install

Local .env file

When running the server manually outside Claude Desktop/Code (e.g., for development or debugging), you can create a .env file in the project root so the server picks up credential paths without passing environment variables:

GMAIL_CREDENTIALS_PATH=credentials/gmail_credentials.json
GMAIL_TOKEN_PATH=credentials/token.json

This is only needed for local development. The Claude Desktop and Claude Code CLI configs pass these values directly via the env block.

Packaging & Distribution

This server is currently distributed as source via git. To install:

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

This is the standard distribution model for local-stdio MCP servers today. The project is already configured for wheel builds via hatchling, so future distribution options include:

  • PyPI — publish to PyPI, then install with uv tool install gmail-mcp-server or pip install gmail-mcp-server. Would require adding a publish workflow to CI.
  • uvx — once on PyPI, uvx gmail-mcp-server runs the server without cloning the repo. Claude Desktop/Code config would point to the uvx-managed binary instead of a local .venv.

Releases

This project uses release-please for automated versioning and releases. The version is determined by Conventional Commits:

  • fix: commits bump the patch version (e.g. 0.1.0 → 0.1.1)
  • feat: commits bump the minor version (e.g. 0.1.1 → 0.2.0)
  • BREAKING CHANGE in the commit footer bumps the major version

When commits land on main, release-please opens (or updates) a Release PR that:

  • Bumps the version in pyproject.toml
  • Updates CHANGELOG.md with grouped entries

Merging the Release PR creates a git tag and GitHub Release automatically.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选