Skip to main content
Glama

get_draft

Retrieve a specific Gmail draft by its ID to access and edit saved email content before sending.

Instructions

Get a specific draft by ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe ID of the draft 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

  • The main handler function for the 'get_draft' tool. It calls the Gmail API to fetch the draft by ID in full format, processes the message payload (decoding body and filtering headers), and returns a formatted JSON response.
    async (params) => { return handleTool(config, async (gmail: gmail_v1.Gmail) => { const { data } = await gmail.users.drafts.get({ userId: 'me', id: params.id, format: 'full' }) if (data.message?.payload) { data.message.payload = processMessagePart( data.message.payload, params.includeBodyHtml ) } return formatResponse(data) }) }
  • Zod schema defining the input parameters for the get_draft tool: 'id' (string, required) and 'includeBodyHtml' (boolean, optional).
    { id: z.string().describe("The ID of the draft 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") },
  • src/index.ts:311-331 (registration)
    Registration of the 'get_draft' tool on the MCP server, including name, description, input schema, and handler function.
    server.tool("get_draft", "Get a specific draft by ID", { id: z.string().describe("The ID of the draft 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.drafts.get({ userId: 'me', id: params.id, format: 'full' }) if (data.message?.payload) { data.message.payload = processMessagePart( data.message.payload, params.includeBodyHtml ) } return formatResponse(data) }) } )
  • Helper function used by get_draft to recursively process message parts: decodes base64 bodies (unless HTML and not includeBodyHtml), recurses on parts, and filters headers to common ones.
    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 function to decode base64-encoded message body data to UTF-8 string, used within 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/faithk7/gmail-mcp'

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