gmail-mcp-local
Enables reading, writing, and modifying Gmail messages, threads, labels, and attachments.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@gmail-mcp-local show my most recent 5 emails"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
gmail-mcp-local
Your Gmail, inside Claude & Cursor — without handing your inbox to a server.
A local-first MCP server that lets AI assistants (Claude Desktop, Cursor, VS Code, …) search, read, label, draft, and send your Gmail. Your Google login (OAuth refresh token) is stored in your operating system's keychain and never leaves your machine — there is no cloud service in the middle, not even ours.
Why
🔒 Private by design. Mail and tokens stay on your device. There is no server that ever sees your email — so no operator (including us) can read it.
🧩 Cross-client. One install serves Claude Desktop, Cursor, VS Code, Windsurf.
📬 Multi-account. Connect personal + work Gmail, tag them, pick per request.
🛠️ 20 tools. The full read/write/organize Gmail toolkit (below).
Using it is two separate steps — install the connector once, then add Gmail accounts from inside the chat whenever you like. You never have to hand-edit a config file (but you can — see the appendix).
Related MCP server: multi-mail-mcp
1 · Install the connector (once)
One prerequisite for every path: a Google Desktop-app OAuth client id + secret. It's free and takes ~5 minutes — full walkthrough in SETUP_LIVE.md. (Tester builds with credentials already bundled skip this entirely.)
Option A — Claude Desktop extension (.mcpb) · easiest
Download
gmail-mcp-local-<version>.mcpbfrom Releases.Double-click it (or drag it into Claude Desktop).
Paste your Google client id + secret when prompted — Claude Desktop stores the secret in your OS keychain.
No terminal, no Node install, no config files. (Claude Desktop only; for Cursor use Option B.)
Option B — One-click installer (Claude Desktop + Cursor)
Download
gmail-mcp-local-installer.zipfrom Releases and unzip.Double-click
install.cmd(Windows) orinstall.command(macOS). Requires Node 20+.It copies the app to
~/.gmail-mcp-local/appand writes the MCP client config for you — Claude Desktop and Cursor are auto-detected, your existing config is preserved (and backed up to.bak).Unless your copy came with credentials bundled, put yours in
~/.gmail-mcp-local/config.json:
{ "clientId": "<your-id>.apps.googleusercontent.com", "clientSecret": "GOCSPX-…" }Option C — From source
git clone https://github.com/alexpekach/gmail-mcp-local.git
cd gmail-mcp-local
npm install # pulls the OS keychain helper
npm run setup # writes the Claude Desktop / Cursor config for you (same as Option B)Credentials go in ~/.gmail-mcp-local/config.json as in Option B (or env vars — see appendix).
Then fully quit and reopen your MCP client. That's the last time you touch an installer.
2 · Add Gmail accounts (anytime, in chat)
Connecting accounts happens in the conversation, not in config files:
connect_account({ ref: "work" })…your browser opens → sign in with Google → click Allow → done. The refresh token lands in your OS keychain; the account is ready immediately.
More accounts, anytime:
connect_account({ ref: "personal", tag: "home" })— connect as many as you like.Pick per request: every tool takes
account, e.g.search_threads({ account: "personal", query: "newer_than:7d has:attachment" }).See what's connected:
list_accounts(metadata only — never tokens).Remove one:
remove_account({ ref: "work" })— deletes the token from your keychain.Check granted scopes:
check_account_scopes({ account: "work" }).
What it can do (20 tools)
Group | Tools |
Accounts |
|
Read |
|
Write |
|
Organize |
|
Attaching files
create_draft and send_message take attachments by local path, so the server reads the file itself and the model never has to emit the bytes.
Off until you opt in. file_path is refused until you name the folders it may read from, in ~/.gmail-mcp-local/config.json:
{ "attachmentRoots": ["C:/Users/me/Documents", "C:/Users/me/Downloads"] }Restart the server after editing. Keep the list narrow: anything that can call send_message - a tunneled connector, or a prompt-injected email the model obeys - can attach any file inside these folders. Never list your whole home folder. The server's own ~/.gmail-mcp-local folder (OAuth client secret, connector secret) is always refused, even inside a listed folder.
create_draft({ account: "work", to: ["a@b.com"], subject: "Quote",
attachments: [{ file_path: "C:/Users/me/Documents/Quote.pdf" }] })Each item needs exactly one of
file_path(preferred) ordata_base64(small generated content only).filenameandmime_typedefault from the path.The result echoes every attachment as
{ filename, mime_type, size_bytes, sha256, source }. Comparesize_bytes/sha256with the source file;list_thread_attachmentsshows the size Gmail stored.Guardrails: the path must be absolute and its real path (symlinks and junctions followed) must sit inside a listed folder; directories are rejected; a read that returns fewer bytes than the file holds is refused rather than attached short; total attachment bytes are capped at 18 MB (Gmail's 25 MB message limit after base64), checked before reading. File I/O is time-boxed (15 s), so an offline drive cannot freeze the server. File contents are never logged.
Other settings:
"maxAttachmentBytes"in the same file. Env equivalents:GMAIL_MCP_ATTACHMENT_ROOTS(path-delimiter list:;on Windows),GMAIL_MCP_MAX_ATTACHMENT_BYTES.Known limit: the folder check and the read are separate steps, so a process that can already write inside a listed folder could swap a link in between. Node has no portable way to close that window; keep listed folders ones only you write to.
Privacy & security
Tokens in the OS keychain — macOS Keychain / Windows Credential Manager / Linux libsecret. Never written to disk in plaintext; never sent anywhere. (The
.mcpbextension keeps your client secret in the keychain too.)PKCE + loopback OAuth (RFC 8252) — a public client; the auth code is exchanged with a one-time verifier, not a network-shared secret.
Local execution — the server runs as a subprocess of your MCP client. No telemetry, no remote storage of mail or tokens.
Least scope — request only the Gmail scopes you need (read-only by default).
Restricted Gmail scopes mean your Google OAuth app must be verified (or in Testing with ≤100 users). See SETUP_LIVE.md.
How it works (30 seconds)
Your client launches gmail-mcp-local as a local stdio subprocess → it runs Google OAuth in your browser → the refresh token is saved to your OS keychain → each tool call mints a short-lived access token and calls the Gmail API directly from your machine. A single tokenFor() chokepoint keeps every tool custody-agnostic, so the same code can later swap to a team/shared backend without touching tool logic.
Optional: use it from claude.ai / web / mobile (tunnel)
The same server can speak MCP over Streamable HTTP instead of stdio, so a claude.ai custom connector can reach it — while your tokens still never leave this machine's keychain:
node bin/gmail-mcp-local.js --http # serves http://127.0.0.1:8765/<secret>/mcp
cloudflared tunnel --url http://127.0.0.1:8765Then in claude.ai: Settings → Connectors → Add custom connector → https://<tunnel-host>/<secret>/mcp.
The unguessable
<secret>path is the only credential — treat the URL like a password. It's persisted in~/.gmail-mcp-local/http-secret; rotate it by deleting that file.Your machine must be on (server + tunnel running) for the connector to respond.
Even
connect_accountworks remotely: the Google sign-in opens in the browser of the machine running the server — yours.Overrides:
GMAIL_MCP_HTTP_PORT,GMAIL_MCP_HTTP_SECRET(env or~/.gmail-mcp-local/config.json).
Appendix: manual install & what's written where
You never need to hand-edit JSON — Options A–C above write everything for you. This section exists for transparency, and for clients the auto-setup doesn't cover (VS Code, Windsurf).
What the installer / npm run setup writes — one entry, added non-destructively to %APPDATA%\Claude\claude_desktop_config.json (Claude Desktop) and ~/.cursor/mcp.json (Cursor):
{
"mcpServers": {
"gmail-local": {
"command": "node",
"args": ["<install-path>/bin/gmail-mcp-local.js"]
}
}
}For VS Code, Windsurf, or any other MCP client, add the same entry to that client's MCP config by hand.
Where credentials come from (precedence, highest first):
Env vars —
GMAIL_MCP_CLIENT_ID,GMAIL_MCP_CLIENT_SECRET(set them in the"env"block of the entry above if you prefer everything in one file)~/.gmail-mcp-local/config.json—{ "clientId": "…", "clientSecret": "…" }bundled-config.jsonshipped inside the package (tester/turnkey builds)
Other knobs: GMAIL_MCP_SCOPES (override requested scopes), GMAIL_MCP_CONFIG (alternate config path), GMAIL_MCP_METADATA (alternate accounts metadata path).
Uninstall: remove_account({ ref: "…" }) for each account → delete ~/.gmail-mcp-local → remove the gmail-local entry from your client config (a .bak backup sits next to it) → revoke at myaccount.google.com/permissions.
Develop
npm test # 122 tests - no network, no browser, no native deps
npm run build:mcpb # build the Claude Desktop extension → dist/mcpb/*.mcpbCommonJS, Node ≥ 20. Issues and PRs welcome.
Status
v0.2.0 - attachments by local path (file_path) with size/sha256 echo. v0.1.0 - local-first core (20 tools) complete and tested; verified live (read + draft) against real Gmail; ships as a one-click installer and a Claude Desktop extension (.mcpb). Roadmap: re-auth/scope-upgrade UX, signed installers, optional Pro features (shared team mailboxes via a funded backend).
License
MIT © ALEPEK Accounting and Consulting LLC.
Available Tools
20 toolscheck_account_scopesA
Report the OAuth scopes currently granted on a connected account. Returns {granted_scopes[], has_write_scope, has_modify_scope, needs_reauth}. If needs_reauth, reconnect to grant compose/modify.
Inputs: account (required).
connect_accountA
Connect a Google account on THIS device via your browser (PKCE + loopback). The refresh token is stored in your OS keychain and never leaves the machine. Returns {ref, email, tag}.
Inputs: ref (required), tag.
create_draftA
Create a Gmail draft. Returns {draft_id, message_id, thread_id}. For replies pass reply_to_message_id. Requires gmail.compose scope.
Inputs: account (required), to, cc, bcc, +6 more.
create_labelA
Create a user label. Use "/" for nesting (e.g. "Clients/Acme"). Returns {id, name}. Requires gmail.modify scope.
Inputs: account (required), name (required), label_list_visibility, message_list_visibility.
delete_labelA
Permanently delete a user label (messages keep other labels). Requires gmail.modify scope.
Inputs: account (required), label_id (required).
get_attachmentA
Fetch one Gmail attachment by message_id + attachment_id (discover both via list_thread_attachments). Returns base64 bytes + filename/mime_type/size_bytes; for text-like MIMEs also data_text. Default cap 5MB.
Inputs: account (required), message_id (required), attachment_id (required), max_size_bytes.
get_threadC
Fetch a Gmail thread by id, with each message parsed into readable headers + body text/html.
Inputs: account (required), thread_id (required), format.
label_messageC
Same as label_thread but for a single message id. Requires gmail.modify scope.
Inputs: account (required), message_id (required), add_label_ids, remove_label_ids.
label_threadA
Add/remove labels on every message in a thread. INBOX/STARRED/UNREAD/IMPORTANT/SPAM/TRASH or user label ids. Mark read: remove ["UNREAD"]. Archive: remove ["INBOX"]. Requires gmail.modify scope.
Inputs: account (required), thread_id (required), add_label_ids, remove_label_ids.
list_accountsA
List the Google accounts connected on THIS device (metadata only — never tokens). Each entry has ref, email, tag, has_refresh_token. Optionally filter by tag.
Inputs: tag.
list_labelsA
List Gmail labels (system + user) for a connected account.
Inputs: account (required).
list_thread_attachmentsA
List metadata for all attachments in a thread — filename, mime_type, size_bytes, message_id, attachment_id. No bytes (cheap). Use get_attachment to fetch one.
Inputs: account (required), thread_id (required).
remove_accountA
Disconnect a Google account: deletes its refresh token from the keychain and its metadata. Does NOT revoke at Google — do that at https://myaccount.google.com/permissions.
Inputs: ref (required).
search_threadsA
Search Gmail threads in a connected account using Gmail search syntax (e.g. "from:bob newer_than:7d has:attachment"). Returns thread ids + snippets in one API call. Use get_thread for full content.
Inputs: account (required), query, max_results, page_token.
send_draftA
Send a previously-created draft (review it in Gmail first). Returns {message_id, thread_id, label_ids}. Requires gmail.compose scope.
Inputs: account (required), draft_id (required).
send_messageA
Compose AND send in one step (no draft review). Same payload as create_draft. Returns {message_id, thread_id, label_ids}. Requires gmail.compose scope.
Inputs: account (required), to, cc, bcc, +6 more.
set_tagA
Change your tag for a connected account (e.g. switch "personal" to "work"). Metadata only — never touches the token.
Inputs: account (required), tag (required).
trash_threadA
Move a thread to TRASH (reversible via untrash_thread). Requires gmail.modify scope.
Inputs: account (required), thread_id (required).
untrash_threadA
Restore a trashed thread to its previous labels. Requires gmail.modify scope.
Inputs: account (required), thread_id (required).
update_labelB
Rename or change visibility of a user label. Requires gmail.modify scope.
Inputs: account (required), label_id (required), name, label_list_visibility, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 20 tools
Each tool targets a distinct action on a specific resource (e.g., create_draft vs send_message, get_thread vs search_threads, label_message vs label_thread). There is no functional overlap; even similar-sounding tools like send_draft and send_message have clearly differentiated purposes.
All tool names follow a consistent verb_noun pattern with lowercase and underscores (e.g., check_account_scopes, create_label, delete_label). The naming is predictable and makes it easy to infer the tool's function from its name alone.
With 20 tools, the count is slightly above the typical well-scoped range of 3-15, but each tool serves a distinct purpose in Gmail management. The size is justified by the breadth of Gmail's features, making it reasonable for a comprehensive MCP server.
The tool set covers the core Gmail lifecycle: account management, email sending (draft or direct), threading, labeling, attachments, and trash operations. Minor gaps exist (e.g., no direct individual message retrieval, but get_thread suffices), but agents can work around them.
Maintenance
Related MCP Connectors
Hosted MCP server with managed OAuth for 15+ toolkits: Google Workspace, Fitbit, Oura, Kalshi, etc.
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Your Gmail, Calendar, Drive, GitHub, Oura, wallet and confirmed profile facts in any MCP client.
MCP server for Nylas — read email, calendars, events and contacts, and send email or create events.
Related MCP Servers
- AlicenseBqualityCmaintenanceMulti-account Google MCP server providing read access to Gmail and Calendar via stdio. Supports secure authentication for personal and work accounts with OAuth and keychain token storage.4MIT
- FlicenseAqualityCmaintenanceLocal-first MCP server for agents that need to work across multiple Gmail and Microsoft 365 accounts without cloud token storage.6-
- FlicenseNot gradedqualityDmaintenanceLocal MCP server that manages Gmail OAuth 2.0 authentication (read-only) and filter setup, with planned AI-driven email digest and summarization features.-
- AlicenseNot gradedqualityDmaintenanceA local MCP server that manages multiple Gmail accounts simultaneously, allowing MCP clients to switch between accounts per request without logging out or in. It securely stores OAuth tokens in the macOS Keychain.MIT