Skip to main content
Glama

Gmail second account MCP server

Version Python Node OAuth

从 Claude.ai 和 Claude Code 读写一个 Gmail 邮箱。Claude.ai 自带的 Gmail 连接器只处理单个账户,因此这个项目用于第二个账户:每个邮箱运行一个实例,每个连接器只访问分配给它的地址。

每个实例一个邮箱

实例服务哪个账户由 GMAIL_CREDENTIALS_DIR 决定,该进程无法访问任何其他内容。这种隔离正是关键,而非限制:当服务器只持有一组凭据时,草稿不可能落入错误的邮箱。

Related MCP server: Gmail MCP Local Server

工具

读取

工具

返回内容

gmail_profile

此实例服务的邮箱及其计数

gmail_search

使用 Gmail 自身的查询语法搜索

gmail_get_message

单条消息及其正文

gmail_get_thread

整个会话,按时间从旧到新

gmail_list_attachments

消息附件的文件名、类型和大小

gmail_list_labels

所有标签及其 ID

gmail_list_drafts / gmail_get_draft

邮箱中待处理的草稿

写入

工具

作用

gmail_create_draft

撰写草稿,可选择作为回复加入会话

gmail_update_draft

替换草稿内容

gmail_delete_draft

丢弃草稿

gmail_modify_labels

在消息上添加或移除标签

gmail_archive

将消息移出收件箱

gmail_mark_read

标记为已读或未读

gmail_trash / gmail_untrash

移入回收站及恢复

gmail_create_label / gmail_delete_label

管理标签

gmail_send_draft

发送现有草稿

gmail_send_message

一步完成撰写并发送

这两个发送工具被标记为破坏性操作,并在其描述中明确说明:它们会触达他人,且无法撤销。安全的做法是先使用 gmail_create_draft 创建草稿,阅读确认后,再在有人批准文本后使用 gmail_send_draft 发送。

搜索

gmail_search 使用与 Gmail 搜索框相同的运算符:

is:unread from:client.com
subject:invoice has:attachment newer_than:7d
label:important -in:trash

它返回每封邮件的标头和摘要,而不是正文,因此宽泛搜索的返回量仍然很小。后续可配合 gmail_get_messagegmail_get_thread 使用。

整体结构

Claude.ai / Claude Code
        |  HTTPS
   Cloudflare Tunnel, or any proxy that gives you HTTPS
        |
   nginx  127.0.0.1:8461
        |
   auth-server.js  :8462    handles the login and the tokens
        |
   gmail-mcp  :8460         the server itself, local only
        |
   gmail.googleapis.com

MCP 本身没有登录机制,并且只监听本机,因此所有到达它的请求都已经通过了登录。

设置

你需要一个已启用 Gmail API 的 Google Cloud OAuth 客户端,以及该邮箱的刷新令牌。凭据目录包含两个文件:

credentials.json        {"refresh_token": "..."}
gcp-oauth.keys.json     the downloaded OAuth client

gmail.modify 是要授予的权限范围。它涵盖读取、标记、起草和发送;如果你希望凭据本身无法发送,可降级为 gmail.readonlygmail.compose

git clone https://github.com/rollecode/gmail-second-account-mcp.git
cd gmail-second-account-mcp
uv venv && uv pip install -e .
npm install --omit=dev

CONFIG_DIR=~/.config/gmail-mcp node set-password.js 'your-password-here'
openssl rand -hex 32 > ~/.config/gmail-mcp/token
chmod 600 ~/.config/gmail-mcp/token

systemd/*.servicenginx/gmail-mcp.conf 中填写 YOUR_USER、主机名和凭据目录,然后:

sudo cp systemd/*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now gmail-mcp gmail-mcp-auth

sudo cp nginx/gmail-mcp.conf /etc/nginx/sites-enabled/gmail-mcp
sudo nginx -t && sudo systemctl reload nginx

将隧道或 HTTPS 代理指向 127.0.0.1:8461。OAuth 需要 HTTPS。

从外部检查:发现端点返回元数据,且不带令牌访问 /mcp 必须返回 401

curl https://your-host/.well-known/oauth-authorization-server
curl -o /dev/null -w '%{http_code}\n' -X POST https://your-host/mcp

连接

Claude.ai:设置、连接器、添加自定义连接器,https://your-host/mcp,客户端 ID 和密钥留空。

Claude Code:

claude mcp add --transport http gmail https://your-host/mcp \
  --header "Authorization: Bearer $(cat ~/.config/gmail-mcp/token)" --scope user

本地通过 stdio 运行,完全不需要服务器:

GMAIL_CREDENTIALS_DIR=/path/to/creds claude mcp add gmail -- /path/to/.venv/bin/gmail-mcp

配置

变量

用途

GMAIL_CREDENTIALS_DIR

存放 credentials.jsongcp-oauth.keys.json 的目录

GMAIL_ACCOUNT_LABEL

邮箱名称,显示在服务器的说明中

MCP_PUBLIC_URL

公共地址,用于展示图标

ISSUER

登录服务器的公共源

PORT

登录服务器端口,默认为 8462

UPSTREAM

MCP 服务器 URL,默认为 http://127.0.0.1:8460

CONFIG_DIR

密码、令牌和 OAuth 数据库的存放位置

访问令牌过期时会在内存中刷新;只有刷新令牌会从磁盘读取。

致谢

登录层来自 rollecode/obsidian-remote-mcp

A
license - permissive license
A
quality
A
maintenance

Maintenance

Maintainers
Response time
0dRelease cycle
2Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    F
    maintenance
    Enables reading, sending, searching, and managing Gmail through Claude using the official Google Gmail API.
    165
    3
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables Claude to read, search, send, and manage Gmail messages and threads through natural language.
    205
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables Gmail integration with Claude Code for reading, sending, searching emails, and managing labels through natural language.
    205
    MIT

View all related MCP servers

Related MCP Connectors

  • Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…

  • Manage Gmail messages, threads, labels, drafts, and settings from your workflows. Send and organiz…

  • Read, search, send, organize, draft and schedule email across your inboxes from any MCP client.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rollecode/gmail-second-account-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server