Skip to main content
Glama

google_gmail_get_email

Retrieve detailed information about a specific email using its unique message ID. Specify the output format (full, metadata, minimal, raw) for tailored results within the Google MCP server.

Instructions

Get detailed information about a specific email

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoFormat to return the email in (full, metadata, minimal, raw)
messageIdYesID of the email to retrieve

Implementation Reference

  • The main handler function for the google_gmail_get_email tool. Validates input using isGetEmailArgs and delegates to GoogleGmail.getEmail method.
    export async function handleGmailGetEmail(
      args: any,
      googleGmailInstance: GoogleGmail
    ) {
      if (!isGetEmailArgs(args)) {
        throw new Error("Invalid arguments for google_gmail_get_email");
      }
      const { messageId, format } = args;
      const result = await googleGmailInstance.getEmail(messageId, format);
      return {
        content: [{ type: "text", text: result }],
        isError: false,
      };
    }
  • Registration in the MCP server: switch case that dispatches tool calls to the appropriate handler function.
    case "google_gmail_get_email":
      return await gmailHandlers.handleGmailGetEmail(
        args,
        googleGmailInstance
      );
  • MCP Tool schema definition with input schema specifying required messageId and optional format.
    export const GET_EMAIL_TOOL: Tool = {
      name: "google_gmail_get_email",
      description: "Get detailed information about a specific email",
      inputSchema: {
        type: "object",
        properties: {
          messageId: {
            type: "string",
            description: "ID of the email to retrieve",
          },
          format: {
            type: "string",
            description:
              "Format to return the email in (full, metadata, minimal, raw)",
          },
        },
        required: ["messageId"],
      },
    };
  • Type guard/helper function that validates the tool arguments against the expected schema.
    export function isGetEmailArgs(args: any): args is {
      messageId: string;
      format?: string;
    } {
      return (
        args &&
        typeof args.messageId === "string" &&
        (args.format === undefined || typeof args.format === "string")
      );
    }
  • Core helper method in GoogleGmail class that implements the Gmail API call to retrieve email details, parse headers, body, attachments, and format the response text.
    async getEmail(messageId: string, format: string = "full") {
      try {
        const response = await this.gmail.users.messages.get({
          userId: "me",
          id: messageId,
          format: format,
        });
    
        const { payload, snippet, labelIds } = response.data;
        const headers = payload.headers;
    
        // Extract common headers
        const subject =
          headers.find((h: any) => h.name === "Subject")?.value || "(No subject)";
        const from = headers.find((h: any) => h.name === "From")?.value || "";
        const to = headers.find((h: any) => h.name === "To")?.value || "";
        const date = headers.find((h: any) => h.name === "Date")?.value || "";
    
        // Extract message body
        let body = "";
        if (payload.parts) {
          // Multipart message
          for (const part of payload.parts) {
            if (part.mimeType === "text/plain" && part.body.data) {
              body = Buffer.from(part.body.data, "base64").toString();
              break;
            } else if (part.mimeType === "text/html" && part.body.data) {
              body = Buffer.from(part.body.data, "base64").toString();
            }
          }
        } else if (payload.body && payload.body.data) {
          // Simple message
          body = Buffer.from(payload.body.data, "base64").toString();
        }
    
        // Get attachment information
        const attachments = await this.getEmailAttachments(messageId);
    
        // Format the result
        let result = `Subject: ${subject}\n`;
        result += `From: ${from}\n`;
        result += `To: ${to}\n`;
        result += `Date: ${date}\n`;
        result += `Labels: ${labelIds.join(", ")}\n\n`;
        result += `Snippet: ${snippet}\n\n`;
    
        if (attachments.length > 0) {
          result += `Attachments (${attachments.length}):\n`;
          attachments.forEach((att, index) => {
            result += `  ${index + 1}. ${att.filename} (${
              att.mimeType
            }, ${FileUtils.formatFileSize(att.size)})\n`;
          });
          result += `\nUse google_gmail_download_attachments to download all attachments.\n\n`;
        }
    
        result += `Body: \n${body.substring(0, 1500)}${
          body.length > 1500 ? "... (truncated)" : ""
        }`;
    
        return result;
      } catch (error) {
        throw new Error(
          `Failed to get email: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves 'detailed information' but doesn't specify what that includes (e.g., headers, body, attachments), whether it requires authentication, or if there are rate limits. For a read operation with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 without unnecessary words. Every part of the sentence earns its place by specifying the action ('Get'), the scope ('detailed information'), and the target ('a specific email').

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 the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on behavior, output format, and usage context. Without annotations or output schema, more elaboration would be helpful for a complete understanding.

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%, with clear parameter descriptions in the schema itself. The description adds no additional parameter semantics beyond what's already documented in the schema (e.g., it doesn't explain the 'format' options or 'messageId' format). 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 ('detailed information about a specific email'), making the purpose immediately understandable. It distinguishes from sibling tools like 'google_gmail_list_emails' (which lists multiple emails) and 'google_gmail_get_email_by_index' (which uses a different identifier). However, it doesn't explicitly mention the Gmail context beyond the tool name.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose 'google_gmail_get_email_by_index' instead, nor does it specify prerequisites like needing a specific email ID. The context is implied by the tool name but not elaborated in the description.

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