Skip to main content
Glama

google_gmail_get_email_by_index

Retrieve a specific email by its index from recent Gmail search results, with options to fetch it in full, metadata, minimal, or raw format.

Instructions

Get email by its index from the most recent search results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoFormat to return the email in (full, metadata, minimal, raw)
indexYesIndex of the email from search results (starting from 1)

Implementation Reference

  • The handler function that validates input arguments, retrieves the message ID by index from recent emails, fetches the email content, and returns formatted text response or error.
    export async function handleGmailGetEmailByIndex(
      args: any,
      googleGmailInstance: GoogleGmail
    ) {
      if (!isGetEmailByIndexArgs(args)) {
        throw new Error("Invalid arguments for google_gmail_get_email_by_index");
      }
      const { index, format } = args;
      try {
        const messageId = googleGmailInstance.getMessageIdByIndex(index);
        const result = await googleGmailInstance.getEmail(messageId, format);
        return {
          content: [{ type: "text", text: result }],
          isError: false,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
          isError: true,
        };
      }
    }
  • Tool schema definition including name, description, and input schema with required 'index' and optional 'format' parameters.
    export const GET_EMAIL_BY_INDEX_TOOL: Tool = {
      name: "google_gmail_get_email_by_index",
      description: "Get email by its index from the most recent search results",
      inputSchema: {
        type: "object",
        properties: {
          index: {
            type: "number",
            description: "Index of the email from search results (starting from 1)",
          },
          format: {
            type: "string",
            description:
              "Format to return the email in (full, metadata, minimal, raw)",
          },
        },
        required: ["index"],
      },
    };
  • Dispatch registration in the main server request handler switch statement that routes the tool call to the specific Gmail handler function.
    case "google_gmail_get_email_by_index":
      return await gmailHandlers.handleGmailGetEmailByIndex(
        args,
        googleGmailInstance
      );
  • Type guard function for input validation matching the tool's input schema.
    export function isGetEmailByIndexArgs(args: any): args is {
      index: number;
      format?: string;
    } {
      return (
        args &&
        typeof args.index === "number" &&
        (args.format === undefined || typeof args.format === "string")
      );
    }
  • Helper method in GoogleGmail class that retrieves the message ID from the cached recentEmails list based on the provided index.
    getMessageIdByIndex(index: number): string {
      if (index < 1 || index > this.recentEmails.length) {
        throw new Error(
          `Invalid email index: ${index}. Available range: 1-${this.recentEmails.length}`
        );
      }
      return this.recentEmails[index - 1].id;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the index-based retrieval from search results, which is useful context. However, it doesn't disclose critical behavioral traits: whether this is a read-only operation, what happens if the index is out of bounds, if it requires specific permissions, or what the return format looks like (though 'format' parameter hints at options). For a tool with no annotations, this leaves significant gaps.

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?

The description is a single, efficient sentence that front-loads the core purpose ('Get email by its index') and adds essential context ('from the most recent search results'). Every word earns its place with zero waste or redundancy.

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?

Given no annotations and no output schema, the description is incomplete for a tool that retrieves data. It mentions the index-based context but doesn't cover return values, error conditions, or behavioral constraints. However, the 100% schema coverage helps document inputs, and the purpose is clear, making it minimally adequate but with clear gaps.

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 description coverage is 100%, so the schema already documents both parameters ('index' and 'format') thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain the 'format' options like 'full' vs 'metadata'). Baseline 3 is appropriate when the schema does the heavy lifting.

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?

The description clearly states the verb 'Get' and resource 'email by its index', specifying it's from 'most recent search results'. It distinguishes from sibling 'google_gmail_get_email' (which likely retrieves by ID) by mentioning the index-based retrieval context. However, it doesn't explicitly contrast with 'google_gmail_list_emails' (which might list emails without indexing).

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?

The description implies usage context ('from the most recent search results'), suggesting this tool should be used after a search operation. However, it doesn't explicitly state when to use this versus alternatives like 'google_gmail_get_email' (likely by ID) or 'google_gmail_list_emails', nor does it mention prerequisites (e.g., needing to run a search first).

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

Related 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/vakharwalad23/google-mcp'

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