gmail-mcp

gmail-mcp

A local MCP server that gives Claude access to multiple Gmail accounts simultaneously for search, read, draft, send, label, and a scheduled cross-inbox digest, with enforced send policies per mailbox.

Category
访问服务器

README

gmail-mcp

A local MCP server that gives Claude access to several Gmail accounts at once — search, read, draft, send, label, and a scheduled cross-inbox digest — without switching mailboxes.

Runs entirely on your machine. Nothing is hosted; mail goes only to Google.

The problem

Running several mailboxes — personal, sales, support, billing — means switching between them all day. AI assistants don't fix it: they connect to one account, or take broad access with no way to say this one may send, that one may not. Unrestricted send access to a client-facing address is why most people never connect one at all.

Who it's for

Freelancers, agencies and small teams with several Gmail or Workspace mailboxes who want an assistant across all of them, and a hard guarantee about what it can send.

What it does

Ten tools, each taking an explicit account alias so the mailbox is never ambiguous.

Tool Purpose
list_accounts Aliases, addresses, send policies
search_mail Gmail query syntax against one account
read_message / read_thread Full body; threads with quotes collapsed
create_draft / send_message / send_draft Compose, gated by policy
list_labels / modify_labels Labels — also marks read and archives
check_inboxes New unread across every account, for scheduled use

Send safety is the core design decision. Each mailbox declares send, confirm, or draft_only in config, enforced in code rather than in a prompt — so neither the model nor anything written into the mail it reads can talk it out of it. check_inboxes reads untrusted email on a schedule, which is exactly why that control can't live in an instruction.

Architecture

flowchart TD
    H["Claude Desktop · Claude Code"] -->|stdio| S["server.py<br/>10 tools — validate, delegate, shape"]
    S --> P{"send policy gate<br/>send · confirm · draft_only"}
    P -->|blocked| D["draft"]
    P -->|allowed| T["transmit"]
    S --> G["gmail/<br/>search · messages · compose · labels"]
    S --> C["check.py<br/>parallel watermarked sweep"]
    G --> CL["client.py<br/>retry · error mapping · per-account cache"]
    C --> CL
    T --> CL
    CL --> A["auth.py — OAuth refresh"]
    A --> ST["storage.py<br/>OS keyring, or 0600 file"]
    CL --> API[("Gmail API — gmail.modify")]

Every Gmail call passes through one choke point owning retries and error mapping, and each account gets its own service object — which is what makes the parallel sweep safe. check_inboxes keeps a per-account watermark, so a scheduled run reports only genuinely new mail.

Setup

Full guide: docs/SETUP.md.

1. Google Cloud — enable the Gmail API, configure an OAuth consent screen (Internal for a Workspace domain, External for consumer Gmail), add the single scope gmail.modify, create a Desktop app OAuth client, and save the JSON as client_secret.json in your config directory.

2. Install

git clone <this repo> && cd gmail-mcp
uv sync
cp config.example.toml <config-dir>/config.toml   # then edit it
uv run gmail-mcp auth add <alias>                 # once per account
uv run gmail-mcp doctor                           # verify every account
OS Config directory
Linux ~/.config/gmail-mcp/
macOS ~/Library/Application Support/gmail-mcp/
Windows %LOCALAPPDATA%\gmail-mcp\

3a. Claude Code — any OS:

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

3b. Claude Desktop — add to claude_desktop_config.json:

{
  "mcpServers": {
    "gmail": {
      "command": "/absolute/path/to/uv",
      "args": ["--directory", "/absolute/path/to/gmail-mcp",
               "run", "gmail-mcp", "serve"]
    }
  }
}
OS Config file
macOS ~/Library/Application Support/Claude/claude_desktop_config.json
Windows %APPDATA%\Claude\claude_desktop_config.json
Linux ~/.config/Claude/claude_desktop_config.json

Absolute paths in both: neither host inherits a shell PATH, and a bare command name is the usual reason a server silently fails to start.

Demo

📹 Recording: add link here

Local server, so no hosted instance. Two moves:

  1. "Check all my inboxes and tell me what needs my attention." Ask again — nothing new, because each account remembers where it got to.
  2. "Send this from my personal account." It returns a draft and names the policy that stopped it.

Design notes

  • Least privilege. One scope, gmail.modify — which cannot permanently delete mail. Chosen, not inherited.
  • Credentials live in the OS keyring (Keychain, Credential Manager, Secret Service), falling back to a 0600 file. Deliberately not encrypted: the server starts unattended, so any key would sit beside the ciphertext.
  • Failure isolation. A revoked token fails one mailbox and names the fix; the others keep working.
  • Correct replies. In-Reply-To and References are set, so replies thread in Outlook and Apple Mail — not only Gmail.
  • Cross-platform via platformdirs and keyring.

Development

uv sync && uv run pytest

193 tests, written test-first, running offline against a fake Gmail API — no network, credentials, or live mailbox needed. One opt-in integration test covers the real OAuth round trip.

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选