send_draft
Send a saved draft email from Gmail by specifying its ID to complete and deliver the message.
Instructions
Send an existing draft
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the draft to send |
Implementation Reference
- src/index.ts:357-372 (registration)Registration of the send_draft tool, including name, description, input schema, and inline handler function.server.tool("send_draft", "Send an existing draft", { id: z.string().describe("The ID of the draft to send") }, async (params) => { return handleTool(config, async (gmail: gmail_v1.Gmail) => { try { const { data } = await gmail.users.drafts.send({ userId: 'me', requestBody: { id: params.id } }) return formatResponse(data) } catch (error) { return formatResponse({ error: 'Error sending draft, are you sure you have at least one recipient?' }) } }) } )
- src/index.ts:362-371 (handler)The handler function for the send_draft tool. It uses the shared handleTool helper to authenticate, create a Gmail client, and call the Gmail API to send the specified draft by ID.async (params) => { return handleTool(config, async (gmail: gmail_v1.Gmail) => { try { const { data } = await gmail.users.drafts.send({ userId: 'me', requestBody: { id: params.id } }) return formatResponse(data) } catch (error) { return formatResponse({ error: 'Error sending draft, are you sure you have at least one recipient?' }) } }) }
- src/index.ts:360-360 (schema)Zod input schema defining the required 'id' parameter for the draft to send.id: z.string().describe("The ID of the draft to send")
- src/index.ts:50-66 (helper)Shared helper function used by send_draft (and other tools) to handle OAuth2 authentication, credential validation, Gmail client creation, and API call execution.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) { return `Tool execution failed: ${error.message}` } }
- src/index.ts:48-48 (helper)Shared helper function to format tool responses as MCP content blocks with JSON-stringified data.const formatResponse = (response: any) => ({ content: [{ type: "text", text: JSON.stringify(response) }] })