Skip to main content
Glama
SymbolStar

gmail-mcp

by SymbolStar

list_emails

Retrieve Gmail inbox messages with optional search filters and result limits. Use query parameters to find specific emails.

Instructions

List Gmail inbox messages. Supports maxResults and Gmail query filters.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxResultsNoMaximum number of emails to return. Default 10, max 50.
queryNoOptional Gmail search query, applied within INBOX.

Implementation Reference

  • src/index.ts:17-34 (registration)
    Registers the 'list_emails' tool with the MCP server, defining input schema (maxResults, query) and delegating to listInboxEmails.
    server.tool(
      "list_emails",
      "List Gmail inbox messages. Supports maxResults and Gmail query filters.",
      {
        maxResults: z
          .number()
          .int()
          .min(1)
          .max(50)
          .optional()
          .describe("Maximum number of emails to return. Default 10, max 50."),
        query: z
          .string()
          .optional()
          .describe("Optional Gmail search query, applied within INBOX."),
      },
      async ({ maxResults, query }) => jsonResult(await listInboxEmails({ maxResults, query })),
    );
  • Core execution logic: calls Gmail API users.messages.list with inbox filter, then fetches metadata for each message and maps to EmailSummary objects.
    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);
        }),
      );
    }
  • Public wrapper that delegates to listEmails with inboxOnly=true.
    export async function listInboxEmails(options: {
      maxResults?: number;
      query?: string;
    }): Promise<EmailSummary[]> {
      return listEmails({ ...options, inboxOnly: true });
    }
  • EmailSummary type definition — the return shape of list_emails results.
    export type EmailSummary = {
      id: string;
      threadId?: string | null;
      snippet?: string | null;
      from?: string;
      to?: string;
      subject?: string;
      date?: string;
      labels?: string[] | null;
    };
  • Helper function that normalizes maxResults: defaults to 10, clamps between 1 and 50.
    function normalizeMaxResults(value: number | undefined): number {
      if (value === undefined || !Number.isFinite(value)) {
        return 10;
      }
    
      return Math.min(Math.max(Math.trunc(value), 1), 50);
    }
Behavior2/5

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

No annotations provided, so description must disclose behavior. Mentions it lists inbox messages and supports parameters, but no details on pagination, response format, or conditions like invalid queries. For a read operation, minimal disclosure.

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?

Two sentences, no filler. Efficiently conveys the core purpose and supported features.

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

Completeness3/5

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

For a simple tool with 2 params and no output schema, the description covers basics but lacks usage guidelines and behavioral details, leaving gaps for an AI agent to make informed decisions.

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

Parameters3/5

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

Schema coverage is 100% with clear parameter descriptions (maxResults: default, min, max; query: optional within INBOX). Description merely restates that parameters are supported, adding no new semantic meaning beyond the schema.

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

Purpose4/5

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

Clearly states 'List Gmail inbox messages' with verb and resource, distinguishing from get_email (single email) and list_labels (labels). However, does not explicitly differentiate from search_emails, which may also list emails but with different scope.

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

Usage Guidelines2/5

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

No guidance on when to use this tool vs alternatives like search_emails. Only states what it does, leaving the agent to infer usage context.

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