Skip to main content
Glama
Racimy

iMail-mcp

set_flags

Set message flags like read, unread, or flagged status on iCloud emails to organize and manage your inbox efficiently.

Instructions

Set flags on messages (read, unread, flagged, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionNoWhether to add or remove the flags (default: add)add
flagsYesArray of flags to set (e.g., ["\Seen", "\Flagged"])
mailboxNoMailbox name (default: INBOX)INBOX
messageIdsYesArray of message IDs to set flags on

Implementation Reference

  • Core implementation of setFlags method in iCloudMailClient class that adds or removes IMAP flags on all messages in the specified mailbox using imap.addFlags or imap.delFlags.
    async setFlags(
      _messageIds: string[],
      flags: string[],
      mailbox: string = 'INBOX',
      action: 'add' | 'remove' = 'add'
    ): Promise<{ status: string; message: string }> {
      return new Promise((resolve) => {
        this.imap.openBox(mailbox, false, (err: Error) => {
          if (err) {
            resolve({
              status: 'error',
              message: `Failed to open mailbox '${mailbox}': ${err.message}`,
            });
            return;
          }
    
          this.imap.search(['ALL'], (err: Error, results: number[]) => {
            if (err) {
              resolve({
                status: 'error',
                message: `Failed to search messages: ${err.message}`,
              });
              return;
            }
    
            if (!results || results.length === 0) {
              resolve({
                status: 'error',
                message: 'No messages found in mailbox',
              });
              return;
            }
    
            const flagOperation = action === 'add' ? 'addFlags' : 'delFlags';
    
            this.imap[flagOperation](results, flags, (err: Error) => {
              if (err) {
                resolve({
                  status: 'error',
                  message: `Failed to ${action} flags: ${err.message}`,
                });
                return;
              }
    
              resolve({
                status: 'success',
                message: `Successfully ${action === 'add' ? 'added' : 'removed'} flags [${flags.join(', ')}] ${action === 'add' ? 'to' : 'from'} ${results.length} messages in '${mailbox}'`,
              });
            });
          });
        });
      });
    }
  • MCP tool dispatch handler for 'set_flags' that extracts parameters and delegates to mailClient.setFlags method.
    case 'set_flags': {
      if (!mailClient) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          'iCloud Mail not configured. Please set ICLOUD_EMAIL and ICLOUD_APP_PASSWORD environment variables.'
        );
      }
    
      const messageIds = args?.messageIds as string[];
      const flags = args?.flags as string[];
      const mailbox = (args?.mailbox as string) || 'INBOX';
      const action = (args?.action as string) || 'add';
    
      const result = await mailClient.setFlags(
        messageIds,
        flags,
        mailbox,
        action as 'add' | 'remove'
      );
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • JSON schema definition for the set_flags tool input parameters, including messageIds, flags, mailbox, and action.
    {
      name: 'set_flags',
      description: 'Set flags on messages (read, unread, flagged, etc.)',
      inputSchema: {
        type: 'object',
        properties: {
          messageIds: {
            type: 'array',
            items: { type: 'string' },
            description: 'Array of message IDs to set flags on',
          },
          flags: {
            type: 'array',
            items: { type: 'string' },
            description:
              'Array of flags to set (e.g., ["\\Seen", "\\Flagged"])',
          },
          mailbox: {
            type: 'string',
            description: 'Mailbox name (default: INBOX)',
            default: 'INBOX',
          },
          action: {
            type: 'string',
            enum: ['add', 'remove'],
            description: 'Whether to add or remove the flags (default: add)',
            default: 'add',
          },
        },
        required: ['messageIds', 'flags'],
      },
    },
  • src/index.ts:54-384 (registration)
    Registration of all tools including 'set_flags' in the ListToolsRequestSchema handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: 'get_messages',
            description: 'Get email messages from specified mailbox',
            inputSchema: {
              type: 'object',
              properties: {
                mailbox: {
                  type: 'string',
                  description: 'Mailbox name (default: INBOX)',
                  default: 'INBOX',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of messages to retrieve',
                  default: 10,
                },
                unreadOnly: {
                  type: 'boolean',
                  description: 'Retrieve only unread messages',
                  default: false,
                },
              },
            },
          },
          {
            name: 'send_email',
            description: 'Send an email through iCloud Mail',
            inputSchema: {
              type: 'object',
              properties: {
                to: {
                  oneOf: [
                    { type: 'string' },
                    { type: 'array', items: { type: 'string' } },
                  ],
                  description: 'Recipient email address(es)',
                },
                subject: {
                  type: 'string',
                  description: 'Email subject',
                },
                text: {
                  type: 'string',
                  description: 'Plain text email body',
                },
                html: {
                  type: 'string',
                  description: 'HTML email body',
                },
              },
              required: ['to', 'subject'],
            },
          },
          {
            name: 'mark_as_read',
            description: 'Mark email messages as read',
            inputSchema: {
              type: 'object',
              properties: {
                messageIds: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Array of message IDs to mark as read',
                },
                mailbox: {
                  type: 'string',
                  description: 'Mailbox name (default: INBOX)',
                  default: 'INBOX',
                },
              },
              required: ['messageIds'],
            },
          },
          {
            name: 'get_mailboxes',
            description: 'List all available mailboxes',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
          {
            name: 'test_connection',
            description: 'Test the email server connection (IMAP and SMTP)',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
          {
            name: 'create_mailbox',
            description: 'Create a new mailbox (folder)',
            inputSchema: {
              type: 'object',
              properties: {
                name: {
                  type: 'string',
                  description: 'Name of the mailbox to create',
                },
              },
              required: ['name'],
            },
          },
          {
            name: 'delete_mailbox',
            description: 'Delete an existing mailbox (folder)',
            inputSchema: {
              type: 'object',
              properties: {
                name: {
                  type: 'string',
                  description: 'Name of the mailbox to delete',
                },
              },
              required: ['name'],
            },
          },
          {
            name: 'move_messages',
            description: 'Move messages between mailboxes',
            inputSchema: {
              type: 'object',
              properties: {
                messageIds: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Array of message IDs to move',
                },
                sourceMailbox: {
                  type: 'string',
                  description: 'Source mailbox name',
                },
                destinationMailbox: {
                  type: 'string',
                  description: 'Destination mailbox name',
                },
              },
              required: ['messageIds', 'sourceMailbox', 'destinationMailbox'],
            },
          },
          {
            name: 'search_messages',
            description: 'Search for messages using various criteria',
            inputSchema: {
              type: 'object',
              properties: {
                query: {
                  type: 'string',
                  description:
                    'Search query text (searches in subject, from, body)',
                },
                mailbox: {
                  type: 'string',
                  description: 'Mailbox name (default: INBOX)',
                  default: 'INBOX',
                },
                limit: {
                  type: 'number',
                  description: 'Maximum number of messages to retrieve',
                  default: 10,
                },
                dateFrom: {
                  type: 'string',
                  description: 'Start date for search (YYYY-MM-DD format)',
                },
                dateTo: {
                  type: 'string',
                  description: 'End date for search (YYYY-MM-DD format)',
                },
                fromEmail: {
                  type: 'string',
                  description: 'Filter by sender email address',
                },
                unreadOnly: {
                  type: 'boolean',
                  description: 'Search only unread messages',
                  default: false,
                },
              },
            },
          },
          {
            name: 'delete_messages',
            description: 'Delete messages from a mailbox',
            inputSchema: {
              type: 'object',
              properties: {
                messageIds: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Array of message IDs to delete',
                },
                mailbox: {
                  type: 'string',
                  description: 'Mailbox name (default: INBOX)',
                  default: 'INBOX',
                },
              },
              required: ['messageIds'],
            },
          },
          {
            name: 'set_flags',
            description: 'Set flags on messages (read, unread, flagged, etc.)',
            inputSchema: {
              type: 'object',
              properties: {
                messageIds: {
                  type: 'array',
                  items: { type: 'string' },
                  description: 'Array of message IDs to set flags on',
                },
                flags: {
                  type: 'array',
                  items: { type: 'string' },
                  description:
                    'Array of flags to set (e.g., ["\\Seen", "\\Flagged"])',
                },
                mailbox: {
                  type: 'string',
                  description: 'Mailbox name (default: INBOX)',
                  default: 'INBOX',
                },
                action: {
                  type: 'string',
                  enum: ['add', 'remove'],
                  description: 'Whether to add or remove the flags (default: add)',
                  default: 'add',
                },
              },
              required: ['messageIds', 'flags'],
            },
          },
          {
            name: 'download_attachment',
            description: 'Download an attachment from a specific message',
            inputSchema: {
              type: 'object',
              properties: {
                messageId: {
                  type: 'string',
                  description: 'Message ID containing the attachment',
                },
                attachmentIndex: {
                  type: 'number',
                  description: 'Index of the attachment to download (0-based)',
                  default: 0,
                },
                mailbox: {
                  type: 'string',
                  description: 'Mailbox name (default: INBOX)',
                  default: 'INBOX',
                },
              },
              required: ['messageId'],
            },
          },
          {
            name: 'auto_organize',
            description:
              'Automatically organize emails based on rules (sender, subject keywords, etc.)',
            inputSchema: {
              type: 'object',
              properties: {
                rules: {
                  type: 'array',
                  items: {
                    type: 'object',
                    properties: {
                      name: {
                        type: 'string',
                        description: 'Rule name',
                      },
                      condition: {
                        type: 'object',
                        properties: {
                          fromContains: {
                            type: 'string',
                            description: 'Move emails if sender contains this text',
                          },
                          subjectContains: {
                            type: 'string',
                            description:
                              'Move emails if subject contains this text',
                          },
                        },
                      },
                      action: {
                        type: 'object',
                        properties: {
                          moveToMailbox: {
                            type: 'string',
                            description: 'Mailbox to move matching emails to',
                          },
                        },
                        required: ['moveToMailbox'],
                      },
                    },
                    required: ['name', 'condition', 'action'],
                  },
                  description: 'Array of organization rules',
                },
                sourceMailbox: {
                  type: 'string',
                  description: 'Source mailbox to organize (default: INBOX)',
                  default: 'INBOX',
                },
                dryRun: {
                  type: 'boolean',
                  description:
                    'If true, only shows what would be organized without moving emails',
                  default: false,
                },
              },
              required: ['rules'],
            },
          },
          {
            name: 'check_config',
            description: 'Check if environment variables are properly configured',
            inputSchema: {
              type: 'object',
              properties: {},
            },
          },
        ],
      };
    });
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does without disclosing behavioral traits. It doesn't mention permission requirements, side effects (e.g., whether flags persist), error handling, or rate limits, which are critical 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, efficient sentence that front-loads the core purpose with no wasted words. It uses parentheses to include helpful examples without cluttering the main statement.

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?

For a mutation tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral context, error cases, or return values, leaving significant gaps for the agent to operate safely and effectively.

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 the schema fully documents all 4 parameters. The description adds minimal value by hinting at flag examples (e.g., 'read, unread, flagged'), but doesn't elaborate beyond what the schema provides, meeting the baseline for high coverage.

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

Purpose4/5

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

The description clearly states the verb ('Set') and resource ('flags on messages'), with examples of specific flags like 'read, unread, flagged'. It distinguishes from siblings like 'mark_as_read' by covering multiple flag types, though it doesn't explicitly contrast with them.

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 on when to use this tool versus alternatives like 'mark_as_read' or 'auto_organize'. The description mentions flag types but doesn't specify scenarios or prerequisites for usage, leaving the agent to infer context from parameter names alone.

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/Racimy/iMail-mcp'

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