Skip to main content
Glama

get_message

Retrieve a specific Gmail message by its ID, with options to include or exclude HTML body content for efficient email management.

Instructions

Get a specific message by ID with format options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID of the message to retrieve
includeBodyHtmlNoWhether to include the parsed HTML in the return for each body, excluded by default because they can be excessively large

Implementation Reference

  • Full handler implementation for the 'get_message' MCP tool: registers the tool, defines input schema, fetches Gmail message by ID, processes payload (decodes body, filters headers), handles auth/errors via handleTool, and formats response.
    server.tool("get_message",
      "Get a specific message by ID with format options",
      {
        id: z.string().describe("The ID of the message to retrieve"),
        includeBodyHtml: z.boolean().optional().describe("Whether to include the parsed HTML in the return for each body, excluded by default because they can be excessively large")
      },
      async (params) => {
        return handleTool(config, async (gmail: gmail_v1.Gmail) => {
          const { data } = await gmail.users.messages.get({ userId: 'me', id: params.id, format: 'full' })
    
          if (data.payload) {
            data.payload = processMessagePart(data.payload, params.includeBodyHtml)
          }
    
          return formatResponse(data)
        })
      }
  • Zod input schema for the get_message tool: requires message ID, optional flag to include HTML bodies.
    {
      id: z.string().describe("The ID of the message to retrieve"),
      includeBodyHtml: z.boolean().optional().describe("Whether to include the parsed HTML in the return for each body, excluded by default because they can be excessively large")
    },
  • Shared helper function used by all tools, including get_message: creates/validates OAuth2 client, executes Gmail API call, handles auth errors specifically.
    const handleTool = async (queryConfig: Record<string, any> | undefined, apiCall: (gmail: gmail_v1.Gmail) => Promise<any>) => {
      try {
        const oauth2Client = queryConfig ? createOAuth2Client(queryConfig) : defaultOAuth2Client
        if (!oauth2Client) throw new Error('OAuth2 client could not be created, please check your credentials')
    
        const credentialsAreValid = await validateCredentials(oauth2Client)
        if (!credentialsAreValid) throw new Error('OAuth2 credentials are invalid, please re-authenticate')
    
        const gmailClient = queryConfig ? google.gmail({ version: 'v1', auth: oauth2Client }) : defaultGmailClient
        if (!gmailClient) throw new Error('Gmail client could not be created, please check your credentials')
    
        const result = await apiCall(gmailClient)
        return result
      } catch (error: any) {
        // Check for specific authentication errors
        if (
          error.message?.includes("invalid_grant") ||
          error.message?.includes("refresh_token") ||
          error.message?.includes("invalid_client") ||
          error.message?.includes("unauthorized_client") ||
          error.code === 401 ||
          error.code === 403
        ) {
          return formatResponse({
            error: `Authentication failed: ${error.message}. Please re-authenticate by running: npx @shinzolabs/gmail-mcp auth`,
          });
        }
    
        return formatResponse({ error: `Tool execution failed: ${error.message}` });
      }
    }
  • Helper to process message payload for get_message: recursively decodes base64 bodies (unless HTML and not requested), filters headers to essentials.
    const processMessagePart = (messagePart: MessagePart, includeBodyHtml = false): MessagePart => {
      if ((messagePart.mimeType !== 'text/html' || includeBodyHtml) && messagePart.body) {
        messagePart.body = decodedBody(messagePart.body)
      }
    
      if (messagePart.parts) {
        messagePart.parts = messagePart.parts.map(part => processMessagePart(part, includeBodyHtml))
      }
    
      if (messagePart.headers) {
        messagePart.headers = messagePart.headers.filter(header => RESPONSE_HEADERS_LIST.includes(header.name || ''))
      }
    
      return messagePart
    }
  • Utility helper called by processMessagePart: decodes base64url-encoded message body data to UTF-8 text.
    const decodedBody = (body: MessagePartBody) => {
      if (!body?.data) return body
    
      const decodedData = Buffer.from(body.data, 'base64').toString('utf-8')
      const decodedBody: MessagePartBody = {
        data: decodedData,
        size: body.data.length,
        attachmentId: body.attachmentId
      }
      return decodedBody
    }
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 mentions 'format options' (via includeBodyHtml), but doesn't describe other critical behaviors: whether this is a read-only operation, potential errors (e.g., invalid ID), rate limits, authentication needs, or the return format. For a retrieval tool with zero annotation coverage, this leaves significant gaps in understanding how it behaves.

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 a specific message by ID') and adds a useful qualifier ('with format options'). There is no wasted verbiage, and it's appropriately sized for a simple retrieval tool.

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?

Given the tool's moderate complexity (retrieval with optional formatting), lack of annotations, and no output schema, the description is incomplete. It doesn't explain the return value (e.g., message object structure), error conditions, or behavioral constraints like rate limiting. For a tool that might return large data (implied by includeBodyHtml), more context is needed to use it effectively.

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 fully documents both parameters (id and includeBodyHtml). The description adds minimal value beyond the schema by hinting at 'format options,' which aligns with includeBodyHtml, but doesn't provide additional syntax or usage details. 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 tool's purpose: 'Get a specific message by ID with format options.' It specifies the verb ('Get'), resource ('message'), and key constraint ('by ID'), distinguishing it from list_messages. However, it doesn't explicitly differentiate from get_draft or get_thread, which are similar retrieval operations for different resources.

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 through 'by ID' and 'format options,' suggesting this is for retrieving a known message rather than listing or searching. However, it doesn't explicitly state when to use this versus alternatives like list_messages (for bulk retrieval) or get_thread (for thread-level data), nor does it mention prerequisites like needing a valid message ID.

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/faithk7/gmail-mcp'

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