Skip to main content
Glama
google-mail

google-mail

by xippios

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:

A documented choice that a caller of a task cannot make stands here with its issue:

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 router

The 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 installed

30-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 whole

q 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, or gwscli.

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

list_accounts

google_mail_list_accounts

available; names only, no request

GET gmail/v1/users/{userId}/profile (users.getProfile)

get_profile(account)

google_mail_get_profile

available; userId me, the account's own

GET gmail/v1/users/{userId}/labels (users.labels.list)

list_labels(account)

google_mail_list_labels

available; the label ids label_ids takes

GET gmail/v1/users/{userId}/labels/{id} (users.labels.get)

get_label(account, id)

google_mail_get_label

available; one label with its message and thread counts and its colour

GET gmail/v1/users/{userId}/messages (users.messages.list)

list_messages(account, *, q=None, label_ids=None, max_results=None, page_token=None, include_spam_trash=False)

google_mail_list_messages

available; ids only, one page; q in Gmail's search syntax, verbatim; result_size_estimate upstream's estimate, meta.total None

users.messages.list, then GET gmail/v1/users/{userId}/messages/{id} (users.messages.get, format=metadata) per id

search_messages(account, q, *, label_ids=None, max_results=20, page_token=None, include_spam_trash=False)

google_mail_search_messages

available; one page: From, To, Cc, Subject, Date, labels, time, size and snippet per message, and next_page_token; max_results from 1 to 23 (5 quota units for the list, 20 a message)

GET gmail/v1/users/{userId}/messages/{id} (users.messages.get, format=full)

get_message(account, id, *, include_html=False)

google_mail_get_message

available; the decoded view: thirteen headers, the plain text, the HTML on request, the attachments' metadata (no content)

GET gmail/v1/users/{userId}/messages/{messageId}/attachments/{id} (users.messages.attachments.get)

get_attachment(account, message_id, id)

google_mail_get_attachment

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 (content)

GET gmail/v1/users/{userId}/threads/{id} (users.threads.get, format=full)

get_thread(account, id, *, start=0, limit=None)

google_mail_get_thread

available; each message's decoded view, text only; start and limit read a long thread in parts, a start past its end refused

GET gmail/v1/users/{userId}/drafts (users.drafts.list)

list_drafts(account, *, q=None, max_results=None, page_token=None, include_spam_trash=False)

google_mail_list_drafts

available; ids only, one page, and next_page_token; q in Gmail's search syntax, verbatim

GET gmail/v1/users/{userId}/drafts/{id} (users.drafts.get, format=full)

get_draft(account, id)

google_mail_get_draft

available; the draft's id and its message's decoded view, text only

POST gmail/v1/users/{userId}/drafts (users.drafts.create)

create_draft(account, *, to, subject, body, cc=None, bcc=None, in_reply_to_message_id=None, html=None, attachments=None, confirm=False)

google_mail_create_draft (write server)

available; a preview unless confirm=True, which reads the account's address (users.getProfile); an HTML part and attachments on request, 500 recipients at most; a reply reads the original's headers (users.messages.get, format=metadata)

PUT gmail/v1/users/{userId}/drafts/{id} (users.drafts.update)

update_draft(account, id, *, to, subject, body, cc=None, bcc=None, in_reply_to_message_id=None, html=None, attachments=None, confirm=False)

google_mail_update_draft (write server)

available; without confirm=True a preview that reads the draft (users.drafts.get) and the account's address (users.getProfile) and refuses an unknown id; an HTML part and attachments on request; a reply reads the original's headers

POST gmail/v1/users/{userId}/drafts/send (users.drafts.send)

send_draft(account, id, *, confirm=False)

google_mail_send_draft (write server)

available; without confirm=True a preview that reads the draft (users.drafts.get), shows its headers, first lines and attachments and refuses an unknown id

DELETE gmail/v1/users/{userId}/drafts/{id} (users.drafts.delete)

delete_draft(account, id, *, confirm=False)

google_mail_delete_draft (write server)

available; without confirm=True a preview that reads the draft (users.drafts.get) and refuses an unknown id; deleted permanently, not trashed

POST gmail/v1/users/{userId}/messages/send (users.messages.send)

send_message(account, *, to, subject, body, cc=None, bcc=None, in_reply_to_message_id=None, html=None, attachments=None, confirm=False)

google_mail_send_message (write server)

available; a preview unless confirm=True, which reads the account's address (users.getProfile); plain text in UTF-8, an HTML part and attachments on request, 500 recipients at most, From set by Gmail

POST gmail/v1/users/{userId}/messages/{id}/modify (users.messages.modify)

modify_message(account, id, *, add_label_ids=None, remove_label_ids=None, confirm=False)

google_mail_modify_message (write server)

available; without confirm=True a preview that reads the message (users.messages.get, format=metadata) and the labels (users.labels.list) and refuses an unknown id or label id; label ids only, 100 each at most

POST gmail/v1/users/{userId}/messages/{id}/trash (users.messages.trash)

trash_message(account, id, *, confirm=False)

google_mail_trash_message (write server)

available; without confirm=True a preview that reads the message (users.messages.get, format=metadata) and refuses an unknown id; untrash_message undoes it

POST gmail/v1/users/{userId}/messages/{id}/untrash (users.messages.untrash)

untrash_message(account, id, *, confirm=False)

google_mail_untrash_message (write server)

available; without confirm=True a preview that reads the message (users.messages.get, format=metadata) and refuses an unknown id; a message in the trash, which search_messages finds with include_spam_trash=True; no label that the trash took comes back

POST gmail/v1/users/{userId}/labels (users.labels.create)

create_label(account, *, name, message_list_visibility=None, label_list_visibility=None, color=None, confirm=False)

google_mail_create_label (write server)

available; a preview unless confirm=True, which reads nothing

PATCH gmail/v1/users/{userId}/labels/{id} (users.labels.patch)

update_label(account, id, *, name=None, message_list_visibility=None, label_list_visibility=None, color=None, confirm=False)

google_mail_update_label (write server)

available; only the fields given change; without confirm=True a preview that reads the label (users.labels.get) and refuses an unknown id

DELETE gmail/v1/users/{userId}/labels/{id} (users.labels.delete)

delete_label(account, id, *, confirm=False)

google_mail_delete_label (write server)

available; without confirm=True a preview that reads the label (users.labels.get) and refuses an unknown id; deleted permanently and removed from every message

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…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables read-only Gmail access via MCP, allowing users to list and retrieve email messages with query and pagination support.
      4
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables 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
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables 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