Skip to main content
Glama
ggiraudon

Email MCP Server

by ggiraudon

getMessage

Retrieve specific email messages from IMAP folders using unique identifiers to access and manage email content within email servers.

Instructions

Returns a message by UID from a given folder for a given IMAP account.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folderYes
uidYes

Implementation Reference

  • The GetMessageTool object defining the tool's metadata and the execute handler function that fetches and returns the message using ImapController.
    export const GetMessageTool: Tool<any, typeof GetMessageInput> = {
      name: "getMessage",
      description: "Returns a message by UID from a given folder for a given IMAP account.",
      parameters: GetMessageInput,
      async execute(args, context) {
        if (!args || typeof args !== 'object' || !('folder' in args) || !('uid' in args)) {
          throw new Error("Missing required arguments");
        }
        const controller = ImapControllerFactory.getInstance();
        await controller.connect();
        const message: MailItem = await controller.getMessage(args.folder, args.uid);
        return JSON.stringify({ message });
      }
    };
  • Zod schema defining the input parameters for the getMessage tool: folder (string) and uid (number).
    export const GetMessageInput = z.object({
      folder: z.string().min(2).max(100),
      uid: z.number()
    });
  • src/index.ts:52-52 (registration)
    Registration of the GetMessageTool with the FastMCP server.
    server.addTool(GetMessageTool);
  • The ImapController.getMessage method that retrieves and parses the full message content from the IMAP server, used by the tool handler.
    getMessage(folder: string, uid: number): Promise<MailItem> {
        return new Promise((resolve, reject) => {
            this.imap.openBox(folder, true, (err: Error | null, box: Imap.Box) => {
                if (err) return reject(err);
                const fetch = this.imap.fetch(uid, { bodies: ['HEADER', 'TEXT'], struct: true, envelope: true, size:true });
                let mail: MailItem = { id: uid };
                fetch.on('message', (msg: ImapMessage, seqno: number) => {
                    let headersBuffer = '';
                    let textBuffer = '';
                    let htmlBuffer = '';
                    let attachments: any[] = [];
                    let headers: any = {};
                    let fullbuffer = '';
                    msg.on('body', (stream: any, info: any) => {
                        let buffer = '';
                        stream.on('data', (chunk: Buffer) => { 
                            buffer += chunk.toString('utf8');
                            fullbuffer += buffer;
                         });
                        stream.on('end', () => {
                            if (info.which && info.which.toUpperCase().startsWith('HEADER')) {
                                headersBuffer += buffer;
                            } else if (info.which && info.which.toUpperCase().includes('TEXT/HTML')) {
                                htmlBuffer += buffer;
                            } else {
                                textBuffer += buffer;
                            }
                            //console.log('=============END============');
                            simpleParser(fullbuffer, (parserErr, parsedmail) => {
                                if (parserErr) throw parserErr;
                                //console.log('Subject:', parsedmail.subject);
                                //console.log('From:', parsedmail.from);
                                //console.log('To:', parsedmail.to);
                                //console.log('Text Body:', parsedmail.text?.toString().length);
                                //console.log('HTML Body:', parsedmail.html.toString().length);
                                //console.log('Headers:', parsedmail.headers);
                                mail.subject = parsedmail.subject;
                                mail.from = EmailAddressSchema.parse({ address: parsedmail.from?.value[0].address?.toString(), name: parsedmail.from?.value[0].name });
                                if (typeof parsedmail.to !== 'undefined' && !Array.isArray(parsedmail.to)) {
                                    mail.to?.push(EmailAddressSchema.parse({ address: parsedmail.to.value[0].address?.toString(), name: parsedmail.to.value[0].name }));
                                }else{
                                    if(Array.isArray(parsedmail.to)) {
                                        parsedmail.to.map((addr: AddressObject) => {
                                            mail.to?.push(EmailAddressSchema.parse({ address: addr.value[0].address?.toString(), name: addr.value[0].name }));
                                        });
                                    }
                                }
                                if(typeof parsedmail.cc !== 'undefined' && !Array.isArray(parsedmail.cc)) {
                                    mail.cc?.push(EmailAddressSchema.parse({ address: parsedmail.cc.value[0].address?.toString(), name: parsedmail.cc.value[0].name }));
                                }else{
                                    if(Array.isArray(parsedmail.cc)) {
                                        parsedmail.cc.map((addr: AddressObject) => {
                                            mail.cc?.push(EmailAddressSchema.parse({ address: addr.value[0].address?.toString(), name: addr.value[0].name }));
                                        });
                                    }
                                }
                                if(typeof parsedmail.bcc !== 'undefined' && !Array.isArray(parsedmail.bcc)) {
                                    mail.bcc?.push(EmailAddressSchema.parse({ address: parsedmail.bcc.value[0].address?.toString(), name: parsedmail.bcc.value[0].name }));
                                }else{
                                    if(Array.isArray(parsedmail.bcc)) {
                                        parsedmail.bcc.map((addr: AddressObject) => {
                                            mail.bcc?.push(EmailAddressSchema.parse({ address: addr.value[0].address?.toString(), name: addr.value[0].name }));
                                        });
                                    }
                                }
                                mail.date = parsedmail.date ? new Date(parsedmail.date) : undefined;
                                mail.messageId = parsedmail.messageId;
                                mail.inReplyTo = parsedmail.inReplyTo;
                                if(typeof parsedmail.references !== 'undefined' && !Array.isArray(parsedmail.references)) {
                                    mail.references?.push(parsedmail.references);
                                }else{
                                    if(Array.isArray(parsedmail.references)) {
                                        parsedmail.references.map((ref: string) => {
                                            mail.references?.push(ref);
                                        });
                                    }
                                }
                                mail.text = parsedmail.text?.toString();
                                mail.html = parsedmail.html?.toString();
                                for(let [key,value] of parsedmail.headers) {
                                    mail.headers?.push([key, value]);
                                }
                                mail.attachments = parsedmail.attachments;
                                // Remove undefined/empty arrays
                                if (mail.to && mail.to.length === 0) delete mail.to;
                                if (mail.cc && mail.cc.length === 0) delete mail.cc;
                                if (mail.bcc && mail.bcc.length === 0) delete mail.bcc;
                                if (mail.references && mail.references.length === 0) delete mail.references;
                                if (mail.attachments && mail.attachments.length === 0) delete mail.attachments;
                                resolve(MailItemSchema.parse(mail));
    
    
    
                            });
                            //console.log('=============END============');
    
                        });
    
                    });
                    msg.once('end', () => {
                    });
                });
                fetch.once('error', (err: Error | null) => reject(err));
            });
        });
    }
  • src/index.ts:12-12 (registration)
    Import of the GetMessageTool in the main index file.
    import { GetMessageTool } from "./tools/GetMessageTool.js";
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool returns a message but doesn't specify what data is included (e.g., headers, body, attachments), error handling (e.g., for invalid UIDs or folders), or performance aspects (e.g., speed, rate limits). For a read operation with zero annotation coverage, this is a significant gap in transparency.

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 functionality ('Returns a message') and includes essential details (UID, folder, IMAP account) without unnecessary words. Every part earns its place, making it highly concise and well-structured.

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 complexity of an IMAP message retrieval tool, no annotations, no output schema, and low schema description coverage, the description is incomplete. It lacks details on return values (e.g., message structure), error conditions, authentication needs, and how it differs from sibling tools. This leaves the agent with insufficient context for effective use.

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 description adds meaning beyond the input schema by explaining that 'folder' and 'uid' are used to retrieve a message from an IMAP account, which clarifies their purpose. However, with 0% schema description coverage, it doesn't detail parameter formats (e.g., folder naming conventions, UID constraints) or provide examples. This meets the baseline for minimal compensation but doesn't fully address the coverage gap.

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 tool's purpose: 'Returns a message by UID from a given folder for a given IMAP account.' It specifies the verb ('Returns'), resource ('a message'), and key parameters (UID, folder, IMAP account). However, it doesn't explicitly differentiate from sibling tools like 'getMessageList' or 'search', which prevents a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose 'getMessage' over 'getMessageList' (for listing messages) or 'search' (for finding messages by criteria), nor does it discuss prerequisites like authentication or folder existence. This leaves the agent without context for tool selection.

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

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