Skip to main content
Glama
SymbolStar

gmail-mcp

by SymbolStar

search_emails

Find emails in Gmail using its search syntax. Specify a query and optionally set a maximum number of results.

Instructions

Search Gmail messages with Gmail search syntax.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesGmail search query string.
maxResultsNoMaximum number of emails to return. Default 10, max 50.

Implementation Reference

  • src/index.ts:45-59 (registration)
    Registers the 'search_emails' tool on the MCP server with zod schema for 'query' (required string) and 'maxResults' (optional int, 1-50). Handler calls searchEmails() from gmail.ts.
    server.tool(
      "search_emails",
      "Search Gmail messages with Gmail search syntax.",
      {
        query: z.string().min(1).describe("Gmail search query string."),
        maxResults: z
          .number()
          .int()
          .min(1)
          .max(50)
          .optional()
          .describe("Maximum number of emails to return. Default 10, max 50."),
      },
      async ({ query, maxResults }) => jsonResult(await searchEmails({ query, maxResults })),
    );
  • Exported async function searchEmails that accepts { maxResults, query } and delegates to the internal listEmails with inboxOnly: false (searching all folders/labels).
    export async function searchEmails(options: {
      maxResults?: number;
      query: string;
    }): Promise<EmailSummary[]> {
      return listEmails({ ...options, inboxOnly: false });
    }
  • Internal listEmails function that calls the Gmail API users.messages.list with the query and labelIds (omitted when inboxOnly=false), then fetches metadata for each message and returns summaries.
    async function listEmails(options: {
      maxResults?: number;
      query?: string;
      inboxOnly: boolean;
    }): Promise<EmailSummary[]> {
      const gmail = await getGmailClient();
      const maxResults = normalizeMaxResults(options.maxResults);
    
      const response = await gmail.users.messages.list({
        userId: USER_ID,
        maxResults,
        q: options.query || undefined,
        labelIds: options.inboxOnly ? ["INBOX"] : undefined,
      });
    
      const messages = response.data.messages ?? [];
    
      return Promise.all(
        messages.map(async (message) => {
          const detail = await gmail.users.messages.get({
            userId: USER_ID,
            id: requiredId(message.id),
            format: "metadata",
            metadataHeaders: ["From", "To", "Subject", "Date"],
            fields:
              "id,threadId,snippet,labelIds,payload(headers(name,value))",
          });
    
          return toEmailSummary(detail.data);
        }),
      );
    }
  • Zod schema for search_emails: 'query' is a required string, 'maxResults' is an optional integer between 1 and 50.
    {
      query: z.string().min(1).describe("Gmail search query string."),
      maxResults: z
        .number()
        .int()
        .min(1)
        .max(50)
        .optional()
        .describe("Maximum number of emails to return. Default 10, max 50."),
Behavior2/5

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

No annotations provided, so description bears full burden. It only mentions search syntax, but does not disclose output format, error behavior, or whether results include full messages or metadata.

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

Conciseness5/5

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

Single sentence with no redundancy. Every word adds meaning.

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

Completeness2/5

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

Lacks details on return format (e.g., fields, pagination) and how it differs from list_emails. No output schema, so description should provide more context.

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 baseline is 3. Description adds value by specifying query uses 'Gmail search syntax', which is essential for correct invocation.

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?

Description clearly states verb (Search) and resource (Gmail messages) using specific syntax. Distinguishes from sibling tools like get_email (single) and list_labels.

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

Usage Guidelines3/5

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

No explicit guidance on when to use search vs alternatives like list_emails or get_email. The description is minimally adequate but lacks contextual differentiation.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SymbolStar/gmail-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server