
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 分