Skip to main content
Glama

create_reply

Generate Gmail reply drafts with provided content and direct compose URLs for responding to specific email messages.

Instructions

Generate a brief, natural reply draft and provide Gmail compose URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
messageIdYesEmail message ID to reply to
replyMessageYesThe reply message content to create as a draft

Implementation Reference

  • Main handler for the 'create_reply' tool call. Validates arguments and invokes GmailService.createReply, then returns formatted response with draft preview.
    case "create_reply": { const v = validated as z.infer<typeof schemas.create_reply>; const result = await gmailService.createReply(v.messageId, v.replyMessage); return { content: [{ type: "text", text: `${result.message}\n\n**Draft Preview:**\n\n**To:** ${result.to}\n**Subject:** ${result.subject}\n\n**Message:**\n\`\`\`\n${result.replyMessage}\n\`\`\`` }] }; }
  • Zod schema defining input parameters for the create_reply tool.
    create_reply: z.object({ messageId: z.string().describe("Email message ID to reply to"), replyMessage: z.string().describe("The reply message content to create as a draft") }),
  • Core helper function implementing reply draft creation using Gmail API, including email reading, draft construction, API call, and fallback compose URL.
    async createReply(messageId: string, replyMessage: string): Promise<{message: string, to: string, subject: string, replyMessage: string}> { const email = await this.readEmail(messageId); // Create email message for draft const subject = email.subject.startsWith('Re: ') ? email.subject : `Re: ${email.subject}`; const to = email.from; const inReplyTo = email.id; const references = email.threadId; const emailContent = [ `To: ${to}`, `Subject: ${subject}`, `In-Reply-To: ${inReplyTo}`, `References: ${references}`, '', replyMessage ].join('\n'); const encodedMessage = Buffer.from(emailContent).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); try { const { data: draft } = await this.gmail.users.drafts.create({ userId: 'me', requestBody: { message: { threadId: email.threadId, raw: encodedMessage } } }); const draftUrl = `https://mail.google.com/mail/u/0/#drafts/${draft.id}`; return { message: `Reply draft created and saved to Gmail drafts.\n\n**Gmail draft URL:** ${draftUrl}`, to, subject, replyMessage }; } catch (error) { console.error('Failed to create draft:', error); // Fallback to compose URL const gmailComposeUrl = `https://mail.google.com/mail/?view=cm&fs=1&to=${encodeURIComponent(to)}&su=${encodeURIComponent(subject)}&body=${encodeURIComponent(replyMessage)}`; return { message: `Failed to create draft. Gmail compose URL: ${gmailComposeUrl}`, to, subject, replyMessage }; } }
  • src/tools.ts:50-55 (registration)
    Exports tool definitions including 'create_reply' for MCP registration, converting Zod schemas to JSON schema.
    export const getToolDefinitions = () => Object.entries(schemas).map(([name, schema]) => ({ name, description: toolDescriptions[name], inputSchema: zodToJsonSchema(schema) }));

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/muammar-yacoob/GMail-Manager-MCP'

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