Skip to main content
Glama

get_message

Retrieve a specific Gmail message by its unique ID, with options to include or exclude parsed HTML content in the response, optimizing for data size and relevance.

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

  • src/index.ts:575-591 (registration)
    Registration of the 'get_message' MCP tool using McpServer.tool(), including description, input schema validation with Zod, and the handler function.
    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) }) }
  • Handler function for the get_message tool. Fetches the Gmail message by ID using the Gmail API with full format, processes the payload (decodes body, handles parts, filters headers), and returns formatted JSON response.
    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 get_message tool: requires 'id' (message ID string), optional 'includeBodyHtml' boolean.
    { 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") },
  • Recursive helper to process Gmail message parts: decodes base64 bodies (text/plain/html if allowed), recurses on parts, filters to essential headers.
    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 }
  • Helper to decode base64url-encoded message body data to UTF-8 string, used in processMessagePart.
    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 }

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

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