google-mail
Provides read-only tools for interacting with Gmail through the Gmail API, exposed as typed client tasks, MCP tools, and FastAPI routes.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
xippios-google-mail
Typed Python client, MCP server and FastAPI routes for Gmail, part of the xippios SDK family. Names and semantics follow the upstream documentation; every response carries its metadata (source, endpoint, retrieved_at, request).
Scope
Gmail's discovery document (docs/upstream/discovery.json) gives each method an id, and the
names here are what stands in it after gmail.users.. The package wraps 20 of the 79 methods:
nine that read, getProfile, labels.list, labels.get, messages.list, messages.get,
messages.attachments.get, threads.get, drafts.list and drafts.get, and eleven that
write, drafts.create, drafts.update, drafts.send, drafts.delete, labels.create,
labels.patch, labels.delete, messages.send, messages.modify, messages.trash and
messages.untrash. The table under Status below gives the task of each.
The package leaves out these methods:
of the labels,
labels.update, a second way to the change thatupdate_labelmakes, which takes the label whole (https://github.com/xippios/sdk-google-mail/issues/22);of the messages,
messages.batchModify, which relabels many in one call (https://github.com/xippios/sdk-google-mail/issues/47), andmessages.importandmessages.insert, which put a message into the mailbox without sending it (https://github.com/xippios/sdk-google-mail/issues/48);of the threads,
threads.list,threads.modify,threads.trashandthreads.untrash(https://github.com/xippios/sdk-google-mail/issues/43);permanent deletion,
messages.delete,messages.batchDeleteandthreads.delete(https://github.com/xippios/sdk-google-mail/issues/46);the changes of a mailbox since a history id,
history.list(https://github.com/xippios/sdk-google-mail/issues/44);the 45 methods under
settings, the vacation responder, forwarding, filters, send-as aliases, delegates and the rest (https://github.com/xippios/sdk-google-mail/issues/45);push notifications,
watchandstop(https://github.com/xippios/sdk-google-mail/issues/49).
A documented choice that a caller of a task cannot make stands here with its issue:
More than 23 messages in a page of
search_messages, which reads each message it shows by a request of its own: a search shows 20 a page unless it is told otherwise, where Gmail's own default is 100 (https://github.com/xippios/sdk-google-mail/issues/26).The
format, themetadataHeadersand the partial answer (fields) of a read:get_messageandget_threadread a message whole and show thirteen of its headers (https://github.com/xippios/sdk-google-mail/issues/76), and no task returns a message as its RFC 2822 text,format=raw(https://github.com/xippios/sdk-google-mail/issues/27).The media upload that Gmail offers beside the JSON field
rawfor a message sent or a draft written, of 36,700,160 bytes at most, for a message too large forraw(https://github.com/xippios/sdk-google-mail/issues/95): the package sets no size bound of its own, and Gmail's refusal of a message too large is raised as it comes. An alias as a message's sender (https://github.com/xippios/sdk-google-mail/issues/45).The scopes of a grant:
xippios-google-mail-authasks forgmail.readonlyor forgmail.modify, and for none of the narrower scopes that the discovery document names (https://github.com/xippios/sdk-google-mail/issues/86).
userId is no such choice: a grant opens the mailbox of its own account, which the argument
account names, so the package sends me. Nor are the parameters beside fields that the
document gives every method, such as alt and quotaUser: the package reads JSON, and the
account that signs a request is the user whose quota it spends.
Related MCP server: mail-mcp
Install
uv add xippios-google-mail # client only
uv add "xippios-google-mail[mcp]" # + MCP server
uv add "xippios-google-mail[http]" # + FastAPI routerThe API takes an OAuth 2.0 bearer token, which the package renews in memory from a
refresh token per Gmail account and never writes to disk. The environment names the
operator's Desktop-app OAuth client, GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET, the
accounts, GOOGLE_ACCOUNTS (work,private), and one GOOGLE_<NAME>_REFRESH_TOKEN per
account (the test account demo is declared by GOOGLE_DEMO_REFRESH_TOKEN alone and
never listed). Every task takes the account's name first; list_accounts names the
declared ones.
A refresh token comes from the consent tool, which listens on http://127.0.0.1:<port>/,
prints the authorization URL to open in a browser signed in to the account, and prints the
refresh token once, to stdout; it stores nothing. A running server reads a new token at its
next start:
uvx --from xippios-google-mail xippios-google-mail-auth --account work # --scopes read: gmail.readonly
uvx --from xippios-google-mail xippios-google-mail-auth --account work --scopes write # gmail.modify, every read too
xippios-google-mail-auth --account work # the same, where xippios-google-mail is installed30-second example
from xippios.google.mail import tasks
tasks.list_accounts().data # ["work", "private"]
result = tasks.get_profile("work")
result.data.messages_total, result.meta.tenant, result.meta.retrieved_at
found = tasks.search_messages("work", "from:alice@example.com newer_than:7d", max_results=5)
[(row.from_, row.subject, row.date, row.label_ids) for row in found.data.messages]
found.data.next_page_token # page_token= takes it for the next page; None on the last
message = tasks.get_message("work", found.data.messages[0].id).data
message.headers, message.text, message.attachments # the decoded view; html on request
attached = tasks.get_attachment("work", message.id, message.attachments[0].attachment_id).data
attached.form, attached.text, attached.content # "pdf": its text; content: the bytes wholeq is Gmail's own search syntax, sent as given. get_message returns a decoded view of
the message: its From, To, Cc, Bcc, Date, Subject, Message-ID, In-Reply-To, References,
Reply-To, Sender, List-Id and List-Unsubscribe headers, the first plain-text part decoded, the first HTML part with include_html=True,
and its attachments' names, types and sizes, never their content. get_thread returns
the same view of each message in a thread, as text. get_attachment reads one attachment by
its attachment_id: a text file as text, a PDF as the text that pypdf extracts from its pages,
and anything else as Gmail's base64, in form, text and data, and from Python the bytes
whole in content, which no JSON answer carries.
The write tasks, in xippios.google.mail.tasks_write (re-exported from
xippios.google.mail), need an account consented with --scopes write, and each
previews unless called with confirm=True:
from xippios.google.mail import tasks_write
from xippios.google.mail.models import OutgoingAttachment
preview = tasks_write.send_message(
"work", to=["alice@example.com"], subject="Lunch on Friday", body="See you!"
)
preview.data.from_, preview.data.headers, preview.data.reads # ["gmail.users.getProfile"]
note = OutgoingAttachment(filename="note.txt", mime_type="text/plain", data="U2VlIHlvdSE=")
tasks_write.send_message(
"work", to=["alice@example.com"], subject="Lunch", body="See you!", attachments=[note]
).data.attachments # the preview names the file: note.txt, text/plain, 8 bytes
sent = tasks_write.send_message(
"work", to=["alice@example.com"], subject="Lunch on Friday", body="See you!", confirm=True
)
sent.data.id, sent.data.label_ids # upstream's answer: ["SENT"], ...The read and write tasks are listed in the status table below.
MCP
{
"mcpServers": {
"google-mail": {
"command": "uvx",
"args": ["--from", "xippios-google-mail[mcp]", "xippios-google-mail-mcp-read"],
"env": {
"GOOGLE_CLIENT_ID": "<client id>.apps.googleusercontent.com",
"GOOGLE_CLIENT_SECRET": "<client secret>",
"GOOGLE_ACCOUNTS": "work,private",
"GOOGLE_WORK_REFRESH_TOKEN": "<refresh token>",
"GOOGLE_PRIVATE_REFRESH_TOKEN": "<refresh token>"
}
}
}
}The refresh tokens come from the consent tool above, one per account; a deployment that
serves one account can pass --account work in args and declare that account alone
("GOOGLE_ACCOUNTS": "work" and its token) instead of listing several.
The read server's tools are read-only and named google_mail_<verb>_<noun>. Results are capped, at
200 rows or 64 KB unless a tool has a cap of its own, with a note on how to see the rest.
google_mail_search_messages shows at most 23 messages a call: one list request, 5 quota
units, and one request per message, 20 units each, so at most 24 requests and 465 units.
Its answer carries next_page_token, which page_token takes for the next page, and
google_mail_list_messages pages through the ids alone.
A page of the search returns whole up to 160 KB, 23 messages whose To and Cc hold some 165
addresses together; a longer page is cut by its rows, and its note says to ask again with a
smaller max_results and every other argument unchanged, since the token follows the page's
last row.
google_mail_get_thread reads a long thread in parts with start and limit: a cut
answer ends with where to resume, or says that the message at its start alone passes the
cap, which google_mail_get_message reads, and a start past the thread's last message is
refused, naming how many the thread holds.
google_mail_get_message returns a message over the cap as its first 64 KB with a note:
include_html=False leaves the HTML out, and the rest is read in a mail client.
google_mail_get_label reads one label with its message and thread counts and its colour,
which google_mail_list_labels leaves out.
google_mail_get_attachment reads one attachment that google_mail_get_message lists, by its
attachment_id: a text file as text, a PDF as its pages' text and anything else as base64,
form naming which, and over the cap its first 64 KB with a note.
The server serves every declared account, and every tool but google_mail_list_accounts
takes account. --account <name> binds the server to one account: every tool acts on it,
takes no account and refuses a call that names one, and the server stops at startup
unless that account is declared with its refresh token. --http serves streamable HTTP instead of stdio, on a loopback --host only
(127.0.0.1, localhost, ::1): the server reaches every declared mailbox and carries no
authentication, so serving it beyond loopback takes --allow-remote and a gateway in front.
The write tools run in a server of their own, xippios-google-mail-mcp-write, so a
client of the read server never sees one; it takes --account too, and core holds it to
a loopback --host over --http unless --allow-remote is passed:
{
"mcpServers": {
"google-mail-write": {
"command": "uvx",
"args": ["--from", "xippios-google-mail[mcp]", "xippios-google-mail-mcp-write"],
"env": {
"GOOGLE_CLIENT_ID": "<client id>.apps.googleusercontent.com",
"GOOGLE_CLIENT_SECRET": "<client secret>",
"GOOGLE_ACCOUNTS": "work,private",
"GOOGLE_WORK_REFRESH_TOKEN": "<refresh token>",
"GOOGLE_PRIVATE_REFRESH_TOKEN": "<refresh token>"
}
}
}
}Its refresh tokens come from xippios-google-mail-auth --scopes write; a deployment that
only reads keeps the default read grant, which cannot change a mailbox.
Eleven write tools store a draft (google_mail_create_draft), replace its message
(google_mail_update_draft), send it (google_mail_send_draft), delete it
(google_mail_delete_draft), send a message (google_mail_send_message), change a
message's labels (google_mail_modify_message), move a message to the trash
(google_mail_trash_message) and take it out again (google_mail_untrash_message), and
make, change and delete a label (google_mail_create_label, google_mail_update_label,
google_mail_delete_label). Every one returns a preview and changes nothing unless it is
called with confirm=true, and reads names what the preview read. The preview of a
message to send or to store shows the address that it goes out from, from_, which it reads
as google_mail_get_profile does, its To, Cc, Bcc, Subject, In-Reply-To and References and
the body's first 10 lines. The tools that change, trash and restore a message read it first,
as google_mail_search_messages shows one, show its sender, subject and labels and refuse an
id that names no message; google_mail_modify_message reads the mailbox's labels too and
refuses a label id that no label has. The three tools that take a draft's id read the draft
first, as google_mail_get_draft does, and refuse an id that names no draft before any
write; the read server's google_mail_list_drafts lists the drafts' ids. The tools that
change and delete a label read it first, as google_mail_get_label does, show it in the
preview and refuse an id that names no label, and google_mail_update_label changes only the
fields that it is given; the preview of google_mail_create_label shows the fields that the
call would send and reads nothing. Confirmed, a tool sends its write once and returns Gmail's
answer: the draft, or the message with its labels, or the label; google_mail_delete_draft
and google_mail_delete_label, which Gmail answers without a body, return the package's
acknowledgement, {"performed": true, "id": "<the draft's or the label's id>"}.
A message is plain text in UTF-8, with an HTML version beside it in html and files in
attachments, each a filename, a mime_type and its data in base64, which the preview
names with its type and size; the preview of google_mail_send_draft names a stored draft's
files too and says whether the draft has a plain text and an HTML part. To, Cc and Bcc hold
500 recipients together at most, more are refused before any request, and a recipient's
domain outside ASCII is sent in its IDNA form (xn--bcher-kva.example for
bücher.example). Gmail sets From to the account's address; a reply
(in_reply_to_message_id) joins the original's conversation and reads the original's
headers first, its preview too. A message taken out of the trash gets back no label that the
trash took, INBOX among them (docs/upstream/OBSERVED.md), which
google_mail_modify_message adds again. The write tools are no HTTP routes.
Google's rule on AI agents
Google's quota page for the Gmail API, as the snapshot of the documentation holds it
(docs/upstream/pages/quota.md), says:
MCP requirement enforcement starts February 1, 2027. External AI agents or similar access tools calling Google Workspace data must use Google Workspace MCP servers or
gwscli. Internal agentic use cases aren't required to use MCP and can choose to use REST APIs, MCP servers, orgwscli.
The package's two MCP servers give an agent a mailbox through the Gmail REST API, so the rule bears on an operator who runs them. The page that the quota page names for the policy's details, Usage tiers and quotas for Google Workspace APIs and MCP servers, adds that from that day an external agent that calls the REST API directly is held to the quotas of the Standard Tier, whichever tier its project chose. It grants the internal-use exception only to a project used by the users of one Google Workspace organization that share no API or MCP access directly with third-party services, and it sets a second condition: "Enrolling requires Google Workspace super administrator privileges and a Cloud project that doesn't contain an OAuth client configured for an external audience."
Neither page says whether a server that an operator runs on its own OAuth client, for its own mailboxes, is an external agent or an internal use; by that sentence, a project whose OAuth client is configured for an external audience cannot enroll in the exception either way. An operator reads both pages for its own case: the package's servers call the REST API, and nothing in the package changes on that day.
Status
Upstream operation | Task function | MCP tool | Status |
none: the declared accounts |
|
| available; names only, no request |
|
|
| available; |
|
|
| available; the label ids |
|
|
| available; one label with its message and thread counts and its colour |
|
|
| available; ids only, one page; |
|
|
| available; one page: From, To, Cc, Subject, Date, labels, time, size and snippet per message, and |
|
|
| available; the decoded view: thirteen headers, the plain text, the HTML on request, the attachments' metadata (no content) |
|
|
| available; one attachment's content: a text file's text, a PDF's text by pypdf, else Gmail's base64; the bytes whole in Python ( |
|
|
| available; each message's decoded view, text only; |
|
|
| available; ids only, one page, and |
|
|
| available; the draft's id and its message's decoded view, text only |
|
|
| available; a preview unless |
|
|
| available; without |
|
|
| available; without |
|
|
| available; without |
|
|
| available; a preview unless |
|
|
| available; without |
|
|
| available; without |
|
|
| available; without |
|
|
| available; a preview unless |
|
|
| available; only the fields given change; without |
|
|
| available; without |
Upstream terms and attribution
Data comes from Gmail (https://developers.google.com/workspace/gmail/api), on whatever terms upstream
states for it, if any; this package adds no rights to it. Documentation snapshot and its
attribution: docs/upstream/FETCHED.md.
Workflows
ci.yml runs ruff, its format check, mypy, pytest and pre-commit on Python 3.12, 3.13 and
3.14, requires a changelog entry of every pull request but Dependabot's and refuses a
fixture file over 256 KiB that a pull request adds or changes. It runs on every pull request and,
called by publish.yml, once for a release, and its job ci is the check the
organization's ruleset requires. It is handed no secret, and no variable switches it off.
publish.yml is the release train (conventions §12): on a push to main whose
pyproject.toml names a version that has no tag yet and has its section in CHANGELOG.md,
it runs ci.yml, refuses a core pinned to git, tags the merge commit, builds the package
and, once a reviewer of the environment pypi approves the run, publishes it to PyPI by
trusted publishing. Every push to main and a dispatch start it, and a push that brings no
release ends quietly. It is handed no secret: the step that tells a release is handed the
job's token as GH_TOKEN, the tag goes with the job's token and PyPI trusts the workflow
itself. Its job tag holds the one checkout of the repository that keeps its credentials,
since it pushes the tag with the job's token; every other checkout sets
persist-credentials: false (conventions §13). No variable switches it off.
live.yml runs every live test against the upstream with --tb=short --assert=plain, so
its public log holds neither a failing test's arguments nor the values an assertion compared.
It runs every night at 02:37 UTC and on demand, never on a pull request.
Its pytest step alone is handed XIPPIOS_LIVE_TESTS and, each from the secret of the same
name, GOOGLE_DEMO_REFRESH_TOKEN, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, so the checkout, setup-uv and uv sync see none.
A variable WORKFLOW_LIVE of off, the repository's over the organization's, switches it off.
conventions.yml calls the organization's review of a pull request against the documents
listed under Documents below, the check conventions / conventions, when a pull request
opens, is pushed to, reopens or is edited, and on a push to main or a dispatch the review
of the range of commits, range / range. It hands the review the organization's
secret of the model's key, by name. A variable WORKFLOW_CONVENTIONS of off, the
repository's over the organization's, switches both off.
adr-index.yml calls the organization's check of the ADR index, adr-index / adr-index,
which runs scripts/adr_index.py --check, when a pull request opens, is pushed to or
reopens. It hands over nothing, and the called workflow reads its switch itself: a variable
WORKFLOW_ADR_INDEX of off, the repository's over the organization's, skips the check.
siblings.yml runs .github/scripts/check-siblings.sh, which installs the wheel beside
every sibling on PyPI under the same provider namespace that shares its core minor and
beside the source packages it depends on, and proves that the namespace levels stay portions
(sdk-core ADR-0006, sdk-core ADR-0021). It runs on every pull request and push to main, a
check the ruleset does not require, in a workflow of its own, since ci.yml is core's file,
which publish.yml calls for a release. It hands the script the job's read-only token as
GITHUB_TOKEN, for the listing of the organization's repositories, since GitHub limits the
calls of a runner without one. A variable WORKFLOW_SIBLINGS of off, the repository's
over the organization's, switches it off.
Documents
sdk-core: docs/conventions.md — the conventions every xippios source package follows: its layout, names, results, tests and releases.
sdk-core: docs/adr.md — the index of the family's architecture decisions, which the conventions cite.
sdk-core: docs/definition-of-done.md — what a change satisfies before its pull request is opened.
sdk-core: docs/review-checklist.md — what the review of a pull request checks, in order.
sdk-google-mail: docs/adr.md — the index of this package's own decisions, generated from the records in
docs/adr/.sdk-google-mail: docs/upstream/FETCHED.md — the snapshot of the upstream documentation, the reference for names, parameters and semantics.
sdk-google-mail: docs/upstream/OBSERVED.md — what Gmail and Google's token endpoint do that no page of the documentation states, each note with its probe.
Licence
Apache-2.0. See LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Email: search, read, fetch attachments; attach files when the MCP client supports inputs.
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Your mailbox for MCP clients: search, read, draft, send, rules and notes. Sending is off by default.
Manage domains, mailboxes, inbox, campaigns and deliverability from any MCP client.
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables read-only, sanitized access to Yahoo Mail through MCP, including email summaries, search, and folder listing.-
- AlicenseNot gradedqualityBmaintenanceEnables read-only Gmail access via MCP, allowing users to list and retrieve email messages with query and pagination support.4MIT
- AlicenseNot gradedqualityBmaintenanceEnables read-only IMAP email access through MCP, including listing accounts and folders, searching messages, retrieving message bodies and attachments, and viewing threads without modifying mail state.MIT
- AlicenseNot gradedqualityBmaintenanceEnables MCP clients and AI assistants to search and read email through read-only IMAP access, including bounded message reads and explicitly selected attachment retrieval.MIT