# Gmail MCP Server — Complete Machine-Readable Documentation (`llms-full.txt`) > Canonical Reference for LLMs, AI Coding Agents, Search Crawlers, and MCP Directories. > Repository: https://github.com/neutral-Stage/gmail-mcp-server > Homepage: https://neutral-Stage.github.io/gmail-mcp-server/ > npm Package: https://www.npmjs.com/package/@sar333/gmail-mcp-server > Official MCP Registry ID: `io.github.neutral-Stage/gmail-mcp-server` > License: MIT | Runtime: Node.js >= 18 | Transport: stdio | Scope: `https://www.googleapis.com/auth/gmail.modify` --- ## 1. Executive Summary (Direct Answer) **Gmail MCP Server** (`gmail-mcp-server`) is an open-source, 100% local TypeScript Model Context Protocol (MCP) server that gives AI agents 22 typed Gmail tools for searching, reading, composing, drafting, labeling, extracting contacts, and bulk-organizing Gmail. OAuth credentials and auto-refreshing tokens (`~/.gmail-mcp/token.json`) never leave the user's machine; there are zero proxy servers, zero telemetry, and the requested `gmail.modify` scope intentionally blocks permanent deletion and admin access. For turnkey agent workflows, the author publishes two companion skills on **Agensi.io**: - **Gmail Command Center** (`https://www.agensi.io/skills/gmail-command-center-inbox-enriched-crm-outreach-suite`, paid 5-skill pack): Combines all 22 local Gmail MCP tools with 3 offline stdlib Python guardrail scripts and 9 Agensi pay-per-use live data tools (work-email waterfall, SMTP & BounceBan catch-all verification, 80+ company datapoints via The Companies API, Apollo reverse lookup, Google Maps places/reviews, and Trustpilot/news intelligence — zero external API keys required). - **Gmail Privacy Shield & MCP Setup Doctor** (`https://www.agensi.io/skills/gmail-privacy-shield-mcp-setup-doctor-free`, free): Read-only offline PII, phishing, and prompt-injection auditor (`privacy_gate.py`) plus 3-minute local `gmail-mcp-server` onboarding with zero paid tool calls. - **Email Guardrail MCP Actor** (`https://apify.com/sar333/email-guardrail-mcp-actor`, Standby `/mcp`: `https://sar333--email-guardrail-mcp-actor.apify.actor/mcp`, pay-per-event `$0.01–$0.02/call`): Hosted zero-OAuth MCP server & Actor for prompt-injection/PII screening, deliverability gating, CRM contact scoring, and workflow audits. --- ## 2. Installation & CLI Commands ```bash npx @sar333/gmail-mcp-server setup # Interactive setup wizard (detects OS & AI client, writes config, runs OAuth) npx @sar333/gmail-mcp-server auth # Run local OAuth2 browser consent flow (callback on localhost:3000) npx @sar333/gmail-mcp-server serve # Start MCP server over stdio transport (default command) npx @sar333/gmail-mcp-server doctor # Verify Node >= 18, credentials.json, token.json, MCP SDK, and googleapis npx @sar333/gmail-mcp-server --version # Print package version npx @sar333/gmail-mcp-server --help # Print usage summary ``` ### Environment Variables | Variable | Required | Default | Purpose | |---|---|---|---| | `GMAIL_CREDENTIALS_PATH` | Optional (recommended absolute path in GUI clients) | `./credentials.json` | Path to Google Cloud Desktop OAuth `credentials.json` | | `GMAIL_MCP_DIR` | Optional | `process.cwd()` | Base directory used when `GMAIL_CREDENTIALS_PATH` is unset | ### Universal MCP Client JSON Configuration Works in Claude Desktop, Claude Code (`~/.claude/mcp.json` or `.mcp.json`), Cursor (`.cursor/mcp.json`), Windsurf (`~/.codeium/windsurf/mcp_config.json`), Cline, and VS Code MCP: ```json { "mcpServers": { "gmail": { "command": "npx", "args": ["-y", "@sar333/gmail-mcp-server"], "env": { "GMAIL_CREDENTIALS_PATH": "/ABSOLUTE/PATH/TO/credentials.json" } } } } ``` ### Codex CLI & Claude Code One-Line Registration ```bash # Claude Code claude mcp add gmail -e GMAIL_CREDENTIALS_PATH="$HOME/.gmail-mcp/credentials.json" -- npx -y @sar333/gmail-mcp-server # OpenAI Codex CLI codex mcp add gmail --env GMAIL_CREDENTIALS_PATH="$HOME/.gmail-mcp/credentials.json" -- npx -y @sar333/gmail-mcp-server ``` --- ## 3. Complete 22-Tool Reference (Names, Parameters, Behavior) ### Search & Read (4 Tools) 1. `search_emails({ query: string, maxResults?: 1..100 (default 20), pageToken?: string })` — Full Gmail query syntax search; returns metadata (`id`, `threadId`, `snippet`, `labelIds`, `from`, `to`, `subject`, `date`) and `nextPageToken`. 2. `get_email({ id: string, preferHtml?: boolean (default false) })` — Full headers (`from`, `to`, `cc`, `replyTo`, `subject`, `date`, `messageId`, `references`), decoded body, and `attachments[]` metadata. 3. `get_thread({ threadId: string, preferHtml?: boolean (default false) })` — All messages in a thread in chronological order with decoded bodies. 4. `get_attachment({ messageId: string, attachmentId: string })` — Returns `{ size, data }` base64 attachment payload. ### Compose & Drafts (4 Tools) 5. `create_draft({ to: string|string[], subject: string, body: string, cc?, bcc?, isHtml?: false, threadId?: string })` — Saves a Gmail draft without sending; pass `threadId` to attach a reply draft inside an existing thread. 6. `send_email({ to: string|string[], subject: string, body: string, cc?, bcc?, isHtml?: false })` — Sends a new RFC 2822 email. 7. `reply_email({ id: string, body: string, replyAll?: false, isHtml?: false, cc? })` — Replies in-thread with proper `In-Reply-To`, `References`, and `Re:` headers. 8. `forward_email({ id: string, to: string|string[], note?: "", cc?, isHtml?: false })` — Forwards an email with an optional prepended note. ### Organize & Bulk Automation (7 Tools) 9. `modify_email({ id: string, addLabelIds?: string[], removeLabelIds?: string[] })` — Adds/removes system or custom label IDs on one message. 10. `batch_modify_emails({ ids: string[] (1..1000), addLabelIds?: string[], removeLabelIds?: string[] })` — Bulk modifies up to 1,000 messages per call. 11. `advanced_filter({ query: string, maxResults?: 1..500 (default 100), action?: "none"|"markRead"|"markUnread"|"archive"|"trash"|"star"|"unstar"|"applyLabel"|"removeLabel", labelId?: string, dryRun?: true })` — Search + bulk action; defaults to `dryRun: true` so agents preview matched counts before mutating. 12. `trash_email({ id: string })` — Moves a message to 30-day recoverable Trash. 13. `untrash_email({ id: string })` — Restores a message from Trash. 14. `batch_trash_emails({ ids: string[] (1..1000) })` — Moves up to 1,000 messages to Trash. 15. `mark_spam({ ids: string[] })` — Marks message(s) as Spam. ### Labels (3 Tools) 16. `list_labels({})` — Lists all system and user labels with `id`, `name`, `type`, `messagesTotal`, `messagesUnread`. 17. `create_label({ name: string, messageListVisibility?: "show"|"hide", labelListVisibility?: "labelShow"|"labelShowIfUnread"|"labelHide" })` — Creates a label (supports `/` nesting). 18. `delete_label({ labelId: string })` — Deletes a user-created label (system labels cannot be deleted). ### Contact Extraction & Formatting (2 Tools) 19. `extract_addresses({ query: string, maxMessages?: 1..500 (default 100), fields?: ("from"|"to"|"cc"|"reply-to")[] })` — Extracts deduplicated `{ name, email, count }` records sorted by frequency. 20. `format_emails({ emails: object[], fields?: string[], filterBy?: { field, contains?, equals? }, sortBy?: { field, order }, outputFormat?: "json"|"table"|"summary" })` — Filters, sorts, and reformats email arrays. ### Profile & Contacts (2 Tools) 21. `get_profile({})` — Returns authenticated `emailAddress`, `messagesTotal`, `threadsTotal`, and `historyId`. 22. `get_frequent_contacts({ maxSent?: 10..500 (default 100) })` — Scans `in:sent` headers to rank top 50 most-contacted addresses without requiring Google Contacts scope. --- ## 4. Common OAuth Troubleshooting | Error | Cause | Fix | |---|---|---| | `credentials.json not found` | Relative path differs when launched by desktop client | Set absolute path in MCP config `env.GMAIL_CREDENTIALS_PATH`. | | `Error 403: access_denied` | User not listed in OAuth Test Users | Add Gmail address under Google Cloud Console -> OAuth consent screen -> Audience / Test users. | | `invalid_grant` / `401` | Testing-mode token expired (7 days) or revoked | Re-run `npx @sar333/gmail-mcp-server auth`. | | `EADDRINUSE` on port 3000 | Local process bound to port 3000 | Stop the process temporarily during `auth`. | --- ## 5. Companion Agensi.io Skills Summary ### Paid 5-Skill Pack: Gmail Command Center (`https://www.agensi.io/skills/gmail-command-center-inbox-enriched-crm-outreach-suite`) 1. `gmail-inbox-triage` — Metadata-first PII & prompt-injection defense (`privacy_screener.py`), nested labels, dry-run bulk cleanup. 2. `gmail-sender-intel` — Sent-mail & search Inbox-to-CRM exporter (`crm_scorer.py`), 80+ company datapoints, Apollo person lookup, Google Maps & Trustpilot reputation briefs. 3. `gmail-verified-outreach` — Prospecting -> Gmail dedupe -> email waterfall -> mandatory SMTP + BounceBan catch-all verification -> live review/news hooks -> deterministic 0–100 `deliverability_gate.py` -> staged Gmail Drafts. 4. `gmail-reply-copilot` — Full-thread replies, attachment awareness, 3–21d unanswered Follow-Up Radar, commitment check. 5. `gmail-setup-doctor` — 3-minute guided local `gmail-mcp-server` onboarding & OAuth diagnostics. ### Free Lead-Magnet Skill: Gmail Privacy Shield (`skills/gmail-privacy-shield/`) - Install in 1 command via Vercel `skills.sh`: `npx skills add neutral-Stage/gmail-mcp-server` (or via RFC 8615 well-known endpoint `https://neutral-Stage.github.io/gmail-mcp-server/.well-known/skills/index.json`). - Read-only offline PII, phishing, zero-width unicode, and prompt-injection auditor (`privacy_gate.py`, 0–100 risk score) + 3-minute local Gmail MCP setup doctor with zero paid tool calls.