Skip to main content
Glama

create_reply

Generate a natural reply draft for any email and return a Gmail compose URL with the draft content filled in.

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

  • The core handler: async createReply() method on GmailService. It reads the original email, constructs a reply draft using Gmail API, and returns the draft/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
            };
        }
    }
  • The tool dispatch case for 'create_reply' in handleToolCall(). Validates args, calls gmailService.createReply(), and formats the response text.
    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 definition for create_reply tool inputs: messageId (string) and replyMessage (string).
    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")
    }),
  • src/tools.ts:50-55 (registration)
    Tool definition registration via getToolDefinitions() which maps schemas to tool names/descriptions, including create_reply with its description.
    export const getToolDefinitions = () => 
        Object.entries(schemas).map(([name, schema]) => ({
            name,
            description: toolDescriptions[name],
            inputSchema: zodToJsonSchema(schema)
        }));
  • Entry point: starts the MCP server which registers and handles create_reply tool calls.
    async function main() {
        // Check for command line authentication
        if (process.argv.includes('auth')) {
            try {
                await setupAuth();
                console.error('Authentication completed successfully!');
            } catch (error) {
                console.error('Authentication failed:', error instanceof Error ? error.message : error);
                process.exit(1);
            }
            process.exit(0);
        }
        
        // Start the MCP server
        await startGmailManagerServer();
    }
    
    main().catch(console.error);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must fully disclose behavior. It only states that a draft is generated and a URL provided, but fails to mention side effects (e.g., whether the draft is saved), required permissions, or error conditions. This is insufficient for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that front-loads the core action ('Generate a brief, natural reply draft') and includes the secondary output. Every word is essential, with no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the absence of an output schema, the description should explain what the tool returns beyond just mentioning a URL. It lacks details on the format of the reply draft or the URL, leaving the agent uncertain about the full return value.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage for both parameters (messageId, replyMessage). The tool description adds no additional semantic meaning beyond what the schema already provides, so a baseline of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the tool's purpose: generating a brief, natural reply draft and providing a Gmail compose URL. It clearly distinguishes itself from sibling tools like `read_email` or `apply_label` by specifying its unique output (a draft and URL).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. There is no mention of scenarios where a more detailed reply tool might be preferred, or when not to use this tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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