Gmail for AI agents: search, read, download attachments, send, reply, forward, drafts, labels. CLI with json and an MCP server.
gmail-agent
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
Gmail for AI agents and the people who run them: search, read, download attachments, send, reply, forward, drafts, labels and trash.
gmail-agent is one small Python package with two faces:
- a **CLI** for agents that have a shell (Claude Code, Codex, Aider, your own scripts), with --json output
- an **MCP server** over stdio for clients like Claude Desktop and Claude Code
It talks directly to the Gmail API from your machine using your own Google Cloud OAuth client, so there is no third-party server in between. You choose how much access it gets when you log in, from read-only up to full.
Why another one? A lot of real agent work with mail is about attachments: find last quarter's invoices, save them, read the PDFs. The hosted Gmail connectors can't save files to disk, and the most used open-source Gmail MCP server is archived. gmail-agent handles attachments well, shows you any write before it happens, and only offers the tools your login allows. See How it compares.
What it does
**Read**
- Search with Gmail syntax (from:, has:attachment, filename:pdf, newer_than:30d, ...), paginated
- Read a message or a whole thread as plain text (HTML mail is converted)
- List labels and drafts
**Attachments**
- List a message's attachments with name, type, size and part id
- Download from one message, or every attachment from every message matching a query
- Extract text from PDF and text attachments without saving them
Downloads never overwrite anything. If invoice.pdf exists, the next one becomes invoice_1.pdf, and you get the real paths back. Names are sanitized, so a file called ../../.ssh/config lands as config inside the folder you picked.
**Write**
- Send new mail with attachments, Cc/Bcc, plain text or HTML
- Reply and reply-all in the same thread (In-Reply-To, References and thread id are set, the original is quoted)
- Forward, including the original attachments
- Drafts: create, list, show, update, send, delete
- Labels: create, rename, delete, add to and remove from messages or threads
- Mark read or unread, star, archive
- Trash and untrash; permanent delete behind an explicit flag
Every write command takes --dry-run, which prints the exact API request and, for mail, the MIME message without changing anything. With --json, results include the ids of whatever was sent or created.
Quick start
You need uv (or pipx) and Python 3.11+.
For the latest unreleased changes: uv tool install git+https://github.com/dremok/gmail-agent.
Then set it up once (about 5 minutes, guided):
Then connect your agent. In Claude Code: /plugin install gmail-agent --marketplace dremok/gmail-agent. For Codex, Gemini CLI, VS Code, Cursor and Claude Desktop, see MCP server.
How it compares
Checked against each project's source and docs in October 2026. Corrections are welcome as issues.
| | gmail-agent | Claude's Gmail connector | google_workspace_mcp | GongRzhe Gmail-MCP-Server |
|---|---|---|---|---|
| Setup | Your own OAuth client; gmail-agent setup guides you (about 5 minutes) | One click | Your own OAuth client, by hand | Your own OAuth client, by hand |
| Runs as | CLI and stdio MCP, on your machine | Hosted (web, desktop, mobile) | stdio or HTTP, multi-user | stdio MCP |
| Save attachments to disk | Yes, never overwrites | No | Yes, to its own folder, deleted after an hour | Yes, overwrites files with the same name |
| Every attachment matching a search | Yes | No | No | No |
| Text of PDF attachments | Yes | No | No | No |
| Forward with original attachments | Yes | Not documented | Yes | No forward |
| Drafts | Create, update, send, delete | Yes | Create only | Create only |
| Dry run of every write, with the MIME message | Yes | No, asks before each write instead | No | No |
| Read-only mode | Yes | No, the grant includes sending | Yes | No |
| Tool list follows the granted scope | Yes | No | From server flags | No |
| Permanent delete | Only with --allow-delete and a full login | Not offered | Not offered | Offered without a guard |
| Drive, Calendar, Docs | No, Gmail only | Separate connectors | Yes | No |
| Maintained | Yes | Yes | Yes | Archived in 2025 |
Use something else if:
- **You want no setup, or use Claude on the web or your phone.** The built-in connector is one click away.
- **You need Drive, Calendar and Docs in the same server, or one server for a team over HTTP.** google_workspace_mcp covers all of Workspace.
- **You need Gmail filters, sending from an alias, your Gmail signature or inline images in outgoing mail.** gmail-agent does none of these yet.