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
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the draft to retrieve | |
| includeBodyHtml | No | Whether 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:317-330 (handler)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) }) }
- src/index.ts:313-316 (schema)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) }) } )
- src/index.ts:94-108 (helper)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 }
- src/index.ts:82-92 (helper)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 }