Skip to main content
Glama
MadLlama25

Fastmail MCP Server

by MadLlama25

create_draft

Create an email draft without sending it. Supports threading headers for replies, enabling you to compose messages in conversation context without sending them. Use to prepare drafts for later review or approval.

Instructions

Create an email draft without sending it. Supports threading headers for replies. IMPORTANT: each call creates a new draft — do not call twice for the same message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toNoRecipient email addresses (optional)
ccNoCC email addresses (optional)
bccNoBCC email addresses (optional)
fromNoSender email address (optional, defaults to account primary email)
mailboxIdNoMailbox ID to save the draft to (optional, defaults to Drafts folder)
subjectNoEmail subject (optional)
textBodyNoPlain text body (optional)
htmlBodyNoHTML body (optional)
inReplyToNoMessage-IDs to reply to (optional, for threading)
referencesNoMessage-IDs for References header (optional, for threading)
replyToNoReply-To email addresses (replies go here instead of to the sender)

Implementation Reference

  • src/index.ts:290-348 (registration)
    Tool registration for 'create_draft' in the ListToolsRequestSchema handler. Defines the tool name, description, and input schema with optional parameters: to, cc, bcc, from, mailboxId, subject, textBody, htmlBody, inReplyTo, references, replyTo.
    {
      name: 'create_draft',
      description: 'Create an email draft without sending it. Supports threading headers for replies. IMPORTANT: each call creates a new draft — do not call twice for the same message.',
      inputSchema: {
        type: 'object',
        properties: {
          to: {
            type: 'array',
            items: { type: 'string' },
            description: 'Recipient email addresses (optional)',
          },
          cc: {
            type: 'array',
            items: { type: 'string' },
            description: 'CC email addresses (optional)',
          },
          bcc: {
            type: 'array',
            items: { type: 'string' },
            description: 'BCC email addresses (optional)',
          },
          from: {
            type: 'string',
            description: 'Sender email address (optional, defaults to account primary email)',
          },
          mailboxId: {
            type: 'string',
            description: 'Mailbox ID to save the draft to (optional, defaults to Drafts folder)',
          },
          subject: {
            type: 'string',
            description: 'Email subject (optional)',
          },
          textBody: {
            type: 'string',
            description: 'Plain text body (optional)',
          },
          htmlBody: {
            type: 'string',
            description: 'HTML body (optional)',
          },
          inReplyTo: {
            type: 'array',
            items: { type: 'string' },
            description: 'Message-IDs to reply to (optional, for threading)',
          },
          references: {
            type: 'array',
            items: { type: 'string' },
            description: 'Message-IDs for References header (optional, for threading)',
          },
          replyTo: {
            type: 'array',
            items: { type: 'string' },
            description: 'Reply-To email addresses (replies go here instead of to the sender)',
          },
        },
      },
    },
  • Handler for the 'create_draft' tool in the CallToolRequestSchema. Extracts parameters, validates at least one meaningful field is provided, calls client.createDraft(), and returns a summary with the email ID.
    case 'create_draft': {
      const { to, cc, bcc, from, mailboxId, subject, textBody, htmlBody, inReplyTo, references, replyTo } = args as any;
    
      if (!to?.length && !subject && !textBody && !htmlBody) {
        throw new McpError(ErrorCode.InvalidParams, 'At least one of to, subject, textBody, or htmlBody must be provided');
      }
    
      const emailId = await client.createDraft({
        to,
        cc,
        bcc,
        from,
        mailboxId,
        subject,
        textBody,
        htmlBody,
        inReplyTo,
        references,
        replyTo,
      });
    
      const summary = [
        `Draft created successfully (Email ID: ${emailId}).`,
        subject ? `Subject: ${subject}` : null,
        to?.length ? `To: ${to.join(', ')}` : null,
        cc?.length ? `CC: ${cc.join(', ')}` : null,
      ].filter(Boolean).join(' ');
    
      return {
        content: [
          {
            type: 'text',
            text: summary,
          },
        ],
      };
    }
  • The core createDraft method on JmapClient. Resolves the from identity, locates the Drafts mailbox, constructs the JMAP Email/set request with $draft keyword, sends it, and returns the created email ID. This is the actual JMAP API call that creates the draft.
    async createDraft(email: {
      to?: string[];
      cc?: string[];
      bcc?: string[];
      subject?: string;
      textBody?: string;
      htmlBody?: string;
      from?: string;
      mailboxId?: string;
      inReplyTo?: string[];
      references?: string[];
      replyTo?: string[];
    }): Promise<string> {
      const session = await this.getSession();
    
      // Validate at least one meaningful field is present
      if (!email.to?.length && !email.subject && !email.textBody && !email.htmlBody) {
        throw new Error('At least one of to, subject, textBody, or htmlBody must be provided');
      }
    
      // Get all identities to resolve from address
      const identities = await this.getIdentities();
      if (!identities || identities.length === 0) {
        throw new Error('No sending identities found');
      }
    
      let selectedIdentity;
      if (email.from) {
        selectedIdentity = identities.find(id => matchesIdentity(id.email, email.from!));
        if (!selectedIdentity) {
          throw new Error('From address is not verified for sending. Choose one of your verified identities.');
        }
      } else {
        selectedIdentity = identities.find(id => id.mayDelete === false) || identities[0];
      }
    
      const fromEmail = email.from || selectedIdentity.email;
    
      // Resolve drafts mailbox
      let draftMailboxId: string;
      if (email.mailboxId) {
        draftMailboxId = email.mailboxId;
      } else {
        const mailboxes = await this.getMailboxes();
        const draftsMailbox = this.findMailboxByRoleOrName(mailboxes, 'drafts', 'draft');
        if (!draftsMailbox) {
          throw new Error('Could not find Drafts mailbox');
        }
        draftMailboxId = draftsMailbox.id;
      }
    
      const mailboxIds: Record<string, boolean> = {};
      mailboxIds[draftMailboxId] = true;
    
      const emailObject: any = {
        mailboxIds,
        keywords: { $draft: true },
        from: [{ email: fromEmail }],
      };
    
      if (email.to?.length) emailObject.to = email.to.map(addr => ({ email: addr }));
      if (email.cc?.length) emailObject.cc = email.cc.map(addr => ({ email: addr }));
      if (email.bcc?.length) emailObject.bcc = email.bcc.map(addr => ({ email: addr }));
      if (email.subject) emailObject.subject = email.subject;
      if (email.inReplyTo?.length) emailObject.inReplyTo = email.inReplyTo;
      if (email.references?.length) emailObject.references = email.references;
      if (email.replyTo?.length) emailObject.replyTo = email.replyTo.map(addr => ({ email: addr }));
      if (email.textBody) emailObject.textBody = [{ partId: 'text', type: 'text/plain' }];
      if (email.htmlBody) emailObject.htmlBody = [{ partId: 'html', type: 'text/html' }];
      if (email.textBody || email.htmlBody) {
        emailObject.bodyValues = {
          ...(email.textBody && { text: { value: email.textBody } }),
          ...(email.htmlBody && { html: { value: email.htmlBody } })
        };
      }
    
      const request: JmapRequest = {
        using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'],
        methodCalls: [
          ['Email/set', {
            accountId: session.accountId,
            create: { draft: emailObject }
          }, 'createDraft']
        ]
      };
    
      const response = await this.makeRequest(request);
    
      const result = this.getMethodResult(response, 0);
    
      // Propagate server-provided error details from notCreated
      if (result.notCreated?.draft) {
        const err = result.notCreated.draft;
        throw new Error(`Failed to create draft: ${err.type}${err.description ? ' - ' + err.description : ''}`);
      }
    
      // Throw if created ID is missing instead of returning silently
      const emailId = result.created?.draft?.id;
      if (!emailId) {
        throw new Error('Draft creation returned no email ID');
      }
    
      return emailId;
    }
Behavior3/5

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

No annotations are present, so the description bears the full burden. It discloses that drafts are created without sending and supports threading headers, but omits details like return values or side effects (e.g., what happens if the draft already exists).

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?

Two sentences plus an important note in bold. Front-loaded with the main purpose, no fluff.

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

Completeness4/5

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

Given 11 optional parameters and no output schema, the description provides essential context (creation behavior, threading support, duplicity warning). It could mention return value (draft ID) for completeness, but is adequate.

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?

Schema description coverage is 100%, so baseline is 3. The description adds the note about threading headers relating to 'inReplyTo' and 'references', but does not significantly enhance parameter meaning beyond the schema.

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 uses a specific verb+resource: 'Create an email draft without sending it.' It clearly distinguishes from siblings like 'send_draft' and 'edit_draft', and mentions threading support.

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

Usage Guidelines4/5

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

The description explicitly warns against calling twice for the same message, providing clear guidance on when not to use. However, it does not explicitly mention alternatives like 'edit_draft' for modifying drafts.

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/MadLlama25/fastmail-mcp'

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