
Gmail Attachments Mcp
io.github.zayansalman由 GitHub 账号 zayansalman 发布v0.1.0更新于 Oct 24, 2026
Minimal MCP server for downloading Gmail attachments to disk. Read-only OAuth by default.
概览
让助手以只读 OAuth 权限搜索 Gmail,并把邮件附件文件下载到本地磁盘。
- 可以做什么
- 一个专注于把 Gmail 附件字节下载到磁盘的 MCP 服务器,同时也可作为独立命令行工具使用。它提供三个工具:gmail_search 使用 Gmail 查询语法返回带附件文件名的会话摘要;gmail_download_thread_attachments 下载某个会话中的全部附件;gmail_download_latest_matching 一次调用完成搜索并下载最近一条匹配邮件的附件。下载可按扩展名过滤并指定目标目录,每个文件返回路径、大小、MIME 类型和原始文件名。
- 适用场景
- 当托管版 Gmail 连接器只给出附件 ID 和元数据、而你需要真实文件时使用,例如从匹配邮件中保存发票、简历或报告。它也适合无界面或定时任务,因为缓存的刷新令牌可让 cron 任务无需浏览器即可运行。如果你还需要发送邮件或管理标签、草稿,请选择功能更全的 Gmail 服务器。
- 运行要求
- 本地 Python 安装(pip install gmail-attachments-mcp 或 uv tool install)。需要一个启用了 Gmail API 的 Google Cloud 项目、OAuth 同意屏幕和桌面应用类型的 OAuth 客户端;客户端密钥 JSON 路径由 GMAIL_MCP_CREDENTIALS 指定。首次需在浏览器中完成一次 OAuth 授权,之后刷新令牌缓存在 GMAIL_MCP_TOKEN 指定的路径。可选配置:GMAIL_MCP_DEFAULT_DEST_DIR、GMAIL_MCP_SCOPES、XDG_CONFIG_HOME。仅支持桌面端,没有托管版本。
安装
在 SourceWeft 中
- 打开 控制台中的 Gmail Attachments Mcp,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
gmail-attachments-mcp
A focused Model Context Protocol server (and standalone CLI) for downloading Gmail attachments to disk. Three tools, read-only OAuth scope, no extra surface area.
Built because the hosted claude.ai Gmail connector in Claude Desktop returns attachment IDs and metadata only — not the actual bytes. This server fills that gap for any MCP client (Claude Code, Claude Desktop, Cursor, Cline, etc.), and also works as a plain CLI for cron jobs and shell scripts.
If you used @GongRzhe/Gmail-MCP-Server (1.1k★, archived 2026-03-03) for its attachment-download workflow, this is a minimal successor focused on that single capability.
Features
- 3 MCP tools —
gmail_search,gmail_download_thread_attachments,gmail_download_latest_matching. That's the whole API. - Read-only OAuth scope (
gmail.readonly) — can't send, delete, or modify mail. - Works as both an MCP server and a standalone CLI — same code, same auth token, both surfaces.
- Env-var-driven config —
GMAIL_MCP_CREDENTIALS,GMAIL_MCP_TOKEN,GMAIL_MCP_DEFAULT_DEST_DIR. - Cron-friendly — once authorized, the cached refresh token lets headless jobs run indefinitely.
Install
One-time setup (~10 minutes)
You need a Google Cloud OAuth client. The server runs entirely on your machine; nothing leaves it.
- Sign in to Google Cloud Console with the Gmail account whose attachments you want to download.
- Create a project (or pick an existing one).
- Enable the Gmail API: console.cloud.google.com/apis/library/gmail.googleapis.com.
- Configure the OAuth consent screen under APIs & Services → OAuth consent screen:
- Google Workspace users: User type = Internal (no app verification needed).
- Personal Gmail users: User type = External. Add your own Gmail address as a test user under "Test users".
- APIs & Services → Credentials → + Create credentials → OAuth client ID
- Application type: Desktop app
- Download the JSON.
- Run setup:
A browser window opens for OAuth consent. After consent, a refresh token is cached at ~/.config/gmail-attachments-mcp/token.json (or $XDG_CONFIG_HOME/gmail-attachments-mcp/).
Verify:
See docs/setup-google-oauth.md for screenshots and troubleshooting.
Use it from Claude Code
Then in any Claude Code session:
Use the gmail-attachments MCP to download the latest CV from
[email protected]to~/CVs.
Use it from Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (Mac) or %APPDATA%/Claude/claude_desktop_config.json (Windows):
Restart Claude Desktop. See docs/claude-desktop.md for details.
Use it from Cursor / Cline / Continue / others
Any MCP client that supports stdio servers. Point it at the same gmail-attachments-mcp serve command. See docs/other-clients.md.
Use it from the shell or cron
Cron example — pull CV attachments hourly:
The 3 MCP tools
gmail_search(query, max_results=10)
Returns thread summaries with attachment filenames. Use Gmail's standard query syntax.
gmail_download_thread_attachments(thread_id, dest_dir?, extensions?)
Downloads every attachment in a thread to disk. Returns path, size_bytes, mime_type, original_filename per file.
gmail_download_latest_matching(query, dest_dir?, extensions?)
Convenience: search + download from the single most recent match, in one call.
Configuration
All paths can be overridden via environment variables.
Security
- Token storage: refresh token is written to
~/.config/gmail-attachments-mcp/token.jsonwith mode0600. Anyone with shell access to your account can read your Gmail. Treat the file like a password. - OAuth scope: default is
gmail.readonly. Cannot send, delete, or modify mail. If you change$GMAIL_MCP_SCOPES, you're on the hook for the consequences. - Credential file: your OAuth client secret JSON is not a password — it identifies your app to Google. But never commit it. The included
.gitignoreblocks the common filenames. - OAuth client: your client lives in your Google Cloud project. There's no central server, no telemetry, nothing leaves your machine.
Troubleshooting
No valid Gmail token when invoked from Claude Desktop / cron
The first OAuth flow requires a browser. Run gmail-attachments-mcp setup once in a terminal where a browser can open. Subsequent runs use the cached refresh token.
Token has been expired or revoked
Refresh tokens stay valid as long as you use them at least every 6 months and don't revoke them at myaccount.google.com/permissions. Re-auth:
Access blocked: This app's request is invalid
On personal Gmail, your OAuth consent screen needs your address listed under Test users. Workspace users should select Internal audience to avoid this.
HttpError 403: Request had insufficient authentication scopes
You changed $GMAIL_MCP_SCOPES without re-authorizing. Run gmail-attachments-mcp setup --reauth.
Comparison with other Gmail MCP servers
Pick this one if you want a tiny, focused, read-only tool. Pick a fuller one if you also need to send mail, manage labels, drafts, threads, etc.
Authentication — bring your own Google OAuth client
There are no API keys and no shipped secrets. The server authenticates to your Google account with an OAuth client you create, and caches a refresh token locally. The author has zero access to your data.
- Why your own client? Google's restricted scopes (here,
gmail.readonly) can't be redistributed in a shared app, and an unverified shared app is capped at 100 users. "Bring your own OAuth client" is the standard pattern for personal-data MCP servers. - What you need: a free Google Cloud project, the Gmail API enabled, an OAuth consent screen, and a Desktop OAuth client. Full walkthrough → docs/setup-google-oauth.md.
- Where your token lives:
~/.config/gmail-attachments-mcp/token.json(mode0600). Delete it to revoke locally; revoke fully at myaccount.google.com/permissions. - No hosted/SaaS option — everything runs locally; your mail never touches a third-party server.
Related tools
Part of a small family of focused, local MCP servers for Google Workspace data the hosted connectors don't expose:
- gmail-attachments-mcp — download Gmail attachment bytes to disk (this repo)
- google-drive-comments-mcp — read comment threads on Docs/Sheets/Slides
- google-drive-files-mcp — move/organize Drive files
They can share one OAuth login or stay isolated — see each repo's setup.
License
MIT. See LICENSE.
Contributing
Issues and PRs welcome. Run pytest and ruff check src tests before submitting.
来源:README.md,提交 2f54ec5
工具
0版本历史
1- v0.1.0最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分