gmail-mcp-multi-account
by ckarandev010
README.md
# Gmail MCP (multi-account)
A small [Model Context Protocol](https://modelcontextprotocol.io) server that lets an AI assistant work with **two personal Gmail accounts**: search and read mail, create drafts (with attachments, threaded replies), list drafts, and send a draft on request.
Built for a job search: the assistant drafts tailored application emails with the right resume attached, and the human reviews and sends (or schedules) them.
## Tools
| Tool | What it does |
|---|---|
| `list_accounts` | Shows which address each account (`personal`, `second`) is signed in as |
| `search_emails` | Gmail search syntax, per account |
| `read_email` | Headers, plain-text body, attachment names |
| `create_draft` | Draft with to/cc/bcc, attachments (local paths), optional reply threading. Nothing is sent. |
| `list_drafts` | Drafts in an account |
| `send_draft` | Sends a draft. Intended only when the user explicitly asks. |
## Safety design
- **Least privilege:** scopes are `gmail.readonly` + `gmail.compose`. No delete, no label changes, no settings.
- **Drafts first:** the assistant creates drafts; the user reviews them in Gmail. Sending is a separate, explicit step.
- **Blocked domains:** mailboxes and recipients in blocked domains (for example a work domain) are refused in code, both when signing in and when building or sending a message. Configure with `GMAIL_MCP_BLOCKED_DOMAINS="@work.com"` or a git-ignored `blocked_domains.txt`.
- **Untrusted content:** email bodies are returned as data; tool descriptions tell the model never to treat them as instructions.
- **Attachment limits:** files are checked to exist and kept under ~20 MB per message.
- **Secrets stay local:** OAuth client and tokens are git-ignored.
## Setup
1. In Google Cloud Console: create a project, enable the **Gmail API**, configure the OAuth consent screen (External, Testing) and add both Gmail addresses as **test users**.
2. Create an OAuth client of type **Desktop app**, download the JSON and save it next to the script as `credentials.json`.
3. Install and sign in each account:
```bash
pip install -r requirements.txt
python gmail_mcp.py --login personal # pick the first Google account in the browser
python gmail_mcp.py --login second # pick the second one
python gmail_mcp.py --whoami
```
4. Register with Claude Code (or any MCP client):
```bash
claude mcp add gmail-jobhunt -s user -- python /path/to/gmail_mcp.py
```
While the consent screen is in Testing, Google expires refresh tokens after 7 days; re-run `--login` when that happens.
## License
MIT