Skip to main content
Glama
ricleedo
by ricleedo

gmail-get-email

Retrieve a specific Gmail email using its message ID to access individual messages within the Google Services MCP Server.

Instructions

Get a specific email by message ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageIdYesGmail message ID

Implementation Reference

  • The handler function that retrieves a specific Gmail email by message ID using the Google Gmail API, extracts headers and body (handling multipart), truncates long body, formats as Markdown using formatEmailToMarkdown, and returns structured content.
    export async function getEmail(params: z.infer<typeof getEmailSchema>) { try { const auth = createGmailAuth(); const gmail = google.gmail({ version: "v1", auth }); const response = await gmail.users.messages.get({ userId: "me", id: params.messageId, format: "full", }); const message = response.data; const headers = message.payload?.headers || []; const getHeader = (name: string) => headers.find((h) => h.name?.toLowerCase() === name.toLowerCase()) ?.value || ""; // Extract body content let body = ""; if (message.payload?.body?.data) { body = Buffer.from(message.payload.body.data, "base64").toString(); } else if (message.payload?.parts) { // Handle multipart messages for (const part of message.payload.parts) { if (part.mimeType === "text/plain" && part.body?.data) { body = Buffer.from(part.body.data, "base64").toString(); break; } } } // Truncate body if it exceeds 30000 characters const truncatedBody = body.length > 20000 ? body.substring(0, 20000) + "\n\n[Email body truncated - content too long]" : body; const emailDetail = { id: message.id, threadId: message.threadId, from: getHeader("From"), to: getHeader("To"), cc: getHeader("Cc"), bcc: getHeader("Bcc"), subject: getHeader("Subject"), date: getHeader("Date"), body: truncatedBody, snippet: message.snippet, labelIds: message.labelIds, }; return { content: [ { type: "text" as const, text: formatEmailToMarkdown(emailDetail), }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Error getting email: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
  • Zod schema for input validation: requires 'messageId' as a string.
    export const getEmailSchema = z.object({ messageId: z.string().describe("Gmail message ID"), });
  • src/index.ts:200-207 (registration)
    MCP server registration of the 'gmail-get-email' tool, using getEmailSchema and delegating to the getEmail handler.
    server.tool( "gmail-get-email", "Get a specific email by message ID", getEmailSchema.shape, async (params) => { return await getEmail(params); } );

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/ricleedo/Google-Service-MCP'

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