Skip to main content
Glama
ggiraudon

Email MCP Server

by ggiraudon

moveMessage

Move email messages between folders by specifying source folder, destination folder, and message ID for organized email management.

Instructions

Moves a message by ID from one folder to another.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceFolderYes
destinationFolderYes
idYes

Implementation Reference

  • The handler function for the 'moveMessage' tool. It validates arguments, gets the IMAP controller instance, connects if needed, moves the message, and returns success.
    export const MoveMessageTool: Tool<any, typeof MoveMessageInput> = { name: "moveMessage", description: "Moves a message by ID from one folder to another.", parameters: MoveMessageInput, async execute(args, context) { if (!args || typeof args !== 'object'|| !('sourceFolder' in args) || !('destinationFolder' in args) || !('id' in args)) { throw new Error("Missing required arguments"); } const controller = ImapControllerFactory.getInstance(); await controller.connect(); await controller.moveMessage(args.sourceFolder, args.destinationFolder, args.id); return JSON.stringify({ success: true }); } };
  • Zod input schema defining parameters for the moveMessage tool: sourceFolder, destinationFolder, and id.
    export const MoveMessageInput = z.object({ sourceFolder: z.string().min(2).max(100), destinationFolder: z.string().min(2).max(100), id: z.number() });
  • src/index.ts:53-53 (registration)
    Registration of the MoveMessageTool with the FastMCP server.
    server.addTool(MoveMessageTool);
  • ImapController method implementing the actual message move using node-imap, with fallback to copy-delete if move is not supported.
    moveMessage(sourceFolder: string, destinationFolder: string, uid: number): Promise<void> { return new Promise((resolve, reject) => { this.imap.openBox(sourceFolder, false, (err: Error | null, box: Imap.Box | null) => { if (err) return reject(err); // Try to use move if supported, otherwise fallback to copy+delete if (typeof this.imap.move === 'function') { (this.imap as any).move(uid, destinationFolder, (err: any) => { if (err) return reject(err); resolve(); }); } else { this.imap.copy(uid, destinationFolder, (err: Error | null) => { if (err) return reject(err); this.imap.addFlags(uid, '\Deleted', (err: Error | null) => { if (err) return reject(err); this.imap.expunge(uid, (err: Error | null) => { if (err) return reject(err); resolve(); }); }); }); } }); }); }

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/ggiraudon/emailMCPServer'

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