Skip to main content
Glama

Gmail Search Emails

gmail_search_emails
Read-onlyIdempotent

Find Gmail messages or whole conversations by search query, labels, sender, recipient, subject, unread status, attachments, and age, with pagination; Spam and Trash are excluded by default.

Instructions

Find Gmail messages, or with group_by_thread whole conversations, by a Gmail search query, labels (names or IDs) and helper filters (sender, recipient, subject, unread, attachments, age), ANDed together, a page at a time; Spam and Trash are left out unless include_spam_trash is true. Use gmail_get_mail_digest for a plain recent feed and gmail_check_mail_updates to poll for new mail since a saved checkpoint. Returns messages (id, thread_id, from, subject, date, snippet, unread, has_attachments, is_draft, is_sent) or threads (the same plus message_count), next_page_token, result_size_estimate and effective_query. Read bodies with gmail_read_emails or gmail_get_thread.

Tool call template

This tool declares no required parameters. Add optional parameters from the input schema as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {},
    "name": "gmail_search_emails"
  }
}

Input Schema

NameRequiredDescriptionDefault
queryNoGmail search query in the same syntax as the Gmail search box, e.g. 'from:ana@example.com newer_than:7d has:attachment'. It is wrapped in parentheses and ANDed with the helper filters; with no query, labels or filters, all mail outside Spam and Trash matches.
labelsNoOnly mail that carries every one of these labels, given by name as shown in Gmail (e.g. 'Clients/Acme') or by ID; system labels such as INBOX or UNREAD match case-insensitively. An unknown or ambiguous name fails with not_found and the candidate labels.
to_emailNoRecipient filter, added to the query as to:"<value>", e.g. 'team@example.com'.
is_unreadNoWhen true, adds is:unread so only unread messages match; false adds nothing, so read mail matches too.
from_emailNoSender filter, added to the query as from:"<value>"; an address or part of a name, e.g. 'ana@example.com'.
page_tokenNoThe next_page_token from the previous response of this same call; omit for the first page.
max_resultsNoMessages (or, with group_by_thread, conversations) per page; each hit is fetched separately, so large pages are slower.
has_attachmentNoWhen true, adds has:attachment so only messages with attachments match; false adds nothing.
group_by_threadNoReturn conversations instead of messages: threads, each summarized by its newest message plus message_count.
newer_than_daysNoOnly mail from the last N days, added to the query as newer_than:{N}d.
subject_containsNoPhrase that must appear in the subject line, added to the query as subject:"<value>".
include_spam_trashNoAlso return items in Spam and Trash; by default they are excluded.

Output Schema

NameRequiredDescriptionDefault
countNoNumber of items in this response.
threadsNoMatching conversations (only with group_by_thread): each the newest message's fields, as in messages, plus message_count.
has_moreNoWhether another page is available.
messagesNoMatching messages (absent with group_by_thread).
fetched_atNoRFC3339 time when this response was fetched.
effective_queryNoThe Gmail query actually run, helper filters included.
next_page_tokenNoOpaque token for the next page, or null.
account_timezoneNoIANA time zone of every time in this result.
result_size_estimateNoGoogle's estimate of the total number of matches.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed19 schema fields changedv2.2.0
    • changedInput schema / properties / group_by_thread / description
      Previous value: -"When true, returns conversations instead of messages: threads, each summarized by its newest message plus message_count. Default false returns individual messages."New value: +"Return conversations instead of messages: threads, each summarized by its newest message plus message_count."
    • changedInput schema / properties / max_results / description
      Previous value: -"Messages (or, with group_by_thread, conversations) per page, 1 to 500 (default 25); each hit is fetched separately, so large pages are slower."New value: +"Messages (or, with group_by_thread, conversations) per page; each hit is fetched separately, so large pages are slower."
    • addedInput schema / properties / max_results / maximum
      Added value: +500
    • addedInput schema / properties / max_results / minimum
      Added value: +1
    • changedInput schema / properties / newer_than_days / description
      Previous value: -"Only mail from the last N days, 1 to 3650, translated to Gmail's newer_than:{N}d query operator."New value: +"Only mail from the last N days, added to the query as newer_than:{N}d."
    • addedInput schema / properties / newer_than_days / maximum
      Added value: +3650
    • addedInput schema / properties / newer_than_days / minimum
      Added value: +1
    • addedOutput schema / properties / account_timezone / description
      Added value: +"IANA time zone of every time in this result."
    • addedOutput schema / properties / effective_query / description
      Added value: +"The Gmail query actually run, helper filters included."
    • addedOutput schema / properties / effective_query / type
      Added value: +[
      +  "string",
      +  "null"
      +]
    • addedOutput schema / properties / messages / description
      Added value: +"Matching messages (absent with group_by_thread)."
    • addedOutput schema / properties / messages / items / description
      Added value: +"Message summary."
    • addedOutput schema / properties / messages / items / properties
      Added value: +{
      +  "category": {
      +    "description": "First Gmail category label on the message (CATEGORY_*), or null.",
      +    "type": [
      +      "string",
      +      "null"
      +    ]
      +  },
      +  "date": {
      +    "description": "Received time in the account time zone.",
      +    "type": [
      +      "string",
      +      "null"
      +    ]
      +  },
      +  "from": {
      +    "description": "Sender name and email.",
      +    "type": "object"
      +  },
      +  "has_attachments": {
      +    "description": "Whether the message has attachments.",
      +    "type": "boolean"
      +  },
      +  "id": {
      +    "description": "Message ID for gmail_read_emails.",
      +    "type": [
      +      "string",
      +      "null"
      +    ]
      +  },
      +  "is_automated": {
      +    "description": "Whether the sender looks automated (no-reply, bulk).",
      +    "type": "boolean"
      +  },
      +  "is_draft": {
      +    "description": "Whether the message is a draft.",
      +    "type": "boolean"
      +  },
      +  "is_newsletter": {
      +    "description": "Whether the message carries a List-Unsubscribe header.",
      +    "type": "boolean"
      +  },
      +  "is_sent": {
      +    "description": "Whether the user sent it.",
      +    "type": "boolean"
      +  },
      +  "snippet": {
      +    "description": "Short plain-text preview.",
      +    "type": [
      +      "string",
      +      "null"
      +    ]
      +  },
      +  "subject": {
      +    "description": "Decoded subject.",
      +    "type": [
      +      "string",
      +      "null"
      +    ]
      +  },
      +  "thread_id": {
      +    "description": "Conversation ID for gmail_get_thread.",
      +    "type": [
      +      "string",
      +      "null"
      +    ]
      +  },
      +  "unread": {
      +    "description": "Whether the message is unread.",
      +    "type": "boolean"
      +  }
      +}
    • addedOutput schema / properties / messages / items / type
      Added value: +"object"
    • addedOutput schema / properties / result_size_estimate / description
      Added value: +"Google's estimate of the total number of matches."
    • addedOutput schema / properties / result_size_estimate / type
      Added value: +"integer"
    • addedOutput schema / properties / threads / description
      Added value: +"Matching conversations (only with group_by_thread): each the newest message's fields, as in messages, plus message_count."
    • addedOutput schema / properties / threads / items / properties
      Added value: +{
      +  "message_count": {
      +    "description": "Messages in the thread.",
      +    "type": "integer"
      +  }
      +}
    • addedOutput schema / properties / threads / items / type
      Added value: +"object"
  2. Addedv2.1.0

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare read-only, idempotent, non-destructive, open-world behavior, so the description's job is to add context and it does: Spam and Trash are excluded unless include_spam_trash, results arrive one page at a time, and each hit is fetched separately so large pages are slower. It also states the returned fields for both message and thread modes, which the annotations cannot convey.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose and scope, then alternatives, then return shape — a sensible order. The first sentence is dense with clauses and semicolons, but each clause carries real information and nothing is padding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 12-parameter, zero-required search tool this covers what an agent needs: match semantics, default exclusions, pagination via page_token, performance caveat on large pages, and the shape of both return modes. Output fields are stated even though an output schema exists, and the follow-up read tools are named.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already carries per-parameter meaning; the description adds the connective semantics the schema cannot — that query, labels and filters are wrapped and ANDed, and that labels must all be present. It also flags group_by_thread as the switch between message and thread shape, though it doesn't restate the false-means-no-op defaults that the schema already documents.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Names a specific verb+resource (find Gmail messages or whole conversations), states the matching mechanism (query, labels, helper filters ANDed together) and the pagination scope. It also draws an explicit line against gmail_get_mail_digest and gmail_check_mail_updates, so an agent can pick it without opening another schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit alternatives with the condition that selects them: digest for a plain recent feed, check-updates for polling since a checkpoint, read_emails/get_thread for bodies. Nothing is left to inference about when this is the wrong tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools