gmail-mcp
Provides read-only access to a Gmail account, enabling search using Gmail syntax, listing recent messages by folder, category, or label, reading messages and conversations, listing and extracting text from attachments, and viewing label counts.
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 find unread emails from this week with attachments"
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
A small read-only MCP server for Gmail. It gives any MCP client (Claude Code, Claude Desktop, Codex, VS Code, Cursor, Gemini CLI, or your own agent) access to a Gmail account:
Search with Gmail's own search syntax (
from:,subject:,has:attachment,newer_than:7d, ...)List the newest messages in Inbox, Sent, a category or any label, optionally unread only or since a date
Read a message or a whole conversation, with its attachments listed
Read attachments as text: Word, Excel, PowerPoint and PDF files are converted in memory (with MarkItDown); a forwarded mail is shown like any other message
Labels with unread and total counts
Nothing is written to disk unless you ask for it. All dates and times, shown and given, are in your time zone.
It works with personal Gmail accounts and Google Workspace accounts.
Status: early, personal project. Licensed under MIT. Its sibling for Microsoft accounts is graph-mcp.
Read-only, twice over
The sign-in only grants read permission: the one scope is
gmail.readonly. Google refuses any send, draft, label change, archive or delete with this token, whatever the code does. It can't reach Drive, Calendar or anything else either.The code only reads: the Gmail client has no method except GET, and every tool is marked read-only for MCP clients. (Signing in and refreshing the token talk to Google's sign-in service, not to Gmail.)
Content of mails reaches the agent as data. The server's instructions tell agents to treat it as data, never as instructions, but as with any tool that reads untrusted text, keep that in mind when you let an agent act on what it read.
Related MCP server: Gmail MCP Server
Setup
1. Create a Google OAuth client (once, about 15 minutes)
Both ways of running it need your own OAuth client in Google Cloud, which gives you a client ID and secret. It's free, and you don't need billing. The console's names below are as of late 2026; Google renames things now and then.
At console.cloud.google.com, sign in with the Google account whose mail you want to read, and create a project (e.g.
gmail-mcp).APIs & Services → Library: find Gmail API and Enable it.
Google Auth Platform (also reached as APIs & Services → OAuth consent screen) → Get started: app name
gmail-mcp, your address as support and contact email, audience External. For a Google Workspace account you can choose Internal instead and skip step 6.Data Access → Add or remove scopes: add
.../auth/gmail.readonly(filter for "gmail.readonly"). Save.Clients → Create client: application type Desktop app, any name. Copy the client ID and client secret. For a desktop app, Google doesn't treat the secret as confidential (it's in every installed copy of such apps), but keep it out of public places anyway.
Audience → Publish app, to move it from Testing to In production. While an app is in Testing, Google expires its sign-ins after 7 days, so you'd have to sign in every week. Publishing doesn't make it public, and Google doesn't review it unless you ask: it stays an unverified app that only you use. When you sign in, Google warns "Google hasn't verified this app": that's you, so choose Advanced → Go to gmail-mcp.
If you'd rather stay in Testing: add your address under Audience → Test users, and expect to sign in again every 7 days. (
gmail-mcp statusand the tools tell you when it has lapsed.)
2. Choose how to run it
A. On this machine | B. In Docker | |
For | Agents on the same computer | A home server that agents on several machines use |
Agents talk to it over | stdio (each agent starts | HTTP with a Bearer token |
The sign-in lives in | Your OS keychain | A Docker volume |
Steps | A1–A3 below | B1–B5 below |
You can use both; each keeps its own sign-in.
Option A: on this machine
A1. Install with uv, as a command on your PATH:
uv tool install git+https://github.com/cart1984/gmail-mcpOr from a local checkout (edits take effect right away): uv tool install --editable ~/projects/gmail-mcp.
A2. Sign in (once per machine):
GMAIL_MCP_CLIENT_ID=<client id> GMAIL_MCP_CLIENT_SECRET=<client secret> gmail-mcp loginYour browser opens Google's sign-in page. Choose the account, allow reading your mail (tick the box if Google shows one), and the command finishes by itself: Google sends the answer back to http://localhost on a free port. If no browser opens, open the URL it prints.
gmail-mcp status shows who is signed in. If the sign-in stops working (you removed the app at myaccount.google.com/connections, changed your password, or the app is still in Testing), tools answer with "run gmail-mcp login". All agents on the machine share this one sign-in.
A3. Add it to your agents. Every client starts the same command, gmail-mcp, with the client ID and secret set.
Claude Code:
claude mcp add --scope user gmail -e GMAIL_MCP_CLIENT_ID=<id> -e GMAIL_MCP_CLIENT_SECRET=<secret> -- gmail-mcpClaude Desktop, Cursor, Gemini CLI (claude_desktop_config.json, ~/.cursor/mcp.json, ~/.gemini/settings.json):
{
"mcpServers": {
"gmail": {
"command": "gmail-mcp",
"env": { "GMAIL_MCP_CLIENT_ID": "<id>", "GMAIL_MCP_CLIENT_SECRET": "<secret>" }
}
}
}GUI apps on macOS may not see your shell's PATH; if the server doesn't start, use the full path from which gmail-mcp (usually ~/.local/bin/gmail-mcp).
VS Code (user or workspace mcp.json):
{
"servers": {
"gmail": {
"type": "stdio",
"command": "gmail-mcp",
"env": { "GMAIL_MCP_CLIENT_ID": "<id>", "GMAIL_MCP_CLIENT_SECRET": "<secret>" }
}
}
}Codex (~/.codex/config.toml):
[mcp_servers.gmail]
command = "gmail-mcp"
env = { GMAIL_MCP_CLIENT_ID = "<id>", GMAIL_MCP_CLIENT_SECRET = "<secret>" }Option B: in Docker
compose.yaml runs the HTTP server in a locked-down container: read-only file system, no capabilities, a non-root user, the port on one address only, and the sign-in in a named volume. Attachments are converted in memory and never kept.
B1. Get the code and write the settings on the machine that will run it:
git clone https://github.com/cart1984/gmail-mcp && cd gmail-mcp
echo "GMAIL_MCP_CLIENT_ID=<client id>" > .env
echo "GMAIL_MCP_CLIENT_SECRET=<client secret>" >> .env
echo "GMAIL_MCP_TOKEN=$(openssl rand -hex 32)" >> .env
echo "GMAIL_MCP_BIND=<this machine's address on your clients' network>" >> .env
echo "TZ=America/New_York" >> .env # your time zone
chmod 600 .envGMAIL_MCP_TOKEN is what agents must send; anyone who has it can read your mail. GMAIL_MCP_BIND is required: the port is published on that address only, never on every interface.
B2. Build (the image is about 1 GB, mostly the document converters' dependencies):
docker compose buildB3. Sign in (once). The container listens for Google's answer on port 8780, published on this machine's loopback only:
docker compose run --rm -p 127.0.0.1:8780:8780 gmail login --no-browser --port 8780 --bind 0.0.0.0It prints a URL. Open it in a browser on the same machine, sign in, and the command finishes by itself. On a server without a browser, forward the port from your computer first, and open the URL there:
ssh -L 8780:127.0.0.1:8780 <server> # in a second terminal on your computer, while the login runsOr sign in on a computer that has gmail-mcp installed (step A1), into a file instead of the keychain, and copy that file into the volume:
# on the computer with the browser:
GMAIL_MCP_CLIENT_ID=<id> GMAIL_MCP_CLIENT_SECRET=<secret> GMAIL_MCP_TOKEN_CACHE=file gmail-mcp login
# writes ~/.config/gmail-mcp/token-cache.json; put it into the gmail-mcp folder on the server, then there:
docker compose run --rm -T --entrypoint sh gmail -c 'umask 077 && cat > /data/token-cache.json' < token-cache.json
rm token-cache.json # and the one in ~/.config/gmail-mcp/ on the other computer: keep no copies aroundB4. Start it and check:
docker compose up -d
docker compose run --rm gmail status # "Signed in as ...; token is valid."
docker compose ps # "healthy" once it's upThe container counts as healthy only while it has a sign-in (/healthz answers 503 "not signed in" otherwise), so docker compose ps also tells you when the sign-in is gone.
B5. Add it to your agents. They connect to http://<GMAIL_MCP_BIND>:8767/mcp with the header Authorization: Bearer <GMAIL_MCP_TOKEN>. Claude Code:
claude mcp add --scope user --transport http gmail http://<host>:8767/mcp --header "Authorization: Bearer <token>"Other clients that support remote (Streamable HTTP) servers take the same URL and header in their config; for a client that only speaks stdio, bridge it with mcp-remote.
This is plain HTTP: the token and everything you read travel unencrypted. That's fine on a network you trust and inside a VPN. Anywhere else, put a TLS proxy in front (Caddy, for example) or don't expose it.
Updating: git pull && docker compose up -d --build. The sign-in stays in the volume.
Other ways to run
HTTP without Docker, e.g. on a server without containers:
GMAIL_MCP_CLIENT_ID=<id> GMAIL_MCP_CLIENT_SECRET=<secret> GMAIL_MCP_TOKEN=$(openssl rand -hex 32) \
gmail-mcp serve --transport http --host <address>The same URL, header and plain-HTTP warning apply as in B5. A token is required except on loopback, where --no-auth is allowed.
The sign-in as a file. Where there's no keychain (containers, headless Linux), the sign-in is kept in a file, ~/.config/gmail-mcp/token-cache.json, mode 0600. It holds the refresh token and your address, isn't encrypted, and with the client secret it's enough to read your mail: keep it (or the Docker volume) where only you can. Access tokens are never saved; they're refreshed in memory about once an hour.
Signing out. gmail-mcp logout deletes the sign-in here. To revoke it at Google as well, remove gmail-mcp at myaccount.google.com/connections.
Keeping the originals. By default, attachments are only converted to text. Set GMAIL_MCP_DOWNLOADS to a folder to also keep the originals there, for an agent on the same machine that needs the file itself (for example a long document whose text was cut off).
Settings
All settings are environment variables:
Variable | Default | What |
| (required) | Client ID of your Google OAuth client (Desktop app) |
| (required) | Its client secret |
|
|
|
|
| The sign-in file, when a file is used |
| (none: keep nothing) | Folder to keep the originals of attachments in |
|
| IANA time zone (e.g. |
| (none) | Bearer token HTTP clients must send; at least 32 characters |
|
| HTTP port |
| (required in Docker) | The address |
Tools
Tool | What it does |
| Which account is signed in, with message and thread counts |
| Labels with unread and total counts: system labels first, then categories and your own |
| Search all mail, Gmail syntax ( |
| Newest messages with a label (by name or id), optionally unread only or since a date |
| One message in full: headers, labels, text, numbered attachments |
| A whole conversation, oldest message first. Replies leave out the earlier mails they quote, since those are shown above them |
| One attachment as text, by its number |
How a message is read: from its original bytes (Gmail's raw format), with Python's email package. The body is the plain-text version if there is one, else the HTML version as Markdown; text that sits between inline pictures is kept. Everything with a file name is an attachment, including inline pictures and calendar invites. A forwarded mail attached whole counts as one attachment.
Dates in Gmail's own search operators (after:2026/11/01) are read by Gmail as Pacific time. mail_list's since is in your time zone, to the minute.
Development
uv sync
uv run pytest
uv run ruff check && uv run ruff format --check
uv run pyrightTests run against a fake Gmail and never touch the network; the fake fails any test whose code sends anything but GET. Message reading is tested against real-world mail shapes in tests/mails/. CI also builds the Docker image, starts the compose stack and checks its lockdown.
Available Tools
7 toolsmail_attachmentARead-only
Read one attachment as text, by its number in mail_get (PDF, Word, Excel, PowerPoint and more are converted; a forwarded mail is shown like mail_get shows a message).
Inputs: attachment (required), message_id (required). Returns: result
mail_getBRead-only
Read one message in full: headers, labels, text, and its numbered attachments.
Inputs: message_id (required). Returns: result
mail_labelsARead-only
List labels (Inbox, Sent, categories, your own labels) with unread and total message counts.
Inputs: no named parameters. Returns: result
mail_listARead-only
List the newest messages with a label: INBOX (default), SENT, DRAFT, STARRED, SPAM, TRASH, a category
such as CATEGORY_PROMOTIONS, or one of your labels by name or id (see mail_labels). since is an ISO date
or date-time such as 2026-11-01, in the server's time zone unless it has an offset.
Inputs: top, label, since, unread_only. Returns: result
mail_searchARead-only
Search mail with Gmail search syntax, e.g. invoice, from:amazon, subject:"tax return",
has:attachment dentist, newer_than:30d, label:receipts, in:anywhere (spam and trash too).
Newest first.
Inputs: query (required), top. Returns: result
mail_threadARead-only
Read a whole conversation, oldest message first (thread id from mail_search, mail_list or mail_get). Replies leave out the earlier mails they quote, since those are shown above them; mail_get shows a message in full.
Inputs: thread_id (required). Returns: result
whoamiARead-only
Show which Gmail account is signed in.
Inputs: no named parameters. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool targets a distinct retrieval unit (account, label list, search, message list, single message, thread, attachment), and the descriptions explicitly contrast the confusable pairs (mail_get vs mail_thread vs mail_attachment). The only mild overlap is mail_list vs mail_search, both returning message summaries, but label-scoped listing versus query syntax distinguishes them adequately.
Six of seven tools follow a predictable mail_<noun> pattern (mail_list, mail_get, mail_search, mail_thread, mail_labels, mail_attachment) with consistent snake_case. whoami is a conventional outlier but does not break readability.
Seven tools is well-scoped for a Gmail client: one entry per retrieval unit with no redundant wrappers. Each tool earns its place and there is no filler.
The read path is thorough — account info, labels, search, listing, message, thread, and attachment extraction all covered with no dead ends. However the surface is entirely read-only: no send, reply, draft creation, label modification, archive, or delete, which is a notable gap for an email server.
Maintenance
Related MCP Connectors
A MCP server for Gmail that lets you search, read, and draft emails and replies.
Email: search, read, fetch attachments; attach files when the MCP client supports inputs.
Hosted email MCP for your own Gmail, Outlook.com, Microsoft 365, iCloud or IMAP inbox: read, search, draft, reply in thread, forward and file mail. It moves or flags up to 500 messages in one call, and a send leaves exactly one copy in Sent. A calendar is a separate connection, and connecting one adds diary and scheduling tools.
Permissioned access to Gmail, Drive and Calendar via the user's own Google account
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables interaction with Gmail through MCP-compatible clients to list, read, search, and send emails. It supports advanced features such as managing labels, handling threaded replies, and utilizing Gmail's native search syntax.2MIT
- AlicenseNot gradedqualityDmaintenanceProvides read-only access to Gmail, enabling email search, unread listing, message and thread retrieval, and draft reply preparation without sending.ISC
- AlicenseBqualityBmaintenanceEnables MCP clients to read, search, send, reply, and organize Gmail messages across multiple accounts via OAuth, with real MIME attachments and live signatures.23Apache 2.0
- AlicenseNot gradedqualityBmaintenanceEnables read-only Gmail access via MCP, allowing users to list and retrieve email messages with query and pagination support.4MIT