Skip to main content
Glama
as-j

Fastmail MCP Server

by as-j

bulk_move

Idempotent

Move multiple emails to a specified mailbox in a single API call. Provide an array of email IDs and the target mailbox ID to batch file messages efficiently.

Instructions

Move multiple emails to a mailbox in one call. Use when the user wants to file a set of known email IDs into the same destination mailbox. Do not use to apply labels while preserving the current mailbox set; use bulk_add_labels.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
emailIdsYesArray of email IDs to move
targetMailboxIdYesID of target mailbox

Implementation Reference

  • Core handler: Fetches current mailboxIds for each email, builds JMAP patches that remove all existing mailbox associations and adds the target mailboxId, then calls Email/set to perform the move.
    async bulkMove(emailIds: string[], targetMailboxId: string): Promise<void> {
      const session = await this.getSession();
    
      // Fetch current mailboxIds for all emails to build proper JMAP patches
      const getRequest: JmapRequest = {
        using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'],
        methodCalls: [
          ['Email/get', {
            accountId: session.accountId,
            ids: emailIds,
            properties: ['id', 'mailboxIds']
          }, 'getEmails']
        ]
      };
      const getResponse = await this.makeRequest(getRequest);
      const emails: any[] = this.getListResult(getResponse, 0);
      const mailboxMap: Record<string, Record<string, boolean>> = {};
      emails.forEach((e: any) => { mailboxMap[e.id] = e.mailboxIds || {}; });
    
      // Build patch per email: remove all current mailboxes, add target
      const updates: Record<string, any> = {};
      emailIds.forEach(id => {
        const patch: Record<string, boolean | null> = {};
        for (const mbId of Object.keys(mailboxMap[id] || {})) {
          patch[`mailboxIds/${mbId}`] = null;
        }
        patch[`mailboxIds/${targetMailboxId}`] = true;
        updates[id] = patch;
      });
    
      const request: JmapRequest = {
        using: ['urn:ietf:params:jmap:core', 'urn:ietf:params:jmap:mail'],
        methodCalls: [
          ['Email/set', {
            accountId: session.accountId,
            update: updates
          }, 'bulkMove']
        ]
      };
    
      const response = await this.makeRequest(request);
      const result = this.getMethodResult(response, 0);
    
      if (result.notUpdated && Object.keys(result.notUpdated).length > 0) {
        throw new Error('Failed to move some emails.');
      }
    }
  • Schema definition for bulk_move: accepts emailIds (string array) and targetMailboxId (string), both required.
    writeTool(
      'bulk_move',
      'Bulk Move',
      description(
        'Move multiple emails to a mailbox in one call.',
        'Use when the user wants to file a set of known email IDs into the same destination mailbox.',
        'Do not use to apply labels while preserving the current mailbox set; use bulk_add_labels.',
      ),
      {
        type: 'object',
        properties: {
          emailIds: {
            ...stringArraySchema,
            description: 'Array of email IDs to move',
          },
          targetMailboxId: {
            type: 'string',
            description: 'ID of target mailbox',
          },
        },
        required: ['emailIds', 'targetMailboxId'],
      },
      { idempotentHint: true },
    ),
  • Registration/dispatch in the MCP server's switch statement: validates params, calls client.bulkMove(), returns success message.
    case 'bulk_move': {
      const { emailIds: rawEmailIdsBM, targetMailboxId } = args as any;
      const emailIds = normalizeStringArray(rawEmailIdsBM);
      if (emailIds.length === 0) throw new McpError(ErrorCode.InvalidParams, 'emailIds array is required and must not be empty');
      if (!targetMailboxId) throw new McpError(ErrorCode.InvalidParams, 'targetMailboxId is required');
      await client.bulkMove(emailIds, targetMailboxId);
      return { content: [{ type: 'text', text: `${emailIds.length} emails moved successfully` }] };
    }
Behavior3/5

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

Annotations already declare readOnlyHint=false, destructiveHint=false, idempotentHint=true, openWorldHint=true. Description adds nothing beyond stating the move action. No contradiction, but no extra behavioral context like effect on source mailbox or permissions.

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?

Three sentences, each essential: purpose, when to use, when not to use. Front-loaded with action. No wasted words.

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?

For a simple 2-parameter bulk operation without output schema, description covers purpose and usage. Could briefly mention that emails are moved out of their current mailbox, but overall sufficient given signal count.

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%; both 'emailIds' and 'targetMailboxId' have adequate descriptions. Description does not add any extra meaning beyond what the schema provides.

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?

Description clearly states 'Move multiple emails to a mailbox in one call' with specific verb 'Move', resource 'emails', and scope 'multiple'. It distinguishes from sibling tool 'bulk_add_labels' which preserves mailbox.

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

Usage Guidelines5/5

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

Explicitly says when to use ('user wants to file a set of known email IDs into the same destination mailbox') and when not to use ('Do not use to apply labels while preserving the current mailbox set; use bulk_add_labels'). Clearly excludes alternative use cases.

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

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